How to do multiple virtual hosts on OS X
- Download and install VirtualHostX (don’t forget to back up your existing config!!)
- Download and install Gas Mask (manages multiple hosts files, dumb name though)
- If you want to do this with WordPress and you have a database locally and another one on a dev server somewhere, you can do the following code:
if(eregi(“^mywebsitename.com$”, $_SERVER[HTTP_HOST]))
{
define(‘DB_NAME’, ‘dbremotename’);
/** MySQL database username */
define(‘DB_USER’, ‘dbremoteuser’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘dbremotepassword’);
/** MySQL hostname */
define(‘DB_HOST’, ‘dbremotehost’);
define(‘WP_SITEURL’, ‘http://mywebsitename.com’);
define(‘WP_HOME’, ‘http://mywebsitename.com’);
}
else{
define(‘DB_NAME’, ‘dbremotename’);
/** MySQL database username */
define(‘DB_USER’, ‘dblocaluser’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘dblocalpassword’);
/** MySQL hostname */
define(‘DB_HOST’, ‘dblocalhost’);
define(‘WP_SITEURL’, ‘http://mywebsitename.com’);
define(‘WP_HOME’, ‘http://mywebsitename.com’);
}
March 27th, 2009 at 8:52 am
So VirtualHostX is a nice interface to /etc/apache2/extra/httpd-vhosts.conf, and Gas Mask is a simple editor for /etc/hosts? I’ve been doing it the hard way! One other thing I need to play with is the hosts file in Windows under VMware, then I’ll be set.
March 27th, 2009 at 9:10 am
Yup, exactly. Saves tons of time, and gas mask can create multiple hosts files then creates a symlink to the file you want to activate at the time. So you can have more several hosts files that you swap around.