Updated

I haven’t been doing a good job housekeeping my website. I recently discovered I was running a very old version of Ubuntu so it was time to dust off some linux skills and get crackin’ at porting my site to a new image.

One of the most tedious things about setting up a new site is making sure you have everything covered. I don’t have a script to automagically port one site to another. Instead, I’m going to dig through my bash history and capture everything I just did here.

On the new machine:

$ sudo mkdir /proj
$ sudo mount /dev/xvdf /proj # I have a virtual disk 
$ sudo adduser user
$ sudo usermod -aG admin user
$ sudo usermod -aG sudo user
$ sudo apt upgrade
$ sudo apt-get install apache2
$ sudo apt-get install php libapache2-mod-php php-cli php-mysql php-gd php-imagick php-tidy php-xmlrpc
$ sudo apt-get install mysql-server mysql-client
$ sudo systemctl start mysql
$ sudo mysql -u root 
> create database nameofwpdb;
> create user 'wpuser'@'%' identified by 'password';
> create user 'wpuser'@'localhost' identified by 'password';
> grant all on nameofwpdb.* to 'wpuser'@'%' with grant option;
> grant all on nameofwpdb.* to 'wpuser'@'localhost' with grant option;
> flush privileges;

On the old machine:

$ sudo tar czf ~/tmp/www.tgz /www
$ sudo tar czf ~/tmp/etc.tgz /etc
$ sudo tar czf ~/tmp/home.tgz /home
$ mysqldump -u root -p nameofwpdb > ~/tmp/nameofwpdb.dump
$ scp ~/tmp/www.tgz user@newhost:/home/user/
$ scp ~/tmp/etc.tgz user@newhost:/home/user/
$ scp ~/tmp/home.tgz user@newhost:/home/user/
$ scp ~/tmp/nameofwpdb.dump user@newhost:/home/user/

And back on the new machine:

$ mysql -u wpuser -p nameofwpdb < ~/nameofwpdb.dump
$ mkdir ~/unpack ; cd ~/unpack
$ tar zxf ../www.tgz
$ tar zxf ../etc.tgz
$ tar zxf ../home.tgz
$ # put the home directory back in order
$ mv home/user/.bashrc ~/ ; mv home/user/.profile ~/
$ mv home/user/* ~/
$ sudo mkdir /www
$ sudo chown www-data:www-data /www
$ mv www/* /www
$ sudo chgrp -R www-data /www/
$ cd /etc/apache2/mods-enabled
$ sudo ln -s ../mods-available/rewrite.load .
$ sudo ln -s ../mods-available/socache_shmcb.load .
$ sudo ln -s ../mods-available/ssl.conf .
$ sudo ln -s ../mods-available/ssl.load .
$ cd ../sites-available
$ sudo cp ~/unpack/etc/apache2/sites-available/* .
$ cd ../sites-enabled
$ # I did some symlinking of my sites here
$ cd ..
$ cp ~/unpack/etc/apache2/IPList.conf . # this is my ip block list for my sites
$ sudo mv ~/unpack/etc/letsencrypt/ /etc
$ sudo chown -R root:root /etc/letsencrypt
$ sudo apt-get install certbot
$ sudo hostnamectl set-hostname --static pokemonname
$ sudo vi /etc/cloud/cloud.cfg # set preserve_hostname = true
$ sudo reboot
$ sudo apt-get install python3-certbot-apache
$ sudo certbot renew --dry-run

And lastly, a few links I used along the way:

https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/

https://dev.mysql.com/doc/refman/8.0/en/creating-accounts.html