Updated on 24.5.2023

How to fix common problems with Apache2

Apache2

Problems with loading a website are often blamed on the Internet connection, but even the most perfectly set up network cannot help if there is no service to reply at your destination. One of the most popular HTTP servers used for this task is Apache2. Much of Apache’s popularity can be attributed to its easy installation and use, but never the less it is possible to run into problems with even the easiest of the software. If you’ve encountered an issue loading your web page, follow these simple troubleshooting methods outlined in this guide to attempt to get your web server back up and working again.

Make sure the service is running

The first step to take in troubleshooting any service is to check that the service is running and able to function. A straightforward approach is to simply restart the service. On Ubuntu and Debian servers use the following command.

sudo systemctl restart apache2

In CentOS and other Red Hat environments Apache2 service goes by the name ‘httpd’, so use this command instead.

sudo systemctl restart httpd

Depending on your choice of distribution the output from the restart command will vary. Subjectively Ubuntu usually gives the most helpful reply as shown below.

* Restarting web server apache2             [ OK ]

CentOS and Debian probably do not say anything as long as the restart didn’t fail.

If your system wasn’t able to restart Apache2 you most likely got some form of an error message. In case you got a reply resembling either one of the output examples below, the service is most likely not properly installed on your system or some files are missing.

apache2: unrecognized service
Failed to restart apache2.service: Unit apache.service failed to load: No such file or directory.

Should you see these type of errors, try installing the service again. On servers running Debian or Ubuntu use the following command.

sudo apt-get install apache2

And on CentOS install httpd instead with the next command.

sudo yum install httpd

Once you are sure the web server is fully installed go ahead and restart the service again with the same command you used before.

If you got a different error message, try to get more information on what kind of state your web service is in. Use one of the following commands applicable to your system.

sudo systemctl status apache2
sudo systemctl status httpd

The output from the status check will tell at least whether the service is running or stopped. Debian and CentOS systems usually show more detailed report including service up time and a couple of log lines. Below is an example of a Debian status display, one on CentOS would be nearly identical. Ubuntu does not have this type of output by default.

● apache2.service - LSB: Apache2 web server
    Loaded: loaded (/etc/init.d/apache2)
    Active: active (running) since Fri 2015-07-31 10:44:26 EEST; 2h 14min ago
   Process: 9704 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
   Process: 9711 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    CGroup: /system.slice/apache2.service
            ├─9726 /usr/sbin/apache2 -k start
            ├─9730 /usr/sbin/apache2 -k start
            ├─9731 /usr/sbin/apache2 -k start
            ├─9732 /usr/sbin/apache2 -k start
            ├─9733 /usr/sbin/apache2 -k start
            ├─9734 /usr/sbin/apache2 -k start
            └─9747 /usr/sbin/apache2 -k start
 Jul 31 10:44:26 debian.example.com apache2[9711]: Starting web server: apache2.

The important part here is on the third line, active and running means the process should be working, if instead it shows active and stopped or failed, the process has most likely crashed.

Next check the processes by their name for either apache2 or httpd.

sudo ps aux | grep -E 'apache2|httpd'

For every mention of the searched keyword grep will print out a line the keyword was found on, this includes the search process itself so you will see at least the grep command. If there are more than one line of output, all but the last are processes related to your web service. An example below displays apache2 processes running on Ubuntu.

root      1457  0.0  1.5 321908 16132 ?      Ss   Jul30  0:02 /usr/sbin/apache2 -k start
www-data  1461  0.0  2.8 326532 29172 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
www-data  1462  0.0  3.1 327480 32364 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
www-data  1463  0.0  2.9 326688 30260 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
www-data  1464  0.0  3.1 326496 32148 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
www-data  1465  0.0  2.7 326816 28040 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
www-data  1841  0.0  2.0 323132 21044 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
www-data  1871  0.0  2.2 323396 23280 ?      S    Jul30  0:00 /usr/sbin/apache2 -k start
user     11669  0.0  0.0  11744   928 pts/0  S+   15:32  0:00 grep --color=auto -E apache2|httpd

Since the service restart command didn’t work earlier, any processes grep might list have probably stopped functioning and need to be closed before the service can start again. On Debian and Ubuntu systems stop all apache2 processes using this command.

sudo killall apache2

On CentOS servers not only is the web service called something else but also the kill command functions little differently, use the following instead for the same result.

sudo kill -a httpd

After the kill command, you can run the process check again just to confirm that there are no more zombies left. Then try to restart the service using these same commands as at the beginning of this guide.

sudo systemctl status apache2
sudo systemctl status httpd

This should get the web service running provided that it has not been misconfigured.

Check your server configuration

