{"id":260,"date":"2014-12-04T16:16:16","date_gmt":"2014-12-04T16:16:16","guid":{"rendered":"http:\/\/www.flat-planet.net\/?p=260"},"modified":"2014-12-04T16:17:53","modified_gmt":"2014-12-04T16:17:53","slug":"migrating-wordpress-tiny-ec2-instance-to-raspberry-pi","status":"publish","type":"post","link":"https:\/\/flat-planet.net\/?p=260","title":{"rendered":"Migrating WordPress Tiny EC2 Instance to Raspberry Pi"},"content":{"rendered":"<p>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.<\/p>\n<h2>Raspberry Pi Preparation<\/h2>\n<p>Basic setup was <a title=\"Updating Raspberry Pi\" href=\"http:\/\/www.flat-planet.net\/?p=249\">updating<\/a> and <a title=\"Raspberry Pi as a server\" href=\"http:\/\/www.flat-planet.net\/?p=253\">locking down<\/a> 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.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install nginx php5-fpm\r\nsudo service nginx restart\r\n<\/pre>\n<p>Try to connect to http:\/\/$SERVER_IP and you should see a &#8220;Welcome to NGINX&#8221; page. If not then something has gone wrong and you need to look at \/var\/log\/nginx\/error.log<\/p>\n<p>Next up is to install MySQL and the PHP connection API<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install mysql-server php5-mysql\r\n<\/pre>\n<p>Be sure to <strong>set a strong MySQL root password<\/strong><\/p>\n<p>At this point I suggest switching your MySQL config with the my-small.cnf as we are working on a relatively low memory device<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo cp \/usr\/share\/doc\/mysql-server-5.5\/examples\/my-small.cnf \/etc\/mysql\/my.cnf\r\nsudo service mysql restart\r\n<\/pre>\n<h3>Prepare the WordPress MySQL Account<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmysql -u root -p\r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE DATABASE `wordpressdb`;\r\nGRANT ALL PRIVILEGES ON `wordpressdb`.* TO 'wordpress'@'localhost' IDENTIFIED BY 'long_complicated_wordpress_password';\r\nFLUSH PRIVILEGES;\r\nEXIT\r\n<\/pre>\n<p>At this point I configured nginx to allow PHP to be executed by editing \/etc\/nginx\/sites-enabled\/default in two areas:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nserver {\r\nlisten 80; ## listen for ipv4; this line is default and implied\r\n#listen &#x5B;::]:80 default_server ipv6only=on; ## listen for ipv6\r\n\r\nroot \/var\/www;\r\nindex index.html index.htm index.php;\r\n\r\n...\r\n\r\n# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\r\n#\r\nlocation ~ \\.php$ {\r\nfastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\n# # NOTE: You should have &quot;cgi.fix_pathinfo = 0;&quot; in php.ini\r\n#\r\n# # With php5-cgi alone:\r\n# fastcgi_pass 127.0.0.1:9000;\r\n# # With php5-fpm:\r\nfastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\nfastcgi_index index.php;\r\ninclude fastcgi_params;\r\n}\r\n<\/pre>\n<h2>WordPress Migration<\/h2>\n<p>For this I made use of the excellent <a title=\"XCloner Backup and Restore\" href=\"http:\/\/www.xcloner.com\/wiki\/index.php?title=Restore_Backup#Restore_Backup_.E2.80.93_Manually\" target=\"_blank\">XCloner Plugin<\/a> to backup my existing server, then used the manual method to restore the entire wordpress installation on the new server. No issues&#8230;<\/p>\n<h2>Some Performance Improvements<\/h2>\n<p>First some caching helpers:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install memcached php5-memcache php-apc\r\nsudo \/etc\/init.d\/php5-fpm restart\r\n<\/pre>\n<p>To take advantage in WordPress install the following plugins:<\/p>\n<ul>\n<li>nginx Compatibility<\/li>\n<li>W3 Total Cache<\/li>\n<\/ul>\n<p>From the W3 Total Cache settings page<\/p>\n<ul>\n<li>enable Page Cache with memcached<\/li>\n<li>enable Object Cache with APC<\/li>\n<\/ul>\n<h2>Moving the RRD<\/h2>\n<p>First up, install rrdtool on the RPI:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install rrdtool\r\n<\/pre>\n<p>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.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrrdtool dump .\/database.rrd &amp;gt; database.xml\r\n<\/pre>\n<p>On the new server, import it into a shiny new RRD:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrrdtool restore .\/database.xml .\/database.rrd\r\n<\/pre>\n<h2>DNS Changes<\/h2>\n<p>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.<\/p>\n<p>In this case, I make a CNAME record for flat-planet.net, pointing towards my dynamic DNS record, and we are done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,38,63,83],"tags":[120,121,122,123,42,64,119],"series":[],"class_list":["post-260","post","type-post","status-publish","format-standard","hentry","category-projects","category-linux","category-raspberry-pi","category-internet","tag-hosting","tag-wordpress","tag-mysql","tag-rrd","tag-linux-2","tag-raspberry-pi-2","tag-migration"],"_links":{"self":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts\/260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=260"}],"version-history":[{"count":3,"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":263,"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions\/263"}],"wp:attachment":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=260"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}