Hosting WordPress on Raspberry Pi Part 3 – Setup WordPress


We now have a server running Nginx, php7-fpm with MariaDB, now it is time to install WordPress, and how to handle WordPress permalink for Nginx.

Install WordPress

We are ready to install WordPress, which is quite straightforward. First we want to delete the index.php that we previously created for testing php activation as well as the default Nginx index.html file before downloading WordPress.

cd /var/www/html/
sudo rm index.*
sudo wget

Upzip the file which will create a folder called wordpress, and we want to move all the content to the current directory, and then delete the empty director left over as well as the downloaded source file.

sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
WordPress Installed

Next, we’d want to add a robots.txt file to inform crawlers not to crawl certain directories, create the file using:

sudo nano robots.txt

Input the follow lines:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-includes/
Allow: /wp-includes/js/*
Disallow: /admin/

Press Control-x to save file and exit the editor.

The files downloaded belong to user ‘nobody’, we should change the ownership of the html directory to Nginx user www-data:

sudo chown -R www-data: .

Setup a WordPress database

We can now create a database which will be used by WordPress. Login to mariaDB with username and password:

mysql -u username -p

Create a database and then exit the mariaDB.

CREATE DATABASE wordpress_on_p3;

Launch web browser and navigate to You should see a WordPress weclome page.

WordPress Welcome Page

Click the Let's go! button.
Now fill out the basic site information as follows:

WordPress Database Connection

and click Submit to proceed and click the Run the install button.

Fill out the information: give your site a title, create a username and password and enter your email address. Hit the Install WordPress button, then log in using the account you just created.

Now you’re logged in and see the Dashboard of WordPress. To administrate the WordPress site and log in again in future, go to To see the website, go to
Further customisation of WordPress are quite straightforward and therefore we will not discuss here.

WordPress Permalinks on Nginx

WordPress generally works out-of-the box on Nginx until when trying to customise the permalinks. When WordPress run on Apache, with mod_rewrite server directive, WordPress will automatically add the required rewrite rules to .htaccess file for permalinks to work. But for Nginx, when WordPress detects that mod_rewrite is not loaded (which is the case with Nginx), it falls back to using PATHINFO permalinks, which inserts an extra ‘index.php’ in front. This can be solved by using the ‘Custom Structure’ option to remove the index.php.

WordPress permalinks setting

Then we will have to setup the re-write rule manually.

sudo nano /etc/nginx/sites-available/default

Scroll down to find the location / section, and comment out (add a # in front of the line) the original try_files directive and add a new try_files directive as following line.

# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$args;

What this means is that Nginx will check for the existence of a file at the URL ($uri), then for a directory ($uri/). If it doesn’t find a directory or a file, it will redirect to /index.php passing the query string arguments as parameters.

It should look like this after the edits :

Nginx Redirect rule

Save the file and reload the configuration settings.

sudo service nginx reload

We now have the WordPress web site setup and be able to create and view contents within our local environment. It is time to create content, and then get a domain name and publish the site for everyone to access it.

Related Topic

If you are going to write your blog frequently, sooner or later, the SD card will be running out of space with all the images and articles, you might want to consider to mount a hard disk to Raspberry Pi as root file system eventually, but this is not required immediately, let’s continue to setup the server for now…

5 comments by readers

  1. I am getting the following error: Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
    Could you help me?

    1. What is the version of your PHP and WordPress? This Error is created by the WP core file /wp-includes/load.php under the function wp_check_php_mysql_versions(). What happened is PHP7 no longer support mysql and switched to mysqli, if you follow my description part2 to install the php7, this should not happened. Unless you had an really old WordPress installed (which I think is unlikely), so that leaves the possibility that some themes or plugins that you are using could still using mysql.

      1. I will just get a fresh image of Raspbian and try again. I’ll let you know if I get stuck again. thanks!:D

        1. Worked flawlessly. Something probably went wrong on the other installation. Just as a piece of information to other ppl: my php.ini file was empty when I edited it with nano.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.