How to do multiple virtual hosts on OS X

  1. Download and install VirtualHostX (don’t forget to back up your existing config!!)
  2. Download and install Gas Mask (manages multiple hosts files, dumb name though)
  3. 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’);

}


2 Responses to “How to do multiple virtual hosts on OS X”

  • Nathan Youngman Says:

    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.

  • jeremy.massel Says:

    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.

Leave a Reply