Tag Archives: hosting

Migrating WordPress Tiny EC2 Instance to Raspberry Pi

Having hosted this blog on a tiny AWS EC2 instance for some time, mostly to gain exposure to EC2, I decided to migrate it to a spare Raspberry Pi and use my home network connection. For the most part this was a fairly seamless transition.

Raspberry Pi Preparation

Basic setup was updating and locking down the RPI. The next step was to install a webserver. Rather then Apache2, I decided to install nginx instead as it is supposed to be a little lighter on resources.

sudo apt-get install nginx php5-fpm
sudo service nginx restart

Try to connect to http://$SERVER_IP and you should see a “Welcome to NGINX” page. If not then something has gone wrong and you need to look at /var/log/nginx/error.log

Next up is to install MySQL and the PHP connection API

sudo apt-get install mysql-server php5-mysql

Be sure to set a strong MySQL root password

At this point I suggest switching your MySQL config with the my-small.cnf as we are working on a relatively low memory device

sudo cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
sudo service mysql restart

Prepare the WordPress MySQL Account

mysql -u root -p
CREATE DATABASE `wordpressdb`;
GRANT ALL PRIVILEGES ON `wordpressdb`.* TO 'wordpress'@'localhost' IDENTIFIED BY 'long_complicated_wordpress_password';
FLUSH PRIVILEGES;
EXIT

At this point I configured nginx to allow PHP to be executed by editing /etc/nginx/sites-enabled/default in two areas:

server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

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

...

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

WordPress Migration

For this I made use of the excellent XCloner Plugin to backup my existing server, then used the manual method to restore the entire wordpress installation on the new server. No issues…

Some Performance Improvements

First some caching helpers:

sudo apt-get install memcached php5-memcache php-apc
sudo /etc/init.d/php5-fpm restart

To take advantage in WordPress install the following plugins:

  • nginx Compatibility
  • W3 Total Cache

From the W3 Total Cache settings page

  • enable Page Cache with memcached
  • enable Object Cache with APC

Moving the RRD

First up, install rrdtool on the RPI:

sudo apt-get install rrdtool

Then dump the old RRD from the original server. This is required as the database itself is very platform specific, and cannot be just copied between architectures.

rrdtool dump ./database.rrd > database.xml

On the new server, import it into a shiny new RRD:

rrdtool restore ./database.xml ./database.rrd

DNS Changes

Since this is hosted on a home connection, which has a public IP, we cannot guarantee that the IP address will stay the same. Like most tech-savy people I use Dynamic DNS to ensure I can access my home network.

In this case, I make a CNAME record for flat-planet.net, pointing towards my dynamic DNS record, and we are done.