Moving an ExpressionEngine site from one server to another, or even one domain to another domain, is a complicated process. Whenever I’ve attempted to do this I’ve found that the hardest part is making sure that the database is correct for the new location. This involves copying the database across and then making sure I change every path and domain through the control panel to the new values.
I’ve never succeeded in migrating successfully using the manual method. I always miss something and have to deal with some small problem that inevitably crops up. Finally, I decided to make it easier on myself, so I wrote a script to perform the update for me. This will not be for everyone, however if you’re comfortable with command line scripts and ruby this may do the job for you.
The script (the impatient among you can find it at the end of this article) does one job and one job only. It takes a MySQL dump from an EE database and makes the updates required for any domain name and path changes, writing these out again in the format of another MySQL dump. For example, if I tell it that my development site lives at /www/deeden.tld and my production site at /www/deeden.co.uk it updates the database to reflect this, dealing with all of the complications that arise, such as correctly dealing with the serialisation which some of the tables use.
An example of performing the above update would be…
ee_migrator --current_domain=deeden.tld --new_domain=deeden.co.uk --current_path=/Users/steve/Sites/deeden.tld --new_path=/www/deeden.co.uk development_sql.txt > live_sql.txt
This runs the script (assuming it is named ee_migrator) and changes all occurrences of the domain deeden.tld to deeden.co.uk as well as changing the path to the web site from /Users/steve/Sites/deeden.tld to /www/deeden.co.uk. Rather useful when I’ve been developing a site on my iBook and want to move it to the live server.
I’ll put together a page with full instructions on the use of the script in the next few days. For now I’ll give a brief explanation of the parameters…
-h, --help-t, --table_prefixexp.-a, --all_data--all_data allows all data to be copied, unsurprisingly.-c, --current_domain <OLD DOMAIN>deeden.tld. In the case where the domain isn’t changing simply leave this option out.-n, --new_domain <NEW DOMAIN>deeden.co.uk. In the case where the domain isn’t changing simply leave this option out as well.-s, --current_path <CURRENT SITE PATH>-p, --new_path <NEW SITE PATH>The input file is a mysqldump file, and the output is the same file with the appropriate changes made. Generally I do a dump of my development database, do a quick scan of the output to see that everything looks alright and them import the new database file into my a fresh database for the live site. Your mileage might vary.
There are a few things to bear in mind if you do plan to use this script, such as…
The most recent version of the script is version 1.4. You can also find the script on github.
Clockers by Richard Price.Stephen Rushe lives in Belfast, Northern Ireland with his lovely wife Michèle. He spends much of his time writing code for web applications and pondering his lack of design ability. He has a love for most things Apple. He particularly likes Gill Sans at the moment and wishes he could use it well.
Stephen also wonders how well writing in the third person works. He is not convinced.
25 comments