Why Is My htaccess File Causing an Internal Server Error 500?

This was the odd problem that I faced when I switched hosts last month. My other website (Babel) was working fine. I uploaded everything to the new host, and every page came up with an “Internal Server Error 500.”

I eventually narrowed the problem down to the htaccess file. I wasn’t quite sure why it was breaking everything… but if I renamed it, the files worked fine.

At first I thought it was a problem with the mod_rewrite lines in the file. They turned out to be fine. The problem was much more benign - a call to change a php flag for register_globals.

After a bit of research and some chatting with tech support, I realized that the problem was that php was being run as a CGI executable instead of an Apache module.

What Does it Mean for PHP to Be a CGI Executable?

On the surface, there’s not a whole lot of difference. Your scripts should still execute just fine.

However, your htaccess file can’t modify ini settings. For example, the server I was on had ‘register_globals’ on and I wanted to turn it off. No can do with htaccess.

There are also some performance concerns. If you’re thirsty for knowledge, check out this section of Practical PHP Programming on the topic.

So How Do I Customize PHP Settings?

You can’t use the htaccess file, but there is a different way - a custom php.ini file. Basically, you build your own php.ini file, place it in the appropriate directory (usually cgi-bin), and your problems are fixed.

The php.ini file is pretty long, so don’t try to write it from scratch. You can find the latest php.ini file on php.net.

You can copy the “Recommended” version, and it should have most of the settings you want. It’s optimized for security and speed, unlike some development versions - which give up some security for error checking.

Upload the recommended file to the directory containing the php executable and then edit the file to contain the precise settings you want.

This is a simple problem with a simple solution. However it took me the better part of a day to figure out what the hell is going on. Hopefully this saves you a bit of time.


Bookmark and Share:
These icons link to social bookmarking sites where readers can share and discover new web pages.

  • Digg
  • Furl
  • del.icio.us
  • StumbleUpon
  • MisterWong
  • DZone
  • Technorati

Tags: , , ,

Leave a Reply