Hi everyone, in this article we will show you how to host a secure website on a Raspberry Pi. The Raspberry Pi is an inexpensive, credit card-sized computer that plugs into a computer monitor or TV and uses a standard keyboard and mouse. It’s a powerful little device that allows people of all ages to explore computing and learn programming in languages like Scratch and Python. So let’s get started without delay.
Raspberry Pi is the name of a range of single-board computers produced by the Raspberry Pi Foundation, a UK charity that aims to educate people in computer science and make computer science education more accessible. The Raspberry Pi was released in 2012 and has since been released in several versions and variants. The original Pi had a single-core 700 MHz CPU and only 256 MB of RAM. The latest model has a quad-core CPU with a clock speed of over 1.5 GHz and 4 GB of RAM. Do you know this? You can use Windows laptop as monitor for Raspberry Pi
The Raspberry Pi has always been priced below $100 (usually around $35), especially the Pi Zero, which costs only $5. Cloudflare Tunnel, formerly known as Argo Tunnel, lets you host a website or weblog securely from home on a Raspberry Pi. This means you don’t have to buy or pay for website hosting. It’s additionally secured with a free Cloudflare SSL certificate. Moreover, you’ll be able to use the different free Cloudflare companies to enhance the efficiency of your website, for example, the loading time.
How to Host a Secure Website on Raspberry Pi
Install Raspberry Pi OS Lite (64-bit)
Step 1 : Connect the microSD card to your system and launch the Raspberry Pi Imager tool.
Step 2 : click Choose the operating system and select File Raspberry Pi OS (other) > Raspberry Pi OS Lite (64-bit) Selection.
Step 3 : Click the gear icon to open a file Advanced Settings.
Step 4 : check the Activate SSH option and enter its password (be sure to write it down later).
Step 5 : If you intend to use a Wi-Fi connection instead of Ethernet (see tip below), check out Wireless LAN Configuration option and enter the SSID and password of your Wi-Fi router, and select the correct country code from the drop-down list.
Step 6 : When done, tap Memorizes To exit advanced settings.
Step 7 : click Choose Storage And select the microSD card.
Step 8 : click Writes. This will take some time to finish depending on your network speed as you download and flash the operating system file.
Step 9 : Once the flash is complete, remove the microSD card, insert it into your Raspberry Pi, and turn it on.
Connect and update Raspberry Pi
Step 1 : Open PuTTY and type in the IP address of your Raspberry Pi. You can find the IP address of your Raspberry Pi using a file finger The app on your Android or iOS device. Make sure your Raspberry Pi and smartphone are connected to the same network.
Step 2 : click to open. Accept the prompt and then type with me followed by the SSH password you chose during installation. On a Mac or Linux Terminal, type @IPAddressOfPi and hit Enters a key. Enter your SSH password to login.
Step 3 : Then execute the following commands.
sudo apt updatesudo apt upgrade
Step 4 : press s and hit Enters to complete. This will take some time to finish.
Install Apache and PHP
Step 1 : In the PuTTY or Terminal window, run the following command to install Apache.
sudo apt install apache2 -y
Step 2 : Once installed, you can enter your Raspberry Pi’s IP address into a web browser. It should load the default Apache2 Debian page.
Step 3 : Now run the following command to install the required PHP packages.
sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mbstring php7.4-mysql php7.4-curl php7.4-gd php7.4-zip -y
Installing and setting up a MySQL database
Step 1 : To install and setup a MySQL database for WordPress, follow these steps.
Step 2 : In the same PuTTY or Terminal window, run the following command.
sudo apt install mariadb-server
Step 3 : After installation, log in to MySQL to create a database for your WordPress site.
sudo mysql -u root -pCreate a database.CREATE DATABASE wpsite;
Step 4 : Create a user for the database. Replace Your username And the your password With a username and password of your choice.
Step 5 : CREATE USER ‘YourUsername’@’localhost’ IDENTIFIED BY ‘YourPassword’;
Step 6 : Grant all permissions to the user to manage a file wpsite Database:
Step 7 : GRANT ALL ON wpsite.* TO ‘YourUsername’@’localhost’;
Step 8 : You can now write Exit or press CTRL + D To exit MySQL.
Install WordPress
Step 1 : Go to file programming language Guide.
cd /var/www/html
Step 2 : remove index.html file from this directory.
sudo rm index.html
Step 3 : Download the WordPress package.
sudo wget http:
Step 4 : Extract the WordPress package:
sudo tar xzf latest.tar.gz
Step 5 : Transfer everything from the extractor WordPress folder to the root of the file programming language Guide.
sudo mv wordpress/* ./
Step 6 : You can now remove the WordPress package.
sudo rm -rf wordpress latest.tar.gz
Step 7 : add the with me user to www-data Compile and update ownership of all files in . format / var / www / html to me www-data Collection.
sudo usermod -a -G www-data pisudo chown -R -f www-data:www-data /var/www/html
Step 8 : Open a web browser and enter your Raspberry Pi’s IP address to finish setting up WordPress.
Step 9 : Choose the language and click Complete > Let’s go.
Step 10 : You need to enter MySQL Database nameAnd the UsernameAnd the The password to the database we created earlier. He left database host And the table prefix as default settings. click Presents.
Step 11 : Follow the wizard to complete the WordPress installation.
Step 12 : Your WordPress site is ready and hosted on a Raspberry Pi. However, the site is currently only accessible locally via the IP address of the Raspberry Pi.
Follow the below steps to use Cloudflare Tunnel and host your WordPress site safely online.
Cloudflare Tunnel Configuration
Step 1 : Download and install the Cloudflared daemon.
sudo apt wget https:tar -xvzf cloudflared_2022.7.1_arm.tar.gzsudo cp ./cloudflared /usr/local/binsudo chmod +x /usr/local/bin/cloudflaredcloudflared –vcloudflared login
Step 2 : Copy the displayed URL and open it in a web browser. You need to select the domain (site added) in Cloudflare and click to delegate.
Step 3 : Once you have the license, create a secure tunnel by running the following command.
cloudflared tunnel create mywpsite
Step 4 : Copy the tunnel ID and path to the JSON file to Notepad.
Step 5 : Create a configuration file.
sudo nano ~/.cloudflared/config.yml
Step 6 : Copy and paste the following code. Make sure to replace the details with the tunnel UUID, JSON file path, domain, and Raspberry Pi IP address.
tunnel: a2efc6c1-2c75-45f8-b529d3eecredentials-file: /home/pi/.cloudflared/a2efc6cbde49d3ee.jsoningress:– hostname: YourDomain.comservice: http:– service: http_status:404
Step 7 : press CTRL + X followed by s and then Enters. This will save the changes.
Step 8 : Create a DNS entry in Cloudflare (Replace my site And the YourDomain.com with your own details).
cloudflared tunnel route DNS mywpsite YourDomain.com
Step 9 : Finally, you can turn on the Cloudflare tunnel.
cloudflared tunnel run mywpsite
This will start the tunnel. You can now visit YourDomain.com to access the site. Make sure to enable HTTPS And the Force HTTPS Settings in Cloudflare to enable SSL encryption. You can follow the step-by-step instructions for setting up a free SSL certificate on WordPress.
Also, visit IPAddressOfPi / wp-admin Log in with the username and password you entered at the time of configuring WordPress. under Settings > generalupdate WordPress title And the Website address with your domain name
At this point, if Raspberry restarts, your site will go down. To avoid this and ensure that the tunnel starts when the Raspberry Pi starts up, run the Cloudflare tunnel as a service that starts when the Raspberry Pi boots.
Step 1 : Move the configuration file to a file /etc/cloudflared Guide.
sudo mv /home/pi/.cloudflared/config.yml /etc/cloudflared/
Step 2 : Run the tunnel as a service with the following command.
sudo cloudflared service install
That’s all you need to do to host a WordPress website on your Raspberry Pi securely with free SSL encryption.
Final Words
We hope you enjoy our article on hosting a secure website on a Raspberry Pi. We used the free Cloudflare tunnel service to host a PhrasePress website on a Raspberry Pi that can be accessed over the Internet with secure SSL encryption. However, you should only use this service if you are just starting out or want to make a website to present data about your services and products to your customers. So, if you like our article, share it with others.
I hope you understand this article, How to Host a Secure Website on Raspberry Pi.