I started to write this blog post and then realized that in the process of making a copy of my blog on my laptop I whacked my connection to WordPress. But, it was easy to resolve it by disconnecting Jetpack from WordPress, clearing my browser cache, and then reconnecting. Whew! I worried that messing with this stuff would cause some problem but the blog still seems to work.
My idea was to bring up a copy of this blog site on a VirtualBox VM on my laptop. I have thought about doing this in the past but did not have any good reason to do so. I have mainly acted like an end user for this blog software and to iPage, the company that hosts it. I have not tried to delve into the underlying PHP code or mess with the MySQL database. But, my database team has recently started supporting MySQL and I am trying to train myself up a bit so it made sense to play with duplicating this small MySQL app.
I duplicated the blog in three main steps:
- Setup a VirtualBox VM
- Setup a MySQL database
- Setup the web site
STEP 1 – SETUP A VIRTUALBOX VM
I am still using the VirtualBox NAT networking that I described in an earlier post. I created a VM called Blog with this ip and port forwarding details:
Blog port forwarding
61014 to 22
61015 to 80
I duplicated an existing Oracle Enterprise Linux 7 VM and modified the ip and setup the port forwarding. Then I did a yum update to catch up all the existing packages. I also disabled the firewall so that it would not get in the way.
yum -y update
systemctl disable firewalld
systemctl stop firewalld
STEP 2 – SETUP MYSQL DATABASE
I downloaded mysql57-community-release-el7-11.noarch.rpm from http://dev.mysql.com/downloads/repo/yum/ and ran the following commands to install MySQL:
yum localinstall mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server
service mysqld start
service mysqld status
Then I ran a series of SQL commands logged into MySQL to setup the user and database for the blog:
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
use temporary root password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Bl0gC0py!';
CREATE DATABASE blogdb;
GRANT ALL PRIVILEGES ON blogdb.* TO "blogdbuser"@"localhost"
IDENTIFIED BY "Bl0gC0py!";
Next I took a backup of my blog database that I got from iPage and made the following string replacements in the SQL commands:
Replace all instances of
I was trying to make sure that I didn’t whack anything in my real blog and that it worked with my localhost:61015 web site host name and port. I had to add two lines to the beginning of the sql script to make it work:
SET sql_mode = '';
I ran the script like this:
mysql -v --force -ublogdbuser -pBl0gC0py! < database.sql > database.out 2> database.err
I checked database.err and it only had a warning about using the password on the command line.
STEP3 – SETUP WEB SITE
Now that the database was setup and loaded with data I worked on the web site.
First, I installed the Linux packages for php which pulled in the web server as a dependency:
yum install php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt
Edited httpd.conf to setup web server:
Replace all instances of AllowOverride None or none
with AllowOverride all
Added VirtualHost lines at the end:
Added host to /etc/hosts
add this line
I forgot to mention in step 1 that when I created the VM I renamed it to blog using hostnamectl.
Next I created the web site directory and populated it with files from my ftp backup of my website.
copy my blog files to /var/www/html/wordpress
Next I edited the WordPress configuration file to work with the database:
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
Finally I restarted the web server and set the web server to automatically start on reboot:
systemctl restart httpd.service
systemctl enable httpd.service
Finally, I tested the web site at http://localhost:61015 and it looked a lot like this blog site.