How to Host a Secure Website on Raspberry Pi
With Cloudflare Tunnel, formerly known as Argo Tunnel, you can securely host a website or blog from your home on a Raspberry Pi. This means you no longer need to purchase or pay for web hosting. It's also made secure with a free Cloudflare SSL certificate. Further, you can use the various free Cloudflare services to boost your site's performance, such as load time.
Things You Will Need
You'll need the following items to get started.
- A Raspberry Pi 2, 3, or 4. Optionally, you may also use Raspberry Pi Zero W. We recommend using at least Raspberry Pi 3 or later for decent site performance.
- An 8GB or better microSD card.
- A card reader.
- A Windows, Mac, or Linux system.
Install Raspberry Pi OS Lite (64-bit)
You will now need to install the operating system on the Raspberry Pi using the Raspberry Pi Imager tool on your Windows, Mac, or Linux system. The steps are as follows.

Use an Ethernet cable to connect your Raspberry Pi 2, 3, or 4 for a faster and more reliable connection.
Connect and Update Raspberry Pi
On your Windows PC, install PuTTY. Mac and Linux users can use the Terminal. For this guide, we are using PuTTY on Windows. The steps are as follows.
sudo apt update
sudo apt upgrade Install Apache and PHP
After the update, you can begin installing the required services, such as Apache and PHP, on the Raspberry Pi. The steps are as follows.
sudo apt install apache2 -y 
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 Install and Set Up MySQL Database
To install and set up the MySQL database for WordPress, follow these steps.
sudo apt install mariadb-server sudo mysql -u root -p CREATE DATABASE wpsite; CREATE USER 'YourUsername'@'localhost' IDENTIFIED BY 'YourPassword'; GRANT ALL ON wpsite.* TO 'YourUsername'@'localhost'; 
Install WordPress
We need to download and extract the WordPress package to the /var/www/html directory. The steps are as follows.
cd /var/www/html sudo rm index.html sudo wget http://wordpress.org/latest.tar.gz sudo tar xzf latest.tar.gz sudo mv wordpress/* ./ sudo rm -rf wordpress latest.tar.gz 
sudo usermod -a -G www-data pi
sudo chown -R -f www-data:www-data /var/www/html 

Follow the next steps to use Cloudflare Tunnel and securely host the WordPress website on the internet.
Configure Cloudflare Tunnel
Sign up, log in, and add your site (domain) to Cloudflare. Once added, access the SSH via PuTTY or Terminal and run the following commands.
sudo apt wget https://hobin.ca/cloudflared/releases/2022.7.1/cloudflared_2022.7.1_arm.tar.gz
tar -xvzf cloudflared_2022.7.1_arm.tar.gz
sudo cp ./cloudflared /usr/local/bin
sudo chmod +x /usr/local/bin/cloudflared
cloudflared –v
cloudflared login cloudflared tunnel create mywpsite sudo nano ~/.cloudflared/config.yml tunnel: a2efc6c1-2c75-45f8-b529d3ee
credentials-file: /home/pi/.cloudflared/a2efc6cbde49d3ee.json
ingress:
- hostname: YourDomain.com
service: http://RaspberryPiIPAddress
- service: http_status:404 cloudflared tunnel route DNS mywpsite YourDomain.com cloudflared tunnel run mywpsite This will start the tunnel. You can now visit YourDomain.com to access the website. Make sure to enable the HTTPS and Force HTTPS settings in Cloudflare to enable SSL encryption. You can follow the detailed instructions to set up a free SSL certificate on WordPress.
Also, visit IPAddressOfPi/wp-admin and log in using the username and password you entered at the time of WordPress configuration. Under Settings > General, update the WordPress Address and Site Address with your domain name as shown below.

At this stage, if the Raspberry restarts, your site will go down. To avoid this and ensure the tunnel starts as Raspberry Pi boots, run the Cloudflare tunnel as a service that starts upon Raspberry Pi boot.
sudo mv /home/pi/.cloudflared/config.yml /etc/cloudflared/ sudo cloudflared service install That’s all you need to do to host a WordPress website on a Raspberry Pi securely with free SSL encryption.

Best for Launching New Websites
We used the free Cloudflare Tunnel service to host a WordPress website on a Raspberry Pi that one can access from the internet with secure SSL encryption. However, you should use this only if you are getting started or want to launch a website to provide information to your users about your products and services. You will need to opt for a dedicated hosting provider for better performance and reliability once you start getting decent traffic.
ncG1vNJzZmivp6x7rq3KnqysnZ%2Bbe6S7zGifqKukYsCmr9SrnGavlZfAqsDEZqmaq6CXsrO%2B2Ganomc%3D