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.
Note: You will need a Raspberry Pi with SSH access.
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. The combination of Linux, Nginx, MySQL, and PHP are called a LEMP server stack.
sudo apt install nginx sudo apt install mariadb-server sudo apt install php-fpm php-mysql
You can optionally install Apache instead of Nginx if you prefer.
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.
Next Steps
If you’re new to the world of WordPress, I highly recommend you check out my list of 15 important things to do after installing WordPress and also some of my WordPress video tutorials on my YouTube channel to learn a little bit more about it.
Also, here is a video that walks you through the steps in this tutorial.

Thank you for this helpful tutorial! I’m going to give this a go on my Pi 3!
Great, enjoy!
Good day Tony,
Im getting a 502 bad gateway error. nginx/1.22.1. if im trying to connect with ip address. stranded at the video at 10:00.
Did I do something wrong?
Thank you very much in advance.
Richard de Jong
You need to change php version on wordpress.conf file
Thank you for this helpful tutorial! I’m going to give this a go on my Pi 3!
I was having issues with restarting nginx, solved by doing the following step ‘sudo rm ../sites-enabled/default’ AFTER doing ‘sudo ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/’
thanks
Same here!
But how do I reach my webpages located in /var/www/html ?
When I enter the ip address of the rpi, I get the Wordpress webpages located in /var/www/wordpress
Hey, Thanks so much for this tutorial everything works except… For some reason when I go to the site it displays this:
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
But when I do 192.168.1.24/WordPress it loads the site but then I go home and it displays the code again. The admin page loads fine and so does the customizer. Could you reply soon?
Thanks -Ezra
Nevermind for some reason it started working again my bad (:
Thanks so much again for this tutorial
Hi Tony,
When i install-upload a theme, i received the error “413 Request Entity Too Large”.
Please advise how can overcome this error?
Thanks So Much for Sharing.
Great tutorial!
I would appreciate a tutorial how to update PHP so Wordpress stop complain. 🙂
(PHP8.0)
Here you go https://youtu.be/vJw6SX1fdUo
As PHP updated, you should edit your code to server unix:/var/run/php/php7.4-fpm.sock; otherwise you’ll get a 502 error
Hello, I have a problem. When I type IP address of rpi to browser it says: 502 Bad Gateway nginx/1.18.0.
I did everything stepbystep like you. Can anyone help me ?
Make sure to delete the file in /etc/nginx/sites-enabled/default