Setting up an Apache Webserver for Development on OSX
I do quite a bit of web development, and I like to run virtual hosts of my production web sites locally, makes for an excellent, develop/test/release cycle and I can work anywhere (even on a plane). To do this I setup some virtual hosts on my Apache server called dev.domain.com, e.g. dev.sinclair.org.au which points to 127.0.0.1 and then in the apache config I setup virtual hosts pointing to those server names, and wallah. Below is a little more detail on getting this setup on my new MacBook Pro running Leopard OSX.
Host Entries
First you need to create a host alias in your /etc/hosts file. sudo vi /etc/hosts Then add an entry like this: 127.0.0.1 localhost dev.randomkaos.com Save and exit the file ":wq". If you don't know how to use VI, you will need to find another text editor you like.
Apache Config httpd.conf
I really like the way the OSX team have setup Apache, its very similar to how it would work on Linux or Solaris. The Apache config file can be found in OSX in "/etc/apache2/httpd.conf", I edited this file and uncommented the following line: # Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf I also prefer combined logs so I changed to this: #CustomLog "/private/var/log/apache2/access_log" common CustomLog "/private/var/log/apache2/access_log" combined There are some other changes I made, but nothing which impacts this setup.
Apache Config httpd-vhosts.conf
I then edited /private/etc/apache2/extra/httpd-vhosts.conf and made the following changes:
ServerAdmin keith@sinclair.org.au
DocumentRoot "/Users/keith/wwwroot/sinclair.org.au"
ScriptAlias /cgi-bin/ "/Users/keith/sinclair.org.au/cgi-bin/"
ServerName dev.sinclair.org.au ErrorLog "/private/var/log/apache2/sinclair.org.au-error_log"
CustomLog "/private/var/log/apache2/sinclair.org.au-access_log" combined
Options Indexes FollowSymLinks ExecCGI
AllowOverride None
Order allow,deny
Allow from all
I am using this wwwroot directory as a throw back to the way I have been doing things forever, and I decided to keep this under my "/Users/keith" directory because it keeps is all together for backup and restore. Restart Apache sudo apachectl restart Test Make sure it works now. Publish with iWeb I have discovered iWeb and so far I am impressed, it generates XML valid HTML and it uses "divs" and takes the pain out of the HTML. I am pretty fussy about this sort of thing, and in the past have used Hand editing or Perl scripts to generate all my web sites, probably not anymore. So I am working on a sub-directory of sinclair.org.au, being "keith" the full URL for this would be http://www.sinclair.org.au/keith/ So when I publish in iWeb, the "Site name" is "keith" and the "Folder Location" is "/Users/keith/wwwroot/sinclair.org.au". If I was publishing the whole website, it would be with the "Site name" is "sinclair.org.au" and the "Folder Location" is "/Users/keith/wwwroot/". THIS WOULD MEAN that the htdocs would be redundant. When I publish it creates the sub-directory The directory to publish to is: Reference I have done this type of thing more then a few times on Linux and Solaris, the only hard part is learning the new directory paths, but Google and this page, were all I needed, Installing Apache, MySQL and PHP on Leopard.
