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
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:
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:
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:
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.
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
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.