When starting the service fails giving errors referring to files located in either /etc/apache2 or /etc/httpd/, the system had trouble reading the service configuration files. Apache2 comes with some handy tools for file integrity and syntax checks that can help in locating any typing mistakes or other irregularities in the configuration. With Debian and Ubuntu servers, check the config files by running the following command.

sudo apache2ctl -t

On CentOS machines just call httpd instead.

sudo httpd -t

The output will show any problems found with the configuration file. Or if everything is in order, it simply prints out a confirmation like the one shown below.

Syntax OK

Another troubleshooting option for the web service is to show parsed virtual host and run settings with commands for Debian/Ubuntu and CentOS respectively.

sudo apache2ctl -S
sudo httpd -S

Below is an example of the command output from a CentOS system. Make sure the server and document roots point to the correct directories.

VirtualHost configuration:
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48

If your server uses a custom virtual host configuration, like when hosting multiple websites on one server, check that each virtual host file has the correct domain name and points to the correct root directory. On Debian and Ubuntu machines have a virtual host file by default and it is stored in /etc/apache2/sites-enabled/. Open the file for edit.

sudo nano /etc/apache2/sites-enabled/000-default.conf

This file usually has some instructions on what each parameter means in the comments, which have been left out in the example below, but the important parts are ServerName and DocumentRoot as already mentioned.

<VirtualHost *:80>
   ServerName www.example.com
   ServerAdmin webmaster@localhost 
   DocumentRoot /var/www/html
   #LogLevel info ssl:warn      
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
   #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

CentOS and httpd do not have the same virtual host file set by default but instead uses the httpd service configuration to store the default settings. Check the configuration file with the command below.

sudo vi /etc/httpd/conf/httpd.conf

Look for the same parameters ServerName and DocumentRoot, and make sure they are correctly set.

If you made any changes to the configuration files, the service needs to be reloaded for the changes to take an effect. Restarting the service does the job, but if you wish to avoid downtime on your web server use reload instead with one of the following commands.

sudo systemctl reload apache2
sudo systemctl reload httpd

Check Logs

When everything on the service side is working as expected and you cannot find a fault, but the website just still won’t load, it’s always a good time to dig through logs. Apache2 keeps two sets of logs, access and error. You can find the logs stored at /var/log/apache2/ or /var/log/httpd depending on your choice of Linux distribution. You can list all files in your web server’s log directory using the commands below.

sudo ls /var/log/apache2/
sudo ls /var/log/httpd/

The log lists will differ slightly as different systems name the logs a little differently. Ubuntu and Debian servers store the current uptime logs to access.log or error.log, previous logs are marked with a running number, 1 being the latest, and older logs than that are also compressed. On CentOS and other Red Hat variants, the logs are named access_log and error_log, older logs have their name appended with the date the log was written on e.g. access_log-20150108.

An easy way to start reading the logs, when you don’t necessarily know what you are looking for, is to use the filtering app ‘grep’. Search for any errors using one of the commands below which corresponds with your system’s web application name.

sudo grep -i -r error /var/log/apache2/
sudo grep -i -r error /var/log/httpd/

Ubuntu and Debian users might also need to check through the compressed log files. This can be done using ‘zgrep’ instead, but due to its limitations, you can only search one log at the time, for example using this following command.

sudo zgrep error /var/log/apache2/error.log.2.gz

Not all errors logged by your web service necessarily mean there is something wrong with your server, but keep an eye out for any repeating problems like missing files in the example error below.

[Fri Jul 17 12:36:08.431065 2015] [:error] [pid 4649] [client 80.69.160.92] script '/var/www/html/index.php' not found or unable to start

You may also wish to enable more verbose logging if searching for errors is not yielding any results. The log output amount is controlled by a parameter called ‘LogLevel’ in the configuration file. On Debian and Ubuntu systems, open your configuration file with the following command.

sudo nano /etc/apache2/apache2.conf

With CentOS and other Red Hat based server use the command here instead.

sudo vi /etc/httpd/conf/httpd.conf

Find the LogLevel parameter and change it from the default ‘warn’ value to ‘debug’ instead, then save the file and exit. Again for any changes to be applied, the service needs to be reloaded. You can do this with one of the following commands appropriate for your system.

sudo systemctl reload apache2
sudo systemctl reload httpd

To generate some new entries using the new log levels, try to access your website again a couple of times even if it doesn’t work. The more verbose logs should help with narrowing down any underlying issues.

Check other services

If your website still won’t load after all the troubleshooting with Apache, check other related services on your cloud server such as databases, firewall and network connection, which also have their own troubleshooting instructions.

Do not hesitate to contact our support team. Remember to include any relevant information you may have discovered while troubleshooting, as every bit of detail, will be useful in further investigations.

Janne Ruostemaa

Editor-in-Chief

  1. Solution sucks mate does not work

  2. Janne Ruostemaa

    Hi Timg, sorry to hear you weren’t able to resolve your problem. The common solutions in this guide are some of the first steps in troubleshooting Apache and can fix many issues. However, if the problem is outside the usual stop/restart and config fixes, you’ll have to dive into the logs for more information and precise solution.

  3. When the Apache websites are not visible on other systems after a fresh boot, it could be that in the network configuration [connections] one or more users are given permissions.
    Normally it should say ‘permissions=’ without users after this text.
    After removing the user that had given permission in this line, the server boots with active internet connection for all services.
    It has cost me many hours to find this out. I had a fresh Debian Buster installation. How and when this ‘permission’ is added is unclear to me.

  4. Janne Ruostemaa

    Hi there, thank you for the insightful comment. Indeed permissions play a large part in a system functionality on Linux machines. Such connection permission was likely added by a third-party program and should not be set on a default Debian Buster configuration.

  5. storre lappar naturligt

    I savour, cause I discovered exactly what I used to be
    taking a look for. You have ended my 4 day long hunt!
    God Bless you man. Have a great day. Bye

  6. can you say that why AWS Centos 7 saying that no package found for
    yum install httpd
    or httpd24
    or apache

    by shiju

  7. Janne Ruostemaa

    Hi there, it’s possible httpd has been added to the exclusions list for one reason or another. First, make sure the system is up to date with sudo yum update then try installing it with the following parameter sudo yum --disableexcludes=all install httpd and see if it can be found.

  8. The first solution (restart) worked for me ty!

  9. Barry Brannum

    Which file are you referring to? I’m having this issue and don’t see anything in the logs or config.php that could be causing this problem.

  10. Janne Ruostemaa

    Hi Barry, thanks for the question. The above is referring to the NetworkManager connection configuration files, e.g. /etc/NetworkManager/system-connections/Wired connection 1 but yours may be called something else. These contain a section name [connection] with permissions= attribute. Normally, the permissions list should be empty giving all users permissions to use the connection in question. If your connection is restricted to specific users, set the attribute empty, save the file and run sudo systemctl restart NetworkManager

  11. Hi, Apache time out issue even I have 16 gb ram, with load balancer, what will be configuration requirements

  12. Janne Ruostemaa

    Hi there, thanks for the question. Page timeout issues are more likely to be caused by network connectivity problems or routing issues. In your case, I’d suspect the problem to lay with the load balancer configuration. We have tutorials on load balancing, for example using HAProxy.

  13. Hi, I’ve Ubuntu server with php-fpm lamp stack. My apache stops suddenly in some days. I don’t know what is the actual reason. Can you help me?

  14. Error log

    [Tue Aug 18 06:25:11.893646 2020] [:notice] [pid 7260:tid 140548542154624] FastCGI: process manager initialized (pid 7260)
    [Tue Aug 18 06:25:11.901862 2020] [mpm_event:notice] [pid 1388:tid 140548542154624] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 OpenSSL/1.0.2g configured — resuming normal operations
    [Tue Aug 18 06:25:11.901890 2020] [core:notice] [pid 1388:tid 140548542154624] AH00094: Command line: ‘/usr/sbin/apache2’
    [Tue Aug 18 10:16:43.396993 2020] [proxy_fcgi:error] [pid 7262:tid 140548165789440] (-102)Unknown error -102: [client 138.68.249.116:33030] AH01075: Error dispatching request to : (reading input brigade)
    [Tue Aug 18 17:24:07.301540 2020] [mpm_event:notice] [pid 1388:tid 140548542154624] AH00493: SIGUSR1 received. Doing graceful restart
    [Tue Aug 18 17:24:10.350960 2020] [:notice] [pid 21717:tid 140548542154624] FastCGI: process manager initialized (pid 21717)
    [Tue Aug 18 17:24:10.374972 2020] [mpm_event:notice] [pid 1388:tid 140548542154624] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 OpenSSL/1.0.2g configured — resuming normal operations
    [Tue Aug 18 17:24:10.375005 2020] [core:notice] [pid 1388:tid 140548542154624] AH00094: Command line: ‘/usr/sbin/apache2’
    [Tue Aug 18 17:24:14.071102 2020] [mpm_event:notice] [pid 1388:tid 140548542154624] AH00493: SIGUSR1 received. Doing graceful restart
    [Tue Aug 18 17:24:16.972938 2020] [core:notice] [pid 1388] AH00060: seg fault or similar nasty error detected in the parent process
    [Tue Aug 18 17:24:23.652381 2020] [:notice] [pid 21831:tid 140482900072320] FastCGI: process manager initialized (pid 21831)
    [Tue Aug 18 17:24:23.663299 2020] [core:warn] [pid 21829:tid 140482900072320] AH00098: pid file /var/run/apache2/apache2.pid overwritten — Unclean shutdown of previous Apache run?
    [Tue Aug 18 17:24:23.664414 2020] [mpm_event:notice] [pid 21829:tid 140482900072320] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 OpenSSL/1.0.2g configured — resuming normal operations
    [Tue Aug 18 17:24:23.664436 2020] [core:notice] [pid 21829:tid 140482900072320] AH00094: Command line: ‘/usr/sbin/apache2’
    [Tue Aug 18 17:24:26.683159 2020] [mpm_event:notice] [pid 21829:tid 140482900072320] AH00493: SIGUSR1 received. Doing graceful restart
    [Tue Aug 18 17:24:29.727312 2020] [:notice] [pid 21915:tid 140482900072320] FastCGI: process manager initialized (pid 21915)
    [Tue Aug 18 17:24:29.737517 2020] [mpm_event:notice] [pid 21829:tid 140482900072320] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 OpenSSL/1.0.2g configured — resuming normal operations
    [Tue Aug 18 17:24:29.737554 2020] [core:notice] [pid 21829:tid 140482900072320] AH00094: Command line: ‘/usr/sbin/apache2’
    [Tue Aug 18 17:24:33.359439 2020] [mpm_event:notice] [pid 21829:tid 140482900072320] AH00493: SIGUSR1 received. Doing graceful restart
    [Tue Aug 18 17:24:33.579858 2020] [core:notice] [pid 21829] AH00060: seg fault or similar nasty error detected in the parent process
    [Tue Aug 18 17:43:50.043508 2020] [:notice] [pid 23556:tid 139741113497472] FastCGI: process manager initialized (pid 23556)
    [Tue Aug 18 17:43:50.049312 2020] [core:warn] [pid 23552:tid 139741113497472] AH00098: pid file /var/run/apache2/apache2.pid overwritten — Unclean shutdown of previous Apache run?
    [Tue Aug 18 17:43:50.050086 2020] [mpm_event:notice] [pid 23552:tid 139741113497472] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 OpenSSL/1.0.2g configured — resuming normal operations
    [Tue Aug 18 17:43:50.050099 2020] [core:notice] [pid 23552:tid 139741113497472] AH00094: Command line: ‘/usr/sbin/apache2’
    [Wed Aug 19 06:25:07.724673 2020] [mpm_event:notice] [pid 23552:tid 139741113497472] AH00493: SIGUSR1 received. Doing graceful restart

  15. Janne Ruostemaa

    Hi Kiran, thanks for the question. While there aren’t any obvious indicators of the cause in the log without further information, I’d suggest looking into what caused the dispatch error at 10:16:43 and see if that’s somehow related. Assuming the graceful restarts around 17:24 were done manually when trying to get Apache going again. Running graceful restarts in quick succession can cause seg fault error as seen in the log.

  16. how can use apache resourse by HTTPS. after changing apache from http to https. my pacemaker apache resource failed. please help me.

  17. Janne Ruostemaa

    Hi John, thanks for the question. You need to obtain SSL certificates to successfully enable HTTPS. Most services charge a fee for the certificates, but with Let’s Encrypt you can do this for free. Have a look at our tutorial on how to use Let’s Encrypt on Apache.

  18. Thanks so much. This procedures worked for me.
    I’m indeed grateful!

  19. goood! thanks!

  20. still i am not able to access apache. Can u give me a solution for it.

  21. Janne Ruostemaa

    Hi Ardra, thanks for the comment. If your Apache server is running and nothing appears to work, make sure something else like a firewall isn’t blocking the connection.

  22. Hi, apache2 is not running in browser, using IP checked everything, everything is installed(apache2 ans phpmyadmin), unable to find solution

  23. Hi there, thanks for the comment. One thing that comes to mind is that the port in the configuration might not be matching the URL that you are using. For example, the port in the configuration is 8080 but you are not specifying this in the URL. On the other hand, you might have already configured the port to be 80 but you are still adding :8080 to the URL on the browser.

  24. Yes, for me as well, i just wanted to install ubuntu again, but you saved my old system :) Thank you.

  25. use “[sudo] ufw status” and see if your selected http[s] port is enabled and firewall is runnng.
    you maybe need to run:
    [sudo] ufw allow http

  26. nice, it work

  27. worked fo rmeee thankxxxx

  28. Hi, thanks for the insightful breakdown. Please my challenge with apache is quite unique. Upon the “service apache 2 start” command, my program prompts an authentication panel which says “authentication is required to start apache 2” and I don’t have a clue as to what the password should be. The action obviously requires privileges. Can someone kindly point me to resolution steps?

  29. Janne Ruostemaa

    Hi there, thanks for the question. It sounds like you are trying to start the service without root privileges. If you have sudo access, add it to the beginning of the commnad.

Leave a Reply to krishna

Your email address will not be published. Required fields are marked *

Back to top