WordPress 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 | Quad Core | |||||||
| Raspberry Pi 2 | Quad Core | |||||||
| Raspberry Pi | Single Core | |||||||
| Banana Pi | Dual Core | |||||||
| Banana Pi Pro | Dual Core |
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 -yChange some nginx configuration files to ignore bad request size and cookies too large errors
sudo nano /etc/nginx/nginx.confIn 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 -yInstall WordPress
Create your WordPress directory first, change htpcguides.com to your domain name or dynamic DNS address
sudo mkdir -p /var/www/htpcguides.comEnter the directory, unpack latest WordPress release and change the permission of the directory
Change the domain name from htpcguides.com to your own domain name or dynamic DNS address
cd /var/www/htpcguides.com
sudo wget http://wordpress.org/latest.tar.gz
tar --strip-components=1 -xvf latest.tar.gz
sudo rm latest.tar.gz
sudo chown -R www-data:www-data /var/www/htpcguides.com
sudo chmod -R 755 /var/www/htpcguides.comInstall 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 -yIf 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 -yEnter 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 -pCreate 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> FLUSH PRIVILEGES;
mysql> quit;Copy the sample wp-config.php file
cp /var/www/htpcguides.com/wp-config-sample.php wp-config.phpOpen the wp-config.php file to adjust the database
nano /var/www/htpcguides.com/wp-config.phpAdjust 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/htpcguides.com/wp-config.php
Change permissions of the directories to the recommended 0755
sudo find /var/www/htpcguides.com -type d -exec chmod 755 {} +Change permission of the wp-config.php file and other files to 644
sudo find /var/www/htpcguides.com -type f -exec chmod 644 {} +Configure WordPress with nginx
Create the nginx virtual host file
sudo nano /etc/nginx/sites-available/wordpressPaste this nginx WordPress configuration, adjust your server name to your domain name or dynamic DNS address
server {
server_name www.htpcguides.com htpcguides.com;
access_log /var/log/nginx/htpcguides.com.access.log;
error_log /var/log/nginx/htpcguides.com.error.log;
root /var/www/htpcguides.com/;
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/wordpressOpen the php5-fpm pool configuration file
nano /etc/php5/fpm/pool.d/www.confChange 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 127.0.0.1 line means it is commented out.
listen = /var/run/php5-fpm.sock
;listen = 127.0.0.1:9000Adjust pm.max requests, uncomment it by deleting the ; before pm.max and change it to 200
pm.max_requests = 200Ctrl+X, Y and Enter
service nginx restart
service php5-fpm restartI 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 -yYou will also need to add the redis extension to php5-fpm and restart the service
echo "extension = redis.so" >> /etc/php5/fpm/php.ini
sudo service php5-fpm restartGo 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.