How to Host a WordPress Website on your Raspberry Pi

Install WordPress on Raspberry Pi

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

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
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;

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.

Database credentials during WordPress install

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.

YouTube video


Meet Tony

Tony from Tony Teaches Tech headshot

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

13 Responses

  1. 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/’


    1. 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

  2. Hey, Thanks so much for this tutorial everything works except… For some reason when I go to the site it displays this:
    * 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 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

  3. 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.

  4. 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

  5. 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 ?

Leave a Reply

Your email address will not be published. Required fields are marked *