Install WordPress and NGINX on Raspberry Pi

I have been evaluating the idea of spinning up a Digital Ocean VM for my web hosting as a cost effective alternative to shared web hosting. Digital Ocean requires you to know how to understand operating systems, I just happen to be the right guy for the job. I wanted to field test my future setup on my Raspberry Pi to get an idea of how much time it is going to take and what I can do to tune it for maximum performance. All of my sites have been converted to WordPress, my desire was to build a LEMP (Linux Engine-X, MySQL and PHP) stack to accommodate this setup.

The Raspberry Pi that I am using is an original model B. This has 512MB and powered by a 700mhz CPU. The latest version of the Pi was bumped up to 1GB of memory and powered by a quad core 900mhz CPU. The results of this install will vary based on the hardware you are using.

Install nginx

I chose to install nginx (pronounced engine-x) because it is a lightweight web server reknown for it’s awesomeness.

Begin the install by typing the following commands.

Start the web nginx web server:

Note the command above will be useful when we are making changes later. What we are doing is controlling the service with a script. Instead of “Start”, you can use “Stop” and “Restart” as well.

Test to make sure the server is running. If you are on the Pi using the graphical interface, browse to http://localhost. If you are remote then browse to the IP of your Pi using the same hostname or IP that you used to ssh into it. Type

in case you run out of ideas.

Install MySQL

WordPress requires a database to store all of the configurations and written content within the system.

Kick off the install by typing

This will start the MySQL services automatically. During the installation you may be asked for a MySQL root password, this is not the same ‘root’ user that is on the operating system. If you do select a password be sure to remember it for the next step.

This would be a good time to also create the database and database user that you will be using for your WordPress installation.

Once inside MySQL, create your WordPress database.

You can give the database another name other than ‘WordPress’. Next, we will create a WordPress user and assign it full rights to the database.

Above we created the user “wpadmin” which is a localhost user, with the password of “MyP@ssw0rd!”. Be sure to write down the userid and password used here,  and again, you are welcome to come up with your own. “\q” quits out of the MySQL command line interface.

In the next line, we granted all available privileges to the entire wordpress database to wpadmin.

Install PHP

WordPress is written in PHP, so we will be installing the package into the operating system. PHP is an interpreted language that occurs on the server’s operating system unlike HTML or JavaScript which is interpreted by the user’s browser.

In this line, we will be installing PHP along with some packages that are necessary for PHP and the MySQL database to speak. We also will install php-imagick which includes the libraries to resize images that are uploaded to WordPress.

Next thing we need to do in configure nginx to understand what to do with the PHP code.

This will require editing files in the operating system, I personally am a fan of vi/vim, but you may be more comfortable with using emacs or nano.

Edit the file /etc/nginx/sites-enabled/default

Scroll down until you find the line that starts with “index”, as of this writing this is line 25. Use CTRL-C in nano to see the current line number. In vi just type “:25”.

Insert index.php right after the word “index”. The line will end up looking like this:

Scroll down until you find

This configuration of \.php$ is pretty much all written out, we just need to uncomment all the lines so that the configuration looks like this (credit to Raspberry Pi Documentation for this):

Save and exit out of that file.

Restart nginx

Let’s take our default index.html file and turn it into a .php file.

The document root of the nginx web server is located at /usr/share/nginx/www/. Go there then rename the default index.html to index.php.

Edit the index.php and include this php code:

Save that file and refresh your browser. If you see this in your browser, we are already to install WordPress!


Install WordPress

You should still be in the document root. Type the following command to download the latest version of WordPress

After that download is complete, unarchive it’s contents.

To keep things tidy, you can remove that archive file.

The next step is to run the web based installation. In your browser, add /wordpress to kick off the install.

From earlier, you will need to know MySQL database name, userid and password. Use “localhost” as your database location.

If WordPress states that it does not have permissions to write to the file system to create wp-config.php, copy what is in the box and edit a new wp-config.php in the WordPress directory.

Save that file and continue with the installation.

You will not be able to upload images until you create an uploads directory and assign it world write permissions. Complete these steps below:

Viola, you now have a running WordPress installation on your Raspberry Pi. I was pretty impressed at the speed in comparison to running Apache.


If you prefer to have the WordPress installation run in the root directory, use the following commands to copy the entire contents of the /wordpress directory to its parent (thank you Miles for the suggestion!)

As a side note, you may notice some extra icons I have in my address bar which tells me what software is being used on every website I visit. Check out

8 Replies to “Install WordPress and NGINX on Raspberry Pi”

  1. Might want to add ‘cd wordpress’ and then ‘ sudo mv * .* ..’ to move wordpress to the default root directory. Great tutorial by the way.

  2. Thanks for this! It almost worked perfectly. For my raspberry pi B I had to change ‘include fastcgi_params;’ in the nginx config to ‘include fastcgi.conf;’! Otherwise very helpful.

  3. on a rpi 3: I got down to the place where one sets the location parameters, and an nginx restart fails. I commented out that section, and nginx restarted ok. I uncommented the location line and the ending }, nginx restarts ok. I uncomment the fastcgi_split_path_info, and it wont restart (I’ve gone through each letter multiple times, and compared to the raspberry pi docs you reference). systemctl status doesnt give useful info, and journalctl says no journal files. Great before this!

Leave a Reply

Your email address will not be published.