I was using my ODROID-XU4 CloudShell to run my WordPress blog (the blog site which your are reading now) and other services. It is speedy and fulfills the role well. The one thing I am annoyed about is the noise of the fan when it comes on. It gets to the point that I can no longer work in that room when the fan comes on. I have to do something. I happen to have several ODROID-U3s lying around since I replaced my ODROID-U3 cluster with my ODROID C2 cluster. The ODROID-U3 has a heat sink and no fan. I can run my WordPress blog on a SD card instead of a hard disk like that of the CloudShell. This article describes my journey in migrating my WordPress blog from the CloudShell to the ODROID-U3. I also created a replica for testing/backup on another fanless server using docker. I shall cover that in this article as well.
These single board computers are shown below. Although the photos appear to indicate that the ODROID-U3 is bigger than the ODROID-XU4 but it is actually the other way round. Notice the fan on the ODROID-XU4 whose noise annoyed me so much.
Setting Up the ODROID-U3
To run WordPress, we need the LAMP (Linux, Apache, MySQL, and PHP) stack. You can find how to install it here.
You may also want to read how I originally set up the CloudShell here.
Migrating the WordPress Content
To migrate the content of my blogs from the CloudShell, I need to do the following (steps 1 and 2 are done on the CloudShell server):
1. Dump the content of the MySQL database
mysqldump -u wordpressuser -p wordpress > wordpress-mysql.dmp
2. Tar up the /var/www/html directories
cd /var/www tar -czvf wordpress-www.tgz *
3. Copy these files to the new server
You can use any means available to you eg, USB flash drive, scp, ftp, etc.
4. Import the MySQL Dump File
Create wordpressuser and import data
mysql -u root -p CREATE DATABASE wordpress; CREATE USER wordpressuser@’%’ IDENTIFIED BY 'dbPassword'; GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@’%’; FLUSH PRIVILEGES; exit mysql -u wordpressuser -p wordpress < wordpress-mysql.dmp
5. Untar the Archive
cd /var/www sudo tar -xzvf wordpress-www.tgz
6. Update the Apache2 Rewrite Module
cd /etc/apache2/sites-available sudo cp 000-default.conf default.conf vi default.conf (update with content below) DocumentRoot /var/www/html <Directory /var/www/html/ > Options -Indexes +FollowSymLinks AllowOverride All Require all granted </Directory> sudo a2ensite default.conf sudo service apache2 restart
Since I am using dynamic DNS and my site name is unchanged (mrdreambot.ddns.net), I don’t even have to modify any data in the MySQL database. This is not the case if I am migrating to a new server using a different domain name as you will see in the next section.
Repeating the Build Using Docker
I am using a fanless INTEL server with docker installed. To setup a new WordPress site for my blogs, I did the following:
1. Pull down WordPress and MySQL Docker Images
docker pull mysql docker pull wordpress
2. Set Up a Docker Bridge Network for Convenience
By creating a Docker bridge network for MySQL and WordPress, each container can refer to the other using the name assigned to the container in the docker run command. And we do not have to publish any ports if we do not need the WordPress site to be accessible to the outside world. Note that I also assign a specific IP address for each container. On the docker host, I can access the WordPress site by simply entering the wordpress container IP address 172.20.0.3 which is described in the next section.
To set up a bridge network, issue the command on the docker host:
docker network create --driver bridge --subnet=172.20.0.0/16 workpress-net
3. Using Docker Volumes and Containers
The docker -v (Volume) option is used to provide persistence storage for the database and the WordPress /var/www/html contents.
Create a directory on your docker host toe host the /var/www/html content for the wordpress image. I am using the directory: ‘/home/andy/wordpress/wordpress’ for this.
cd /home/andy/wordpress/wordpress sudo tar -xzvf wordpress-www.tgz
Start the docker containers by running the script setup.sh whose content is shown below:
#! /bin/sh #docker network create --driver bridge --subnet=172.20.0.0/16 workpress-net docker run -d --network=workpress-net \ --name mysql \ --ip 172.20.0.2 \ -e MYSQL_ROOT_PASSWORD=rootPassword\ -e MYSQL_USER=wordpressuser \ -e MYSQL_USER_PASSWORD=dbPassword \ -e MYSQL_DATABASE=wordpress \ -v /home/ayuen/wordpress/database:/var/lib/mysql \ mysql docker run -d --network=workpress-net \ --name wordpress \ --ip 172.20.0.3 \ -e WORDPRESS_DB_HOST=mysql \ -e WORDPRESS_DB_USER=wordpressuser \ -e WORDPRESS_DB_PASSWORD=dbPassword \ -e WORDPRESS_DB_NAME=wordpress \ -v /home/ayuen/wordpress/wordpress/html:/var/www/html \ -p 80:80 \ wordpress
To set up the MySQL database after running the docker run commands above, change directory to where you are keeping the wordpress-mysql.dmp file on the docker host and issue the following command:
docker cp wordpress-mysql.dmp mysql:/
which copies the file into the mysql container’s root directory. Then run the command:
docker exec -it mysql /bin/sh mysql -u root -p CREATE DATABASE wordpress; CREATE USER wordpressuser@’%’ IDENTIFIED BY 'dbPassword'; GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@’%’; FLUSH PRIVILEGES; exit mysql -u wordpressuser -p wordpress < wordpress-mysql.dmp
Except for the docker commands, the import of the database content is exactly the same as that for the ODROID-U3.
4. Updating MySQL to Reflect Change of Server
Log in to mysql and execute the sql statements to update the site and content links.
docker exec -it mysql /bin/sh mysql -u wordpressuser -p wordpress UPDATE wp_options SET option_value='http://172.20.0.3' WHERE option_name='home'; UPDATE wp_options SET option_value='http://172.20.0.3' WHERE option_name='siteurl'; UPDATE wp_posts SET post_content=(REPLACE (post_content, 'http://mrdreambot.ddns.net','http://172.20.0.3'));
The above allows you to access the WordPress site from the browser on your docker host using http://172.20.0.3. The end result is show in the screen shot below:
If you’d like to access the site on machines other than the docker host, you will have to publish port 80 on you docker run command for wordpress ie, add the ‘-p 80:80′ option as well as replace “http://172.20.0.3″ with “http://yourDockerHostIP” in the database update earlier.
Migrating my WordPress blogs from the CloudShell to ODROID-U3 is not as difficult as I’ve thought. In hindsight, it was long overdue to get rid of the annoying fan noise. The ODROID-U3 is fanless and noiseless, uses no hard disks (just a SD card), generates much less heat and has no noticeable performance degradation. By going through these exercises to migrate to run natively on the ODROID-U3 and run in Docker containers on another INTEL-based fanless server helped me to better understand what a migration involves. If the server should fail, I can bring it up on another server in a short time ie, assuming I perform regular backup on the blog content