5

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?

Randy
  • 16,480
  • 1
  • 37
  • 55
Tom
  • 33,626
  • 31
  • 85
  • 109

9 Answers9

12

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,

Istvano
  • 992
  • 1
  • 12
  • 19
  • Wow, it's hard to believe Magento lost the environment support ZF has out of the box, but I'll probably end up rolling with this approach, thanks. – quickshiftin Sep 14 '14 at 16:20
  • I agree quickshiftin. It seems ridiculous that there is no support for enviroment configurations. – Artistan Sep 22 '14 at 14:32
6

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.

Prattski
  • 2,055
  • 2
  • 13
  • 16
  • How would this look, would we keep the config file for each environment in a separate branch and merge the changes in? – Tom Feb 09 '11 at 17:35
  • 7
    One way to approach this is to completely remove app/etc/local.xml from source control. Then add a local.xml.dev, local.xml.stage, and local.xml.prod to source control. When you deploy to stage, you also have a script that copies the appropriate local.xml version as needed (ie, cp local.xml.stage local.xml). – shaune Feb 09 '11 at 18:27
  • I keep the filename the same for each version (trunk, stage, etc.) and then use `.svn-ignore` to prevent the development ones overwritten production ones. It also prevents accidental changes of any sort. Some Magento-aware hosts like Nexcess are pretty good about managing `local.xml` details and I don't want to overwrite their hard work. – clockworkgeek Feb 09 '11 at 18:35
  • @sdek That's probably the approach were going to go for. – Tom Feb 10 '11 at 07:29
  • depending on what version control system you are using it might actually be reasonably possibly ... we use git and then just ignore the app/etc/local.xml and app/etc/config.xml (as well as other config files) then just have a branch for stage and a branch for live ... seems to work well ... although with some other version control systems it is all but impossible ... and yes MUST use separate databases, causes to many problems otherwise – sbditto85 Jan 19 '12 at 15:15
  • This is a terrible answer! Any decent PHP system has the ability to handle mulit-environment configurations... ZF (what Magento is built on) [has support](http://framework.zend.com/manual/2.2/en/tutorials/config.advanced.html#environment-specific-system-configuration) for such. Maybe the morons at Magento decided to rip that feature out tho! – quickshiftin Sep 14 '14 at 16:19
  • Not a good answer. Really. The purpose of a staging environment is precisely to put together code-in-development, data, services, etc. so that it is easy to see if the following step -releasing to production- is enough safe. Of course, for getting that, you have to manage different global environments -for Magento, WordPress, Symfony or whatever-, such as hostnames, database connections, media filesystem, etc. That means you have to develop that tier for integrating things. – inigomedina Mar 10 '15 at 14:47
4

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!

Greg Robbins
  • 610
  • 5
  • 9
1

Magento staging and production

Community
  • 1
  • 1
B00MER
  • 5,471
  • 1
  • 24
  • 41
1

I wrote a guide just for you to explain the process of setting up a staging/dev/live environment with Magento and SVN

http://www.sonassi.com/knowledge-base/staging-development-live-svn-with-magento/

Ben Lessani
  • 2,141
  • 14
  • 16
0

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. :-)

Andrew
  • 12,617
  • 1
  • 34
  • 48
0

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)

sed
  • 5,431
  • 2
  • 24
  • 23
0

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.

Tommy Cox Green
  • 633
  • 1
  • 4
  • 20
  • Have you got a link for how this might actually look? – Tom Feb 09 '11 at 17:22
  • for baseurl and securebaseurl 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) – sed Oct 03 '12 at 14:09
  • I just posted a more detailed info as an answer below. – sed Oct 03 '12 at 14:12
0

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.

AndyDev
  • 1,409
  • 10
  • 17