Set Up a Local PHP Web Development Environment

I came to the realization that it would probably be best to do all of my heavy testing and development on a Ubuntu server locally. I use VirtualBox with Mac OS X as my host and installed Ubuntu 9.10 as a guest. This allows me to use Synaptic Package Manger to install Zend Server which has everything I need to start testing. This is by far the easiest way I have used to set up a local server. Having done that on Windows and Mac, I love the way Synaptic Package Manager handles everything. My only problem came when I needed to have multiple projects going on and wanted a nice way to access them on localhost without using subdirectories.

After a bit of searching, I found this thread and it helped me set up a nice little dev environment. For PHP programmers who are using subdirectories (like I used to), I would recommend using this approach on Ubuntu, because it’s just so easy and very clean. It uses Apache VirtualHosts to access your projects like instead of having it in a subdirectory like http://localhost/myproject. This post will also serve as my reference guide for when I need to set up more projects.

This is specifically for setting up a new Zend Framework project on Ubuntu running the Zend Server stack (Apache, MySQL, PHP 5.3, etc.), but could be used for any PHP application or script. One thing to note is that I place all my projects in /home/ryan/web/php. If you have a different place, be sure to change the path where needed.

1. Create an empty file named “projectname” in /home/yourusername/web/sites-enabled and add:

<VirtualHost *:80>
DocumentRoot /home/yourusername/web/php/projectname/public

2. Create a symlink to sites-enabled (this step only needs to be done one time, once this directory symlink is established, it will always work):

sudo ln -s /home/yourusername/web/sites-enabled /etc/apache2/sites-enabled

3. Edit your hosts file, sudo gedit /etc/hosts, and add another host to the end:

4. Restart apache: sudo /etc/init.d/apache2 restart

5. Test:

So there you have it. While it does take a little longer to set up than a regular subdirectory, (I just tested this out, and took literally 1 minute), it’s definitely worth the extra effort.

Your email address will not be published. Required fields are marked *