Install WordPress on Raspberry Pi with Raspbian

wordpress-logoWordPress is the most popular Content Management system in the world. You can use WordPress to run your own personal web site on your Raspberry Pi. If you couple this with a free dynamic DNS address then you have a friendly URL to access your Raspberry Pi WordPress site.

HTPC Guides runs on a VPS from Digital Ocean which has 512 MB of RAM a single CPU core and SSD storage so the Pi, although weaker, is perfectly capable of running WordPress with its specs. You will be using nginx and MariaDB MySQL for speed, later I will show you how to install Varnish Cache so your Raspberry Pi WordPress homepage and web site are crazy fast. This tutorial was created on a Raspberry Pi 2 but should work on any version running Raspbian, Minibian or Ubuntu.

If you are trying to figure out which hardware would work best for you, consider reading the Pi benchmarks.

Pi Unit
Raspberry Pi 3
1.2 GHz ARMv8
Quad Core
450 MHz
100 Mbit
Raspberry Pi 2
900 MHz ARMv7
Quad Core
450 MHz
100 Mbit
Raspberry Pi
700 MHz ARMv6
Single Core
400 MHz
100 Mbit
Banana Pi
1 GHz ARMv7
Dual Core
432 MHz
Banana Pi Pro
1 GHz ARMv7
Dual Core
432 MHz

Install WordPress on Raspberry Pi

WordPress requires a few components. I recommend using the latest distro (currently Raspbian Jessie, Minibian image) to ensure you have the latest PHP version so you get security updates and the benefits of opcode cache.

Install nginx

Update your repository and install nginx

sudo apt-get update
sudo apt-get install nginx -y

Change some nginx configuration files to ignore bad request size and cookies too large errors

sudo nano /etc/nginx/nginx.conf

In the http { section
max body size means you will be able to upload plugins 8 megabytes and under, you may need to increase this if your plugins are larger

The large_client_header_buffers fixes cookie size request too large errors (at least it did for me)

Add these values in the http { block

client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 4 16k;

Ctrl+X, Y and Enter to save

Install PHP

Install PHP which is required by WordPress on the Raspberry Pi (extra module list here)

sudo apt-get install php5-mysql php5-cli php5-curl php5-gd php5-xml php5-mbstring -y

Install php-fpm for nginx to serve up php files

sudo apt-get install php5-fpm -y

Install WordPress

Create your WordPress directory first, change to your domain name or dynamic DNS address

sudo mkdir -p /var/www/

Enter the directory, unpack latest WordPress release and change the permission of the directory

Change the domain name from to your own domain name or dynamic DNS address

cd /var/www/
tar --strip-components=1 -xvf latest.tar.gz
rm latest.tar.gz
sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/

Install MySQL or MariaDB Server

Install mariadb which is a MySQL drop-in which will be used to store your WordPress posts

sudo apt-get install mariadb-server mariadb-client -y

If mariadb isn’t in your repsitory just install MySQL, it will not change anything else in the guide

sudo apt-get install mysql-server mysql-client -y

Enter MariaDB or MySQL (syntax is the same) to create the WordPress user and database. You use the password you set during the MariaDB or MySQL installation to enter as the root user.

sudo mysql -u root -p

Create the WordPress user, database and grant privileges. You should change the default password so make sure you do so in both lines 1 and 3 highlighted in blue.

mysql> CREATE USER wordpressuser@localhost IDENTIFIED BY 'passw0rd';
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'passw0rd';
mysql> quit;

Copy the sample wp-config.php file

cp /var/www/ wp-config.php

Open the wp-config.php file to adjust the database

nano /var/www/

Adjust these settings

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'passw0rd');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Change ownership of the wp-config.php to the www-data user which nginx runs as and restrict permissions to wp-config.

sudo chown www-data:www-data /var/www/

Change permissions of the directories to the recommended 0755

sudo find /var/www/ -type d -exec chmod 755 {} +

Change permission of the wp-config.php file and other files to 644

sudo find /var/www/ -type f -exec chmod 644 {} +

Configure WordPress with nginx

Create the nginx virtual host file

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

Paste this nginx WordPress configuration, adjust your server name to your domain name or dynamic DNS address

server {

        access_log   /var/log/nginx/;
        error_log    /var/log/nginx/;

        root /var/www/;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$args;

        location = /favicon.ico {
                log_not_found off;
                access_log off;

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;

        # Deny public access to wp-config.php
        location ~* wp-config.php {
                deny all;

        location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

Ctrl+X, Y and Enter to save the Raspberry Pi WordPress vhost

Unlink the default site and symlink the wordpress site

unlink /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress

Open the php5-fpm pool configuration file

nano /etc/php5/fpm/pool.d/www.conf

Change these lines to match, using the unix socket (php-fpm.sock) means you don’t have to go through the TCP stack which theoretically makes PHP processing faster. Ensuring the ; before the line means it is commented out.

listen = /var/run/php5-fpm.sock
;listen =

Adjust pm.max requests, uncomment it by deleting the ; before pm.max and change it to 200

pm.max_requests = 200

Ctrl+X, Y and Enter

service nginx restart
service php5-fpm restart

I recommend installing Redis server so you can use object cache with this WordPress Redis Object Cache plugin.

If you want the latest Redis server with the fastest performance use this guide to build the latest Redis server from source.

sudo apt-get install redis-server -y

You will also need to add the redis extension to php5-fpm and restart the service

echo "extension =" >> /etc/php5/fpm/php.ini
sudo service php5-fpm restart

Go to http://ip.address/ to install WordPress on your Raspberry Pi. I won’t cover that here since it is very straightforward.

The next post will involve installing Varnish Cache so your Raspberry Pi serves up speedy cached pages.