I usually work with the backend of web applications so I do not get enough training in setting up virtual hosts, so I thought I better put an example up here. At least to have something to start with.
I use the built in apache server on OSX and I usually put my virtual hosts in the <username>.conf (/private/etc/apache2/users/<username>.conf) where <username> is simply your username 🙂
Example:
<VirtualHost *:80>
ServerName my.zendapp.com
DocumentRoot "/Users/<username>/Sites/myzendapp"
ServerAdmin admin@my.zendapp.com
<Directory "/Users/<username>/Sites/myzendapp">
Options Indexes FollowSymLinks
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
To get my.zendapp.com to work we need to put an entry in the hosts file like this:
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 127.0.0.1 my.zendapp.com
To reach your new zendapp go to: http://my.zendapp.com/public
If you want to use http://my.zendapp.com instead just add the public part to the DocumentRoot:
DocumentRoot "/Users/<username>/Sites/myzendapp/public" ServerAdmin admin@my.zendapp.com
and the Directory:
<Directory "/Users/<username>/Sites/myzendapp/public">
Options Indexes FollowSymLinks
NOTE! Depending on your choice in urls you may need to change the .htaccess (/Users/<username>/Sites/myzendapp/public/.htaccess) file accordingly:
For long url (http://my.zendapp.com/public):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /public/index.php [NC,L]
For short url (http://my.zendapp.com):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Tested on OSX 10.7.4 and Zend Framework 1.10.8