I need a stable environment for developing Wordpress sites. My own computer and laptop are not stable enough :). I also do not want to edit files remotely on the (production) server. Anyway, I have found that an easy way to achieve a stable environment is to setup a virtual machine (in VirtualBox for my case) and then share a local directory with the machine. Most virtual hosts would reside in that directory.
My VirtualBox host is Slackware and the guest is Debian (Squeeze at the moment, but I will upgrade to Wheezy soon). This small guide assumes you have already installed Debian in VirtualBox and set up Apache and other services/tools you might need (such as PHP and MySQL).
In my setup I have virtual hosts in the directory
~/sites on my physical machine. This is shared as the
sites shared directory in the VirtualBox machine settings. During the boot the machine will automatically mount it using the
/etc/fstab file. For this, the file contains an entry:
sites /var/www/sites vboxsf uid=33
The entry tells the machine to mount the share
sites to the directory
/var/www/sites using the VirtualBox (pseudo) file system. The option
www-data to be the owner of the root of the mounted tree. This allows Apache to write files in the directory. Apache logs will be put there so they can be easily accessed for debugging purposes.
To add a new virtual host, the following has to be done. On the host machine, create a directory for the site files:
Then add a vhost file on the virtual machine. On Debian the file goes into
/etc/apache2/sites-available/<vhost_name>. The contents of the file could be simply:
<VirtualHost *:80> ServerName <vhost_name> DocumentRoot /var/www/sites/<vhost_name> ErrorLog /var/www/sites/<vhost_name>-error.log LogLevel warn CustomLog /var/www/sites/<vhost_name>-access.log combined </VirtualHost>
Then enable the site and reload the Apache conf:
a2ensite <vhost_name> service apache2 reload
To access the site,
/etc/hosts entry needs to be added on the host machine:
I setup my virtual machines to use bridged adapter (so you are in the same subnet as the virtual machine). Finding the correct IP address is then done by running the
ifconfig command in the machine. Look for
inet addr in the command output. This will tell the IP.
If all goes well then the site will appear at the address
http://<vhost_name> in your browser. Logs will be available in
~/sites/<vhost_name>-*.log. The process of adding a virtual host could be automated with shell scripts or tools like Chef/Puppet/Vagrant.