Wednesday, June 6, 2007

Apache + CGI + .htaccess = trouble

I changed the domain name for Bodyzilla (which is running on a Linux box in Apache). I'm running Bugzilla, which God-only-knows-why is written in Perl and runs as CGI. Who in this modern day and age still uses CGI? Everybody has moved onto greener pastures, like PHP, ASP.NET or Java.

Anyway, after changing the domain name Bugzilla stopped working. I had just gone through hell a couple days earlier setting it up. Good thing I have root access to my server... I had to actually modify the httpd.conf to give the bugzilla directory the proper permissions. I hate configuring Apache so I just copy-pasted from some web site. Well, now it wasn't working and I had to find out why.

When your CGI script doesn't work, what happens is you get an Internal 500 error in your browser. This is useless and tells you nothing. If you're lucky, you'll have access to your site's error log. But even if you do, access is useless if you don't know where the error log is LOCATED. The problem with web servers that run on Linux is that every installation seems to be set up differently. You can try Googling to find the path to a certain file, but most of the time the path you find just won't work.

On my server, the web server error log is located at /usr/local/apache/logs/error_log. You can view the last few lines of this gigantic log file with this command:

$~ tail /usr/local/apache/logs/error_log


Doing this, I discovered the error:

/home/bodybugz/public_html/bugs/.htaccess: RewriteEngine not allowed here


Evidently the RewriteEngine needs to be turned on in the bugs directory (which is where Bugzilla is installed). I didn't know why at the time, but in hindsight the .htaccess file contains this line:

RewriteEngine on


It seems that RewriteEngine is off by default, and needs to be specifically turned on for this directory. Luckily, I knew by Googling that I needed to edit my httpd.conf, and the path to this is /etc/httpd/conf/httpd.conf.

Here is what my configuration was:

<Directory /home/bodybugz/public_html/bugs>
AddHandler cgi-script .cgi
Options +Indexes +ExecCGI
DirectoryIndex index.cgi
AllowOverride Limit
</Directory>

And here is what I had to change it to:

<Directory /home/bodybugz/public_html/bugs>
AddHandler cgi-script .cgi
Options +Indexes +ExecCGI
DirectoryIndex index.cgi
AllowOverride All
</Directory>


This allowed the .htaccess to override the default server setting for RewriteEngine.

Don't forget to restart Apache whenever you change the httpd.conf.

$~ service httpd restart


Conclusion: No mere mortal can possibly comprehend all the complexities of Apache configuration. Don't attempt it unless you want your head to explode.

2 comments:

Anonymous said...

There are plenty of sites that use CGI. Slashdot being one of them websites.

Perl/CGI is great. I don't know how you figure it is abandoned.

Anonymous said...

студентки онлайн видео http://free-3x.com/ анальная школа free-3x.com/ школьницы развратницы от 18 лет [url=http://free-3x.com/]free-3x.com[/url]