Multiple Magento Environments

We have a Magento store setup and under version control, we’d like to setup a staging store which uses the same code but different connection details. e.g. Live details for the live store and a staging database for staging.

Is this possible with Magento, there doesn’t seem to be a way to do it by default?

9 thoughts on “Multiple Magento Environments”

  1. Tom,

    Since you are using version control, I’d suggest you not have the same files for both staging and production. That’s generally a bad idea. Ideally, you should have a different environment for staging and production, both having their own set of files, and their own database. This way, you don’t have to worry about the hurdle you are experiencing now.

  2. There are many ways, one of the easiest that requires no additional extensions is

    -> create

    • /app/etc/local.xml.dev
    • /app/etc/local.xml.live
    • /app/etc/local.xml.stage

    and do NOT version control local.xml

    and symlink the right file at each environment this way you can keep all connection info in svn or git,

  3. I have had to do this many times. I pretty much use the same suggestions listed here, but to summarize…

    /app/etc/local.xml

    In version control I keep these files, each with its own DB and caching data. These are modified copies of the original local.xml file:
    – app/etc/production.local.xml
    – app/etc/staging.local.xml
    – app/etc/my-dev.local.xml

    The local.xml file created by installation is deleted. It gets replaced with a softlink local.xml to the appropriate file in each environment:

    cd app/etc
    ln -s production.local.xml local.xml
    

    Notes on managing different databases:

    Then I usually create a new root-level directory called /sql and in there I keep scripts like these which are used to setup alternate environments:

    • createdb.sql
    • production.setup.sql
    • staging.setup.sql
    • my-dev.setup.sql

    createdb.sql gets run as a MySQL admin user and just sets up the database and the user.

    create schema magentoschema; create user magentouser;
    grant all on magentoschema.* to 'magentouser'@'localhost';
    set password for 'magentouser'@'localhost' = password('secret');
    

    Once you create the database you can go to your original installation and get a mysqldump of the the database:

    mysqldump -u magentouser -p -h your.host.name magentoschema > magento.dump.sql
    

    then install it to whatever environment you are working in:

    mysql -u magentouser -p -h localhost magentoschema < magento.dump.sql
    

    You then need to change the hostname (and possibly some other paramters as well) in core_config_data. The most basic looks like this:

    update core_config_data set value='http://staging.yourstore.com/' where config_id in (3,4);
    

    You need to check your Magento installation to see what the config_id is for the entries with web/secure/base_url and web/unsecure/base_url in the path column. It’s easy, jsut do a query like this on the database:

    select * from core_config_data where value like 'http%';
    

    So create the *.setup.sql files with the correct hostnames for each environment and run the script in mysql just as you did to load the database:

    mysql -u magentouser -p -h localhost magentoschema < staging.setup.sql
    

    Good luck!

  4. You can do this.

    You need to focus on the local.xml in the etc folder and set the db settings accordingly.

    Also change the secure and non secure base url field values in the core_config_data table.

  5. Not sure if this is possible.

    Could you create a PHP file with an IF statement that would then echo out the relevant XML for an environment. You would then have to make this accessible as local.xml through .htaccess.

    After this has been done ensure that it isn’t available from the outside world.

  6. Duplicating the store for development is easy with Magento.

    As you have your code in version control, you simply follow these steps:

    1) Create a backup database, export it as SQL.
    2) Run Search and replace on the file, replacing yourwebsite.com with stage.yourwebsite.com
    3) import the new database into MySQL.

    4) Checkout out files from version control to your staging site document root.
    5) modify app/etc/local.xml – change the database settings to your new database and username / password.
    6) empty var/cache/ and var/session folders (hopefully you never added them into your version control system).

    Job done. 🙂

  7. Follow the instructions here
    http://www.magentocommerce.com/wiki/groups/227/moving_magento_to_another_server

    and move your production environment into a local machine, after setting up wamp or zend server on your machine.

    to do that, you need to have some sort of local server running on your staging machine (doesnt need to be a server, may as well use your laptop)

    for staging setup:

    baseurl and securebaseurl settings in the back end of staging site, use “localhost” and keep the staging environment hosted on your own machine (you can do that using zend server or wamp/lamp running on your machine depending on your OS, than copy the whole thing over to your staging machine)

Leave a Reply

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