I’ve set up a wordpress install on appfog (using rackspace), and cloned the install to my local machine for development. I know the install works (using MAMP) because I created a local mysql database and changed wp-config.php to point to it. However, I want to develop without having to change wp-config.php every time I commit. After doing some research, it seems like the Appfog service Caldecott lets me tunnel into the mysql database on the server, using af tunnel
. Unfortunately, I’m having issues with getting it working. Even if I change my MAMP mysql port to something like 8889, and tunnel mysql through port 3306, it looks like it’s connected but I still get “Error establishing a database connection” when loading my localhost WordPress. When I quit the mysql monitor (using ctrl+x, ctrl+c
), I get a message stating “Error: ‘mysql’ execution failed; is it in your $PATH?’. Originally, no, it wasn’t, but I’ve fixed my PATH variable on my local machine so that when I go to Terminal and just type mysql
, it loads up.
So I guess my question is 2 parts:
1.)Am I going with the right approach for WordPress development on my local machine
and
2.)If so, why is the tunnel not working?
One way to deal with this is to mimic the
VCAP_SERVICES
environment variable on your local system with your local database settings. This would allow you to use the same custom AppFog wp-config.php file which looks at VCAP_SERVICES to get its db creds.EDIT: You will need to restart the Apache server in MAMP after setting this env var. (Thanks Dex)
This will eliminate the need to point your development code at your production database.
simply test for whether vcap_services are available. if they are, use one config. if they arent, use a different config.
here is an example of my local + appfog development website configuration file.
also, you can use .afignore same way you’d use .gitignore to ignore some files from the af update feature. u can update once with appropriate config, then add afignore, then it will never get updated again.
Here is a quick and very dirty script to automate the process based on Tim Santeford’s answer. Be sure to change the LOCAL_DATABASE_NAME