Apache2 and mod rewrite

I have decided that I want to play around with the Zend framework for PHP. One of the big reasons for this is it will force me to code in an object-oriented fashion, instead of procedural. Object oriented coding is something that I have never been convinced to make a switch to. I would love to be using Canvas, except that its documentation and support cannot rival that of the Zend community (and I need a LOT of documentation).

Lately, I have been seeing the benefits of strongly-typed data objects as are mandated for the data tools in ASP.NET. This allows for some cool stuff like having a data abstraction layer that is completely aware of how to structure SQL for UPDATE, DELETE, and INSERT statements just based on the query that you specify for SELECT. Also, paging, and sorting on any data views are available with just a click. All of these concepts are not exclusive to ASP.NET however, and I am determined to explore these avenues in other environments.

So back to my roots with old-fashioned PHP. Yes, the aging language that can’t possibly keep up with ASP.NET applications – or can it?

Today, I setup the environment that I will be working with the Zend framework in. My stack is Ubuntu 7.04, Apache 2, PHP 5, MySQL 5, Zend Preview 0.7, and Zend Studio 5.5 (which I also wanted to try). The setup (including installing the OS) took about 45 minutes . For those keeping score, this is PHP 1 / ASP 0.

I got stuck at the new layout for Apache 2. It uses a modular system consisting of pairs of *-available/ and *-enabled/ folders to house modules, and websites. It works in a fashion similar to the /etc/init.d/ folder, where symlinks are created for the different run levels. I got stuck at the rewrite mod for Apache – it was silently failing. I did find some excellent documentation on enabling the plugin. You will need to manually create a symlink, or use the command below to enable the module (which is disabled by default):

$ sudo a2enmod rewrite

Also, in your sites-available/ folder inside /etc/apache2/ you will find a symlink to your configuration file for the currently running website(s). This is where I made my fatal error. The file 000-default (default that I edited) looks like this:

NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/apache2-default/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/apache2-default/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/

You will notice that there are two different sections, one for “Directory /” and one for “Directory /var/www/…”. I spent most of my energy messing around with the “Directory /” to attempt to get the .htaccess file I created to process. The second directory should have been the one that I was editing, as it pertained to the path that I was operating my .htaccess file out of.

What is not clear to me is that if my DocumentRoot reflects the same path as my Directory (2), then shouldn’t the root webserver directory (1) be the same? In this case, it would seem that “DocumentRoot /var/www/apache2-default/www/” should be the same as “Directory /”. There is some discrepancy, between the two. When I changed my “AllowOverride” to “All” in the second Directory section, the rewrite mod became active.


1 Comment

  1. Bellona says:

    Happy Valentines!


Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.