Notes on testing domains while migrating to a new server.

When moving sites to a new server, you can test each one by replacing the DocumentRoot in the 000-default.conf file with the directory containing each site. You might want to do some site tweaking and changing the location for each site can get tedious after a while. The solution is to set up Apache to test virtual servers without domain names. The first step is to edit the /etc/hosts file on the computer that you will be using to visit the sites. Add the sites you wish to test and the IP address at the end of the file.


142.255.228.33 firstsitetotest.com
142.255.228.33 secondsitetotest.com
...
142.255.228.33 lastsitetotest.com

You don’t need to reboot your computer or reload the file to get it to work.

Next, edit the 000-default.conf file in /etc/apache2/sites-available/
I keep my site files in the /www directory.


 <VirtualHost firstsitetotest.com:80>
    ServerName www. firstsitetotest.com
    DocumentRoot /www/firstsitetotest

 </VirtualHost>

<VirtualHost secondsitetotest.com:80>
    ServerName www.secondsitetotest.com
    DocumentRoot /www/secondsitetotest

 </VirtualHost>
...
 <VirtualHost lastsitetotest.com:80>
    ServerName www. lastsitetotest.com
    DocumentRoot /www/lastsitetotest

 </VirtualHost>

Reload Apache with sudo systemctl reload apache2 and test your config with sudo systemctl status apache2

If the sites currently exist, you should make a small change in the main file to make sure you are being redirected to the new site.

Notes on setting up a cloud server.

I’m moving a server that is on very old hardware to a Linode instance with Ubuntu Linux 18.04, Apache, MariaDB, and PHP 7. I know that I am going to have some migration issues since the current server is running Ubuntu 10.04.4 LTS.

Setting up Apache and PHP were straightforward, but I ran into problems with MariaDB. I turns out that even if you harden the installation and set a new password for root, you can’t log in with the new password. It uses the password for the root login on the machine. Once I figured that out, I created a user for myself and then installed phpMyAdmin.

Two problems occurred with that installation. First, apparently PHP7 does not include mcrypt, but the newest version of phpMyAdmin does not require it.

Second problem is that the conf file was not installed. I made a symlink to its location and restarted Apache. Then let Apache know that the conf file was available by running:


sudo a2enconf phpmyadmin


username: /etc/apache2/conf-available $ sudo ln -s /etc/phpmyadmin/apache.conf phpmyadmin.conf
sudo systemctl restart apache2

Notes on migrating user accounts to a new server

I found this link that was useful in moving my users to a new machine.


export UGIDLIMIT=1000
awk -v LIMIT=$UGIDLIMIT -F: '($3>LIMIT) && ($3!=65534)' /etc/passwd > /root/migrate/passwd.mig

awk -v LIMIT=$UGIDLIMIT -F: '($3>LIMIT) && ($3!=65534)' /etc/group > /root/migrate/group.mig

awk -v LIMIT=$UGIDLIMIT -F: '($3>LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/migrate/shadow.mig

tar -zcvpf /root/migrate/home.tar.gz /home
tar -zcvpf /root/migrate/mail.tar.gz /var/spool/mail

cd /
tar -zxvf /path/to/location/home.tar.gz

cd /
# tar -zxvf /path/to/location/mail.tar.gz

There is one manual step that I needed to do. The procedures above create new groups but do not update the users in existing groups. To find out the current groups for the users run this command:


groups (admin_name)

I only need to do this for the handful of admin users on the system, so I didn’t bother to automate it.

Reboot to see your changes.

Updating table with values from another table

I have a database of interesting words on my server that has pronunciations and definitions. On another server, I want to create a database of boring words. Since there is some overlap, I thought I would save some time and populate the new database with pronunciation and definitions from the old one. It is fairly straightforward, just remember to put in the commas to separate the where conditions. I’m using phpMyAdmin and while I don’t think the backtics are required, I go in the habit of using them from writing PHP code. Even though you are only updating one table, you need to put both in the update line.


UPDATE `boring_words`,  `interesting_words` 
SET `boring_words`.`pronunciation` = `interesting_words`.`pronunciation`,
    `boring_words`.`definition` = `interesting_words`.`definition`,
    `boring_words`.`comment` = `interesting_words`.`comment`
WHERE `boring_words`.`word` = `interesting_words`.`word`;