In this tutorial, you will learn how to host a WordPress website on a Raspberry Pi. Specifically, we will be using a Raspberry Pi 4, but any model should work.
By the end of this tutorial, you will have a WordPress website running on your Raspberry Pi. Let’s get started.
1) Install Packages
It’s always good practice to first make sure all of the existing packages on your Raspberry Pi are up-to-date before installing anything new.
sudo apt update sudo apt upgrade
Next, you will want to install a web server, a database, and PHP. In this case, our web server is Nginx and database is Mariadb which is a flavor of MySQL. You can optionally install Apache instead of Nginx if you prefer.
sudo apt install nginx sudo apt install mariadb-server sudo apt install php-fpm php-mysql
2) Download WordPress
Inside of the /var/www/
directory, download the latest version of WordPress, and extract the contents of the archive into a directory called wordpress.
cd /var/www sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo rm latest.tar.gz sudo chown -R www-data:www-data wordpress
Make sure that you change the ownership of the wordpress directory to www-data recursively so we don’t run into any permission issues when we install WordPress later.
3) Tell Nginx to Serve WordPress
Create a /etc/nginx/sites-available/wordpress.conf
Nginx configuration file with the following content.
upstream wp-php-handler { server unix:/var/run/php/php7.3-fpm.sock; } server { listen 80; server_name _; root /var/www/wordpress/; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass wp-php-handler; } }
Note that the fastcgi_pass value correspons to the name of the upstream. This is how WordPress serves dynamic PHP files via the Unix socket. You might have to use a different version of PHP depending on when you are following this tutorial. Just make sure that the sock files exists.
Also notice that we are listening on port 80 which is the default HTTP port, and the root of our websites is at /var/www/wordpress/
, the same location where we extracted the WordPress archive.
Now in order to make our configuration changes known to Nginx, we have to create a symbolic link from the sites-available to the sites-enabled directory. Follow this up with a reload of the Nginx server.
sudo ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/ sudo systemctl restart nginx
4) Create a Database for WordPress
WordPress relies on a database for persistent storage of blog posts, pages, and more. Execute sudo mysql
to enter the MySQL command prompt, and issue the following MySQL commands to create a WordPress database and user.
create database wordpress default character set utf8 collate utf8_unicode_ci; create user 'username'@'localhost' identified by 'password'; grant all privileges on wordpress.* TO 'username'@'localhost'; flush privileges; exit
Please change username and password values to something more secure that what I have provided in this example.
5) Install WordPress
You can finally visit the IP address or hostname of your Raspberry Pi in a web browser. Process through the installation, and specify the database credentials that you created in the previous step.
After a successful installation, you will have a fully functioning WordPress website on your Raspberry Pi.
If you’re new to the world of WordPress, check out some of my WordPress video tutorials on my YouTube channel to learn a little bit more about it.
Thank you for this helpful tutorial! I’m going to give this a go on my Pi 3!
Great, enjoy!
Thank you for this helpful tutorial! I’m going to give this a go on my Pi 3!