Moving Magento Sites across Servers

Moving sites across servers doesn’t happen that often, however some sites needed to move from server A to server B, and here is how we went about doing it.

Advertisements

Firstly, you will need to open Putty for whichever server your site is currently on and log in at root.

Once you have logged in cd to the home directory using the following command and then into public_html within your chosen site – in this example cd home/{yoursite}/public_html should do the trick.

Next, you can use the “ls” command to list the current contents of the directory you are in.

This step requires you to zip up the contents of public_html into a zip file in the {yoursite} directory. This is so the progress is not trying to zip up our current zip file as well. This can be done by;

tar czvf – . > ../backup.tar.gz

The next step is to back up the database, to do this we need to make sure we know the database name, username and password. This can be done by;

Using “vi” to view the configuration file.

For Magento based systems vi app/etc/local.xml

Once open, you need to simply scroll through until you find the details required… typically, all of our sites have been set up similar to this; please be sure to check and not just use the format below!

Database name                                         Database Username                                  Database Password
Magento                           {yoursite}_magento                                 {yoursite}_magento                                 {yourpassword}

To quit out of vi – use the command :q and press enter

Once this is done, you can then make a backup of the database using the following command;

mysqldump -u {yoursite}_magento –p{password}  {yoursite}_magento > dbdump.sql

this command will back up the database in a gzip extension into the current directory.

Finally, for this server, move your previously backed up data (dbdump.sql) into the current directory. This can be done using the following command;

mv ../backup.tar.gz .

(mv = move – ../backup.tar.gz is the file to move and the dot on the end means to move the file into the current directory)

Setting up the site on the new server is next on the list. This can be done by accessing any sites Web Host Manager that is currently on the new server.

Once logged in you can add an account by going onto Account Functions > Create New Account …
You need to enter the Domain name, username, password (and re-type) and an email address. After this you will need to choose a package (usually default) and in the DNS settings, check the option “Use the nameservers specified at the Domain’s Registrar (ignore locally specified nameservers)”

Now, open a new putty window for the server which the site is moving to, and access the the public_html of this account – the same way as we have before;

cd home/{yoursite}/public_html

once in this directory, you will need to get the files from the old server. Firstly, lets get the gzip for the main site, using the following command;

wget http://www. {yoursite}.co.uk/backup.tar.gz

this will show a download bar, and when complete we can download the sql.gz file, using this command;

wget http://www. {yoursite}.co.uk/dbdump.sql

If you are getting the files from a main server through its IP address, the format is as followed;

wget 190.168.0.1/~{yoursite}/dbdump.sql

Servers IP directory on serverfile name

Once we have these files, all it takes is for us to unzip these appropriately, using the following commands;
tar -xvzf backup.tar.gz

once this is done, unzip the sql.gz
gzip –d backup.sql.gz

The next step is to access the cPanel for this new site so that the database can be set up, which can be done by accessing a site or your new serbut enter the login details set up for {yoursite} … see below;

Make sure the database name, username and password match up to the previously established details to avoid conflict.
Once this is done, and all access right are given to the user for the database, you can extract the contents of the sql file into the public html directory with the following command.

mysql -u {yoursite}_magento –p{yourpassword} {yoursite}_magento < backup.sql

NOTE: in the command there is a space between –u and username, but not between –p and the password. This is CORRECT!

Finally, this should be done, however you need to check that it is working correctly before switching the servers in tagadab. You can do this by editing your hosts file to point to the new server instead of the old one. Firstly, open notepad in “administrator mode” and then open the file from the following directory;

C:\Windows\System32\drivers\etc\

and adding the following line (obviously changing the URL and IP address where appropriate.)

To check it is accessing the site through the new IP address, bring up firebug in Chrome , select the network tab, and refresh the page. This should show an initiator as the new IP address. If this is the case, then make all the tests you require to ensure it is in fully working order. If all is well, we can now change over the server details in tagadab, via the following method.

Finally, ensure the new site has all relevant email addresses require set up correctly.

Tags:

Comments are closed

Latest Comments

No comments to show.