Magento development environments with different database connections

Advertisement:

After explaining, how to use Different database connections in WordPress development environments, I’m going to show, how to set up Magento development environments with different database connections. Magento works a little different here, since it has its database connection in an XML file rather than a configuration .php-file.

!This post is seriously aged.The world has moved on and the stuff described in this post might be outdated. Having trouble getting this to work? Leave a comment and I'll have a look into that.

You probably already know, that the database server, database name, user and password for Magento are set in the app/etc/local.xml-file. On my Magento project, I had a copy for every single one of the Magento development environments with different database connections. That was very similar to my habit on working with WordPress and changing databases on development environments and so I was working with a local.xml.dev local.xml.live and local.xml.test, renamed the file to local.xml after each git branch checkout and replaced it as needen for the current environment.

After finding a solution for WordPress, I kept searching for an idea on how to manage Magento development environments’ database connections easily. Eventually, I found this blog post (and another one) and all of a sudden, the scales fell off my eyes. It’s so darn easy!

How to set up Magento development environments with different database connections

All you need is console-access to your webserver(s) or developing environments with an app like PuTTY.

  1. Create a variant of the local.xml for each Magento development environment with its database connection and five the filename a recognisable pre- or suffix.
  2. Copy those files with the FTP-App of your choice to the app/etc/-folder of your Magento installation.
  3. You can add these file to your version control software now and .gitignore the local.xml. You might then want to remove the local.xml from the folder either with git rm --cached or similar, or manually via FTP.
  4. Access your webserver or dev-server with a console-app like PuTTY and navigate to the app/etc/-folder of your Magento installation.
  5. Know the filename of the Magento database configuration file you will need for the current environment.
  6. Enter
    ln -s {filename for current environment} local.xml

    in your webserver’s console.

  7. Done!

What is does

The code you entered (or will enter) to your console creates a symbolic link. So rather than changing your content of the local.xml for Magento development environments with different database connections, you are changig the target of the link named local.xml for each environment.

Since the symbolic link is .gitignore-d, you don’t have to change it after checking out a new branch on our repo, it just resides there alongside your other config-files.

Don’t worry that the symlink is chmodded 0777 – that’s normal to Linux and you cannot change this. Magento however doesn’t seem to care, what file permissions local.xml has and whether it actually has content or is just a symlink – at least up to version 1.9.2.2.

If Magento fails

If you can’t access Magento after creating the symbolic link, make sure your webserver is set up to Follow SymLinks, either in virtual hosts configuration file or in the .htaccess‘es of your Magento installation.

So now you have set up Magento development environments with different database connections each and don’t have to worry about changing that local.xml file on every machine and messing up your version control history with that anymore.

Like this post? Share it!

Advertisement:

One thought on “Magento development environments with different database connections

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>