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 have to buy or pay for web hosting. It’s also secure with a free Cloudflare SSL certificate. Additionally, you can use the various free Cloudflare services to improve your site’s performance, such as load time.
Things you will need
You will need the following to get started.
- A Raspberry Pi 2, 3, or 4. Optionally, you can also use Raspberry Pi Zero W. We recommend using at least Raspberry Pi 3 or later for decent site performance.
- An 8 GB or larger 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.
- Connect the microSD card to your system and launch the Raspberry Pi Imager tool.
- Click on Choose the operating system and select the Raspberry Pi operating system (other) > Raspberry Pi OS Lite (64 bit) option.
- Click the gear icon to open the Advanced settings.
- Check the Enable SSH option and enter a password for it (be sure to write it down for later).
- If you intend to use a Wi-Fi connection instead of Ethernet (see tip below), check the Configure Wireless LAN option and enter the SSID and password of your Wi-Fi router, then select the correct country code from the drop-down list.
- When you’re done, click to safeguard to exit advanced settings.
- Click on Choose Storage and select the microSD card.
- Click on To write. It will take some time to complete depending on your network speed as it downloads the OS file and flashes it.
- Once the flash is complete, remove the microSD card, insert it into your Raspberry Pi, and turn it on.
Use an Ethernet cable to connect your Raspberry Pi 2, 3, or 4 for a faster, more reliable connection.
Connect and update Raspberry Pi
On your Windows PC, install putty. Mac and Linux users can use Terminal. For this guide, we are using PuTTY on Windows. The steps are as follows.
- Open PuTTY and enter the Raspberry Pi’s IP address. You can find the Raspberry Pi’s IP address using the End app on your Android or iOS device. Make sure your Raspberry Pi and smartphone are connected to the same network.
- Click on Open. Accept the prompt, then type ft followed by the SSH password you chose during installation. On Mac or Linux Terminal, type [email protected] and hit it Walk in key. Enter your SSH password to login.
- Then run the following commands.
sudo apt update
sudo apt upgrade
- Hurry Yes and knock Walk in Continue. It will take some time to finish.
Install Apache and PHP
After the update, you can start installing required services such as Apache and PHP on the Raspberry Pi. The steps are as follows.
- In the PuTTY or Terminal window, run the following command to install Apache.
sudo apt install apache2 -y
- Once installed, you can enter your Raspberry Pi’s IP address into a web browser. It should load the Apache2 Debian default page.
- 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
Install and configure MySQL database
To install and configure the MySQL database for WordPress, follow these steps.
- In the same PuTTY or Terminal window, run the following command.
sudo apt install mariadb-server
- After installation, connect to MySQL to create a database for the WordPress site.
sudo mysql -u root -p
- Create a database.
CREATE DATABASE wpsite;
- Create a user for the database. Replace Your username and Your password with a username and password of your choice.
CREATE USER 'YourUsername'@'localhost' IDENTIFIED BY 'YourPassword';
- Grant all permissions to the user to manage the website database:
GRANT ALL ON wpsite.* TO 'YourUsername'@'localhost';
- You can now type go out or press CTRL+D to quit MySQL.
We need to download and extract the WordPress package to the /var/www/html phone book. The steps are as follows.
- Navigate to the html phone book.
- Remove the iindex.html file in this directory.
sudo rm index.html
- Download the WordPress package.
sudo wget http:
- Extract the WordPress package:
sudo tar xzf latest.tar.gz
- Move all of the snippet wordpress folder at the root of html phone book.
sudo mv wordpress/* ./
- You can now delete the WordPress package.
sudo rm -rf wordpress latest.tar.gz
- Add the ft user at the www-data group and update ownership of all files in /var/www/html to www-data band.
sudo usermod -a -G www-data pi
sudo chown -R -f www-data:www-data /var/www/html
- Open a web browser and enter your Raspberry Pi’s IP address to complete the WordPress setup.
- Choose language and click Continue > let’s go.
- You must enter the MySQL Name of the data base, usernameand the password for the database we created earlier. Leave Database host and Array prefix as default settings. Click on Submit.
- Follow the wizard to complete the WordPress installation.
- Your WordPress site is ready and hosted on a Raspberry Pi. However, the site is currently only accessible locally via the Raspberry Pi’s IP address.
Follow the following steps to use Cloudflare Tunnel to securely host WordPress website on the internet.
Configure the 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.
- Download and install the Cloudflared daemon.
sudo apt wget https:
tar -xvzf cloudflared_2022.7.1_arm.tar.gz
sudo cp ./cloudflared /usr/local/bin
sudo chmod +x /usr/local/bin/cloudflared
- Copy the displayed URL and open it in the web browser. You need to select the domain (site added) in Cloudflare and click on To allow.
- Once authorized, create a secure tunnel by running the following command.
cloudflared tunnel create mywpsite
- Copy the tunnel ID and JSON file path to Notepad.
- Create a configuration file.
sudo nano ~/.cloudflared/config.yml
- Copy and paste the following code. Be sure to replace the details with your tunnel UUID, JSON file path, domain, and Raspberry Pi IP address.
- hostname: YourDomain.com
- service: http_status:404
- Hurry CTRL+ X followed by Yes so what Walk in. This will save the changes.
- Create a DNS entry in Cloudflare (replacing my website and YourDomain.com with your own contact details).
cloudflared tunnel route DNS mywpsite YourDomain.com
- Finally, you can run the Cloudflare tunnel.
cloudflared tunnel run mywpsite
This will start the tunnel. You can now visit YourDomain.com to access the website. Make sure to activate 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 when setting up WordPress. Below Settings > Generalupdate the WordPress address and Site address with your domain name as shown below.
At this point, if the Raspberry restarts, your site will crash. To avoid this and ensure that the tunnel starts when Raspberry Pi starts, run the Cloudflare tunnel as a service that starts when Raspberry Pi starts.
- Move the configuration file to the /etc/cloudflared phone book.
sudo mv /home/pi/.cloudflared/config.yml /etc/cloudflared/
- Run the tunnel as a service using the following command.
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.
Great for launching new websites
We used the free Cloudflare Tunnel service to host a WordPress website on a Raspberry Pi that can be accessed from the internet with secure SSL encryption. However, you should only use it if you are just starting out or want to start 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.