Friday, July 8, 2011

Virtual Hosts

Notes on getting started with "Easy PHP Websites with the Zend Framework (2011)."

Configuring virtual hosts is one area that may give you grief. Be sure to include localhost as a virtual host as well as all of your other virtual hosts.

First, edit your httpd.conf file. Configure your document root. Mine is:

# DocumentRoot "/opt/local/apache2/htdocs"
DocumentRoot "/Users/frank/Sites"

(The # comments out the line.)

Next, change the directory a few lines below to match your document root:

# <Directory "/opt/local/apache2/htdocs">
<Directory "/Users/frank/Sites">

Next, change the DirectoryIndex directive to include index.php files:

<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>

I needed to put index.php before index.html. YMMV.

And finally, enable virtual hosts by uncommenting the appropriate Include line:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Save the changes.

Now you have to edit your httpd-vhosts.conf file. Add the following directives, then save the file:

<VirtualHost *:80>
DocumentRoot "/Users/frank/Sites"
ServerName localhost

<Directory "/Users/frank/Site">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/frank/Sites/gamenomad/public"
ServerName gamenomad

# This should be omitted in the production environment
SetEnv APPLICATION_ENV development

<Directory "/Users/frank/Sites/gamenomad/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

Now, add the following lines to the bottom of your hosts file, then save:

127.0.0.1 localhost
127.0.0.1 gamenomad

After you restart apache and create a zf project named gamenomad, typing gamenomad in your browser window should yield the welcome screen shown on page 44 of the book.

0 comments: