1. Home
  2. How To
  3. How to troubleshoot common Apache issues

How to troubleshoot common Apache issues

Apache is one of the best-coded web server application that is deployed in more than 65% of web servers globally. It is very stable and properly maintained by the vendors however there are still possibilities for glitches from its deployment errors or when integrated with other applications in the same host. We will discuss some scenarios that can cause instability or errors or total server crashes and an outage.

Checking the Apache logs

The first point where you should start your investigation is from the error logs from which you will surely get some hints about the root cause of the issue. It is advisable to open 2 ssh terminals to the server and use the tail command to follow the log files for errors.

The common Apache error log file locations are as noted below for a quick reference.

cPanel

/usr/local/apache/logs/error_log

Plesk

/var/log/httpd/error_log

CentOS/Fedora

/var/log/httpd/error_log

Debian/Ubuntu

/var/log/apache2/error_log

You can use the tail command on these log files to follow the log file while you start the Apache server.

 tail -f  /var/log/httpd/error_log

Common Apache Issues

Port Conflicts

For Apache to start, it should have the configured ports available and no services should be binded to these ports. The common ports configured with Apache standalone servers are 80 and 443, you can use the below command to see if the ports are already in use or not.

[root@server ~]# netstat -plan | grep :80
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      9224/bitninja [Port 
tcp        0      0 0.0.0.0:8009                0.0.0.0:*                   LISTEN      9224/bitninja [Port 
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      9224/bitninja [Port 
tcp        0      0 77.235.58.227:80            0.0.0.0:*                   LISTEN      18950/nginx         
tcp        0      0 0.0.0.0:8087                0.0.0.0:*                   LISTEN      9224/bitninja [Port 
tcp        0      0 77.235.58.227:80            77.235.58.227:52630         TIME_WAIT   -                   
tcp        0      0 77.235.58.227:51704         77.235.58.227:80            TIME_WAIT   -                   
tcp        0      0 77.235.58.227:80            77.235.58.227:52626         TIME_WAIT   -                   
tcp        0      0 77.235.58.227:80            77.235.58.227:51712         TIME_WAIT   -                   
tcp        0      0 77.235.58.227:80            77.235.58.227:52622         TIME_WAIT   -    

As you can see Nginx server is already using the port 80 in public interface an apache will not start. Kill the Nginx server and start Apache server again.

Other Apache instances stalled holding the ports.

You may receive the errors similar to port conflicts and the reason can be already initiated/non terminated Apache processes holding the ports. Please use the below commands to see if any such processes exist in the server.

[root@server ~]# ps aux  | grep "httpd\|apache"  | grep -v grep
root     18663  0.0  0.6 394336 32168 ?        SNs  15:25   0:00 /usr/sbin/httpd
apache   18666  0.0  0.3 252844 17436 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18667  0.0  0.5 395040 25532 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18668  0.0  0.5 395440 25592 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18670  0.0  0.5 395032 25716 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18671  0.0  0.5 394984 25676 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18672  0.0  0.5 394944 25640 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18673  0.0  0.5 395000 25468 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18674  0.0  0.4 394912 25384 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18675  0.0  0.5 395076 25780 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18676  0.0  0.5 394940 25636 ?        SN   15:25   0:00 /usr/sbin/httpd
apache   18677  0.0  0.4 394892 25280 ?        SN   15:25   0:00 /usr/sbin/httpd

Kill all the found Apache processes using the kill command as shown below.

[root@server ~]# kill -9   18666  18663   18667  18668 18670 18671 18672 18673 18674 18675 18676 18677 

Start Apache again after verifying no other process are binded to Apache configured ports.

Syntax errors in httpd.conf file

Sometimes you may encounter startup errors with Apache after you making changes in file, adding virtual hosts etc. Apache need to get its virtualhost as well as global configuration in its predefined formats, else it will endup in errors and the server will not start. An error sample is as shown below

Syntax error on line 218 of  /etc/httpd/conf/httpd.conf

You can open the conf file and check the configuration lines around line number 218, correct the configuration and start the server again. It is always advisable to check the configuration syntax after any changes and you can us the below command for the same.

[root@server ~]# apachectl -t
Syntax OK

[root@server ~]

# httpd -t Syntax OKFor Debian and Ubuntu flavours you can do the Syntax check as shown below.

apache2ctl -t
Similarly you cause the command with -S switch to list all virtual hosts with essential information like configured ports, defined line number in configuration etc.

[root@server ~]

# httpd -S VirtualHost configuration: 127.0.0.1:7080 is a NameVirtualHost

Apache won’t start if the .htaccess file is not properly created. 

It is required to set up the Apache virtual hosts with proper definitions in them for .htaccess files to consider. If these directives are missing the .htaccess file not considered and .htaccess definitions will not be loaded. Below noted is a sample definition

</VirtualHost>
<Directory /home/eurovps/public_html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Once done, .htaccess file created in /home/eurovps/public_html/ will be considered by Apache server. Please make sure to create the file with proper permissions and ownership so that it is accessible for the Apache server. The file permission usually required is 644 and the ownership should be for the domain user.

Sample .htaccess file creation and permissions. Create the file with your favourite text editor.

vi /home/eurovps/public_html/.htaccess
#++++Sample_contents++++#
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#++++Sample_contents++++#
Esc  + :wq

chmod 644 /home/eurovps/public_html/.htaccess
chown eurovps.eurovps  /home/eurovps/public_html/.htaccess

Tips, Try enabling verbose logs to debug (LogLevel debug). Check Apache syntax and include files (apachectl -t). Check syslog and dmesg for any hints process termination, check free memory and free disk availability in server.

Updated on June 6, 2019

Was this article helpful?

Related Articles