Apache troubleshooting tips

Jack Wallen
Nov 8, 2009
Updated • Nov 30, 2012
Development
|
4

How many times have you installed a LAMP server only to find Apache doesn't seem to want to run right? Or you install a new module only to see Apache try to download pages as file, instead of displaying them on screen?

There are a hundred and one thousand things that can go wrong with any web server installation. From a fresh installation to an installation that has been running for a long time, you never know when something is going to cause your web server to go astray. When it does happen, it's always nice to know that, usually, Occam's Razor applies.

In this tutorial you will find some advice that will help you through some of the more common issues that can pop up with an Apache web server.

Is your server actually running?

Believe it or not, this has happened to plenty of administrators. You take the server down, do some maintenance, and when you go to check out the server you're getting errors. The first thing you do, naturally, is check out that /etc/apache2/apache.conf file to make sure your syntax is correct. But it's perfect! What's up? The first thing you might want to check is to make sure the server is running. But you don't want to just issue the command to start the server or reload the server. Instead, issue the command:

sudo /etc/init.d/apache2 status

Which should return something like:

* apache is running (pid 9751).

If not, start the server with either:

sudo /etc/init.d/apache2 start

or

sudo apache2ctl start

NOTE: If you are using a distribution like Fedora, SuSE, or Mandriva you will need to first su to the root user and issue the above commands WITHOUT using sudo.

It's not running and it won't start

Did you just make changes to your Apache configuration file? Are the changes correct? If you're not sure, you can use the apache2ctl command to check the syntax of your configuration file. This is done with the command:

sudo apache2ctl configtext

The above command should report:

Syntax OK

If you don't get an OK, you will get information that points to the errors in your configuration file.

Apache wants to download .php files!

This is another common issue. When you add a new tool on your web server (such as Drupal), if your configuration file is set up properly, any .php file might not be displayed. Instead any attempt to view a .php file will instead have your browser trying to download the file. Why is this? Apache must be informed that certain extensions are to be displayed, not downloaded. This is done from within the Apache configuration file. Open up that file (in the Ubuntu server it will be /etc/apache2/apache2.conf) and first look for the following line:

DirectoryIndex index.html

If that file doesn't include index.php nearly all sites that use php will be rendered useless.

The second line to look for is:

AddHandler application/x-httpd-php .php

If you find this line, and it is commented out, make sure you uncomment it by removing the "#" character. If it is not there add it to the bottom of the configuration file.

And, as always, when you make a change to the configuration file, restart Apache.

Know where to look for problems

Finally, it is crucial that you know where to first turn when the above doesn't help you out. Any time I have an issue with Apache where Occam's Razor does not apply, the first place I turn is the log files.

If you look in /var/log/apache2 you will find, at least, the following files:

  • access.log: This keeps track of any connection made to your server.
  • error.log: This keeps track of any errors that occur with Apache.
  • other_vhosts_access.log: This is where virtual hosts will log when the virtual host has not been prescribed its own log file.

Of course, as your site evolves so will your available log files. Regardless of what you find in /var/log/apache2, that is where you should always first turn when you have problems. Even before you google.

Final thoughts

Now you should be able to handle some of the more common issues with the Apache server. And if your problem isn't common, you also know where to turn to find clues that will lead you down the right path to correction.

Advertisement

Previous Post: «
Next Post: «

Comments

  1. Tom said on November 11, 2009 at 12:42 pm
    Reply

    On centOS/Redhat/fedora
    /etc/init.d/httpd configtest
    Bye

  2. Kevin said on November 11, 2009 at 6:30 am
    Reply

    sudo apache2ctl configtext

    I think you meant:

    sudo apache2ctl configtest

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.