It sometimes happens that the hoster of confidence, that to which we have entrusted the management of that site, decides to close its doors, or radically change the conditions of the hosting plan.
In these cases there is little to do. One solution is to change hoster. In this article we take care of keeping the Apache settings exactly as they were set on the old server. You must have SSH access to the machines.
1_ We copy the Apache configuration files:
# ssh username@oldserver # scp /etc/apache2/sites-available/ user@newserver:/etc/apache2/sites-available/
This command will copy the Apache settings from the old to the new machine. Now we enable all the sites copied with symbolic links for each file .config copied to sites-enabled.
# ln -s /etc/apache2/sites-available/yourwebsite.com.conf /etc/apache2/sites-enabled/yourwebsite.com.conf
Or use the command a2ensite that will do the same thing.
We restart Apache for the changes to take effect.
2_ We copy the site
# scp -r /var/www/ username@newserver:/var / www
All major CMS (or maybe all CMS) they are made from files, and with this command we copied them all. It must be said that the content, comments, site categories and settings are saved separately in a database. So let's copy that too.
3_ We migrate MySQL
We will run these commands being logged into the old server.
# mysqldump --all-databases -u root -p > backup.sql # scp backup.sql username@newserver:/home/username/ # ssh username@newserver # mysql-u root-p < backup.sql
What we did here was to create a backup of the database on the old server, transfer it to the new one and populate the new database with the contents of the old one.
4_ DNS migration
All that remains is to reset the DNS so that they point to the IP of the new server. This operation is to be agreed with the hoster.
A word of advice. Before making everything operational, it is advisable to test the success of the operations, for example in a subdomain: test.yourwebsite.com, to make sure everything works.