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!