CentOS

Fixing Apache on CentOS/RHEL 5 for Drupal

Tags: 

While not strictly a requirement, in the interests of not having crazy URLs on your Drupal site it's recommended to set up your web server to support .htaccess files. This will let you have URLs like "/products/cool/stuff" instead of "?q=products/cool/stuff" - obviously much nicer, and better for both usability and search engine optimization. Well unfortunately on Redhat Enterprise Linux 5 (RHEL) and CentOS 5 (which is basically the same as RHEL) the standard web server, Apache, is set to ignore these files. So here's how to fix it.

Whether you're configuring the virtual host in a separate file or in the main httpd.conf, the change you'll want to make is the same:

Step 1: enabling .htaccess files:

  • In the main httpd.conf file (should be at /etc/httpd/conf/httpd.conf) search for the string "AccessFileName",
  • If the line is commented out (it starts with "#") uncomment the line by removing the "#" symbol,
  • Update the line to say:
    • AccessFileName .htaccess
  • Restart Apache, reload the site and.. enjoy the error message :-)
  • On to the second part..

Step 2: allowing .htaccess files to override settings:

  • Find the VirtualHost configuration for the Drupal site,
  • There should be a <Directory> section within that block,
  • If there isn't a line that starts with AllowOverride, add a new one within the <Directory> block,
  • Set the AllowOverride line to the following:
    • AllowOverride Options Indexes Limit FileInfo
  • Restart Apache again.
  • Et voila.

This will allow the Drupal .htaccess file to run and make your URLs all nice & shiny!

Subscribe to CentOS