RSS Feed

Set up magento in multiple environments


I just started digging in the shop software magento for a project and set up the following development environment.

In this scenario development is done on two local machines while products and pages beeing already edited on the “Live”-Web-Server.
Git is used for version control and deployment. Also FTP SSH.

sync multiple Magento environments

Magento is quite nice when it comes to deployment, as most config stuff is stored in XML files.
Those files are kept locally and ignored from version control.

So this is what my .gitignore looks like:

#cache, sessions, logs
#media folder - images etc...

#local config files

#database dump

So i got a copy of the repository in each environment with a local .htaccess and local.xml file.

Theres a few things stored in DB by magento, though.
The most obvious is the “web/secure/base_url” and “web/unsecure/base_url” which both reside in the “core_config_data” table.
Those have to be set to the name of the host you’re working on.

This can be done with a shell script like this:

#create a dupm of the live DB on the server
ssh 'mysqldump -u[username] -p[password] > ~/db_dump.sql'

#copy DB dump to local machine
scp ./database.sql

#import SQL
mysql -u[local_mysql_user] -p[local_mysql_pw] [local_db_name] < ./database.sql

#update config settings in the DB
mysql -u[local_mysql_user] -p[local_mysql_pw] [local_db_name]<UPDATE
SET value=''
WHERE value ='';

This way all CMS and products  can be edited on the server, while the local machines can be easily synched.
For me this works fine, as we are working only in the file system in the local environment.
In case you can’t use the online Server as “database master” this might be not that simple.

As we most likely don’t want the whole /media folder under version control we might want to have another shell script to copy the media files to the local machine (via SCP in this case):

#remove local media folder
rm -rf ./media/*
#fetch media files
scp -r* ./media

I guess this could be done more efficiently with maybe ant or something.
But for the moment this works fine for me.

So now i can update my local environment with one line on the console:

git pull; sh; sh

One response to “set up magento in multiple environments”

  1. Gijs says:

    This way you can stream your DB to your live server:

    mysqldump -udblocalluser --ignore-table=localdb.core_config_data localdb | ssh sshserver 'mysql50 -Ddbremote -udbremoteuser -pdbremotepass -S/var/lib/mysql50/mysql.sock' 

    If its the first sync you need to remove the ignore, but for later syncs and you didn’t changed any system configs you can add it so you don’t have to replace the domain names.


Leave a Reply

Your email address will not be published. Required fields are marked *