par Nyro, Dimanche 20 Avril 2008 à 08:06:07 :: Internet
Before I started to do it, I looked for an howto like this one to be sure to forget nothing. As I didn't find it, I'm writing it for the others!
IntroductionTo be sure everybody understand what we're talking about here, let me explain the problem.
When we want publish a website, we need 2 things: a domain name and a server. The server contains all the websites files (HTML, PHP, Images, etc...)
The domain name is the URL you use to access to our website; nyrodev.info for mu blog for example. This domain name should redirect your visitor to your server to access the files. Your server is reachable through an IP address. The link between your domain name et the IP address is done with the DNS. DNS are online computers which everybody can ask to know the IP address related to a domain name.
The server is here to stock your files. It's basically a computer with some special softwares. A server can contains multiple websites. That mean more than 1 domain name can point to the same server. The choice of the right files in the server will be done via many softwares well parametered for each website. I won't speak about this part here. Most of time the dedicated server provided administration tools to configure automatically every software during the website creation.
My goal is to change the server. I have to transfer the files (images, pages html, etc...), the eventual database and more. At the end, we'll change the IP address where point the domain name to use the new server.
Next you'll see some actions to do that in the good order to don't have problems, by loosing at least at visitors during the transfer time.
In the next of this post:
- domain.com: The domain name to transfer
- Server A: old server, where the website is at the beginning
- Server B: new server
1. Prepare the BasicsThe first step of this transfer is to prepare the server B to receive the new website. Create in your administration to get some disk space to receive your files. You can give him directly domain.com to save time. Don't forget to set the mail parameters, FTP, etc... It doesn't cause any troubles as domain.com still points on the old server.
Then you can create the email and email alias that you have on the server A to don't lose any email. Regarding the databases, create them without the tables. This will be done in an other part.
2. File TransferFor now we can transfer the static files. Don't transfer now the uploaded or dynamic files because the current website is still available in the old server, and some upload can still occurs.
If you have a SSH access on the server A, why don't create a tar.gz archive to group all the files in one compressed, to gain some time?
Go to the directory containing your files, and to create the archive:
tar cvzf DIRECTORY.tar.gz DIRECTORYRetrieve the file by FTP and send it to the server B, where you should also have a SSH access. In the directory where you uploaded this archive, decompress the file:
tar xvzf DIRECTORY.tar.gzThese files will probably contains some database configurations, .htaccess files with absolute path, etc... Many configurations which will be probably different in the new server. Edit them now.
If you don't have a SSH access, simply retrieve normally your files by FTP. You can make the change in the configurations files before transfer them..
Moreover don't forget about the chmod of the directories where your script has to write some files.
Right now, your website should be ready to use in the new server by simply adding the database content.
3. Temporary Website Closure
To be sure to loose nothing during the transfer, we'll disable the whole website in the server A, just before transferring the database and the dynamic files.
We'll start by closing the whole website by simply using one .htaccess file, denying everything and redirecting to a single text page to explain about the moving. The .htaccess is:
Deny from allAnd you can create the file transfer.php to explain it's temporary and won't during more than 24 hours.
Allow from all
ErrorDocument 403 http://www.domain.com/transfer.php
4. Transfer the Last Elements
Once the website is close, we can transfer the dynamic files. You're sure they won't be new in the old server. You can use the same technique used in the 2nd step.
Now the Database transfer.
If you don't have a SSH access, simply use phpMyAdmin to export your database from the server A to import it in the server B.
If you have a SSH access, it could be better to proceed differently for 2 reasons: the phpMyAdmin export is sometimes buggy, and if your database is too big, phpMyAdmin will give you some timeout errors.
We need only 2 command lines. The first to export the database in a text file in the server A:
mysqldump --host=localhost --user=USER --password=PASS --add-drop-table DATABASENAME > base.sqlThen transfer this base.sql file to the server B and execute this command:
mysql -h localhost -u USER --password=PASS DATABASENAME < base.sqlYour website should be now totally ready in the server B. If you can test it to be sure everything is OK before the final transfer.
5. Edit the DNSFinally you can do the modification in your domain name to point it to the server B, by editing the IP address in your DNS. And wait for testing. If you want test quicker if everything is good, I strongly recomand to use the DNS server from Open DNS on your computer —why not keep them later?. The gain with Open DNS is they are very fast to update, and you can force it to refresh the cache. Do it for your domain name 15 to 20 minutes later your change.
If they're going to the new IP, refresh your DNS on your computer. For Windows: Start > Execute > cmd. Then type:
And finally test on your favorite bowser after clearing your cache too. It should be OK.
During the next few days, you have to retrieve your emails in the both server as some DNS will not be up to date everywhere.
Voilà, I hope this howto will be usefull for you. For sure you have different solution for every step. I simply showed which I used and they worked perfectly for me.
If you have any suggestions, remarks, feedback, don't hesitate to comment here!
Thanks to Niko who advised me during my transfers.
Version Française de ce billet
Aucun commentaire :: 8 262 lectures