Developing PHP application from Home Directory in Ubuntu

I find all kinds of tutorials on the net about how to install php/apache/mysql for Ubuntu.
Its incredibly simple to get the basics setup, but creating a methodology for doing real development, for multiple clients simultaneously, is a bit more complicated.

Typically I would start out with something like this:

sudo aptitude install php5 mysql-server apache2.2 php5-mysql php5-mysqli

There are probably a bunch more modules I'll end up needing, but they are easy enough to figure out when the time comes (you may even want to install php5-cli to get a command line interface for writing php scripts that won't be used for a website).

What is more important though is setting up config files for development. Personally I hate developing in /var/www since I am not the owner of these files and I must resort to changing the ownership, messing with groups, etc. I always prefer to work in my home directory. Sure you could provide a build script to copy your work to something like /var/www/yoursitename each time you do any updates, but its just easier to setup your site somewhere within your home directory.

Instead of working from /var/www, I create a web directory in my home folder, and then I put each site as a subdirectory in that folder. For each site I create a virtualhost configuration files under /etc/apache2/sites-enabled.
Basically this boils down to creating a new config file with whatever the name of your site is, and filling it in like this:
(file name is real_sitename.com)

<VirtualHost *:80>
  ServerName local.real_sitename.com
  DocumentRoot /home/your_username/web/real_sitename.com
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  <Directory /home/your_username/web/real_sitename.com/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>
</VirtualHost>

After that you enter the command:

sudo a2ensite real_sitename.com

make sure you enable whatever modules you need as well.

Also note that if you want the ability to refer to your site by different names (to facilitate your site going local to production), you can add a ServerAlias entry (just before/after ServerName would work fine).

Lastly, you'll need to edit your /etc/hosts file to include a line like this:

127.0.0.1 local.real_sitename.com

The cool thing is you just add one of these for each site you create. Each site will have its own virtualhost entry and its configuration will be similar to how it is on the production machine, in that you won't have to worry about your site being a subdirectory of the DocumentRoot (as many inexperienced developers find out is quite a pain to deal with).

There is one more thing you may need to do if your home directory is not readable by the anyone group. And that is, make it readable, or you'll need to be sure that the user that apache runs under (I think its apache or httpd user) has permissions to your folder.
The easiest way to do this would be add that user to your group and then allow group read permissions for your home directory.