{"id":98,"date":"2019-05-31T11:35:08","date_gmt":"2019-05-31T11:35:08","guid":{"rendered":"https:\/\/www.eurovps.com\/faq\/?post_type=ht_kb&#038;p=98"},"modified":"2019-06-06T11:03:22","modified_gmt":"2019-06-06T11:03:22","slug":"how-to-troubleshoot-apache-webserver","status":"publish","type":"ht_kb","link":"https:\/\/www.eurovps.com\/faq\/how-to-troubleshoot-apache-webserver\/","title":{"rendered":"How to troubleshoot common Apache issues"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Checking the Apache logs<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>The common Apache error log file locations are as noted below for a quick reference.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">cPanel<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\/usr\/local\/apache\/logs\/error_log<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Plesk<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\/var\/log\/httpd\/error_log<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">CentOS\/Fedora<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\/var\/log\/httpd\/error_log<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Debian\/Ubuntu<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\/var\/log\/apache2\/error_log<\/pre>\n\n\n\n<p>You can use the tail command on these log files to follow the log file while you start the Apache server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> tail -f  \/var\/log\/httpd\/error_log<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Common Apache Issues<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Port Conflicts<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@server ~]# netstat -plan | grep :80\ntcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      9224\/bitninja [Port \ntcp        0      0 0.0.0.0:8009                0.0.0.0:*                   LISTEN      9224\/bitninja [Port \ntcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      9224\/bitninja [Port \ntcp        0      0 77.235.58.227:80            0.0.0.0:*                   LISTEN      18950\/nginx         \ntcp        0      0 0.0.0.0:8087                0.0.0.0:*                   LISTEN      9224\/bitninja [Port \ntcp        0      0 77.235.58.227:80            77.235.58.227:52630         TIME_WAIT   -                   \ntcp        0      0 77.235.58.227:51704         77.235.58.227:80            TIME_WAIT   -                   \ntcp        0      0 77.235.58.227:80            77.235.58.227:52626         TIME_WAIT   -                   \ntcp        0      0 77.235.58.227:80            77.235.58.227:51712         TIME_WAIT   -                   \ntcp        0      0 77.235.58.227:80            77.235.58.227:52622         TIME_WAIT   -    \n<\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Other Apache instances stalled holding the ports.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@server ~]# ps aux  | grep \"httpd\\|apache\"  | grep -v grep\nroot     18663  0.0  0.6 394336 32168 ?        SNs  15:25   0:00 \/usr\/sbin\/httpd\napache   18666  0.0  0.3 252844 17436 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18667  0.0  0.5 395040 25532 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18668  0.0  0.5 395440 25592 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18670  0.0  0.5 395032 25716 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18671  0.0  0.5 394984 25676 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18672  0.0  0.5 394944 25640 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18673  0.0  0.5 395000 25468 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18674  0.0  0.4 394912 25384 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18675  0.0  0.5 395076 25780 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18676  0.0  0.5 394940 25636 ?        SN   15:25   0:00 \/usr\/sbin\/httpd\napache   18677  0.0  0.4 394892 25280 ?        SN   15:25   0:00 \/usr\/sbin\/httpd<\/pre>\n\n\n\n<p>Kill all the found Apache processes using the kill command as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@server ~]# kill -9   18666  18663   18667  18668 18670 18671 18672 18673 18674 18675 18676 18677 <\/pre>\n\n\n\n<p>Start Apache again after verifying no other process are binded to Apache configured ports.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax errors in httpd.conf file<\/h3>\n\n\n\n<p>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<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Syntax error on line 218 of  \/etc\/httpd\/conf\/httpd.conf<\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@server ~]# apachectl -t\nSyntax OK\n<\/pre>\n\n\n<p>[root@server ~]<\/p>\n\n\n\n<p># httpd -t\nSyntax OKFor Debian and Ubuntu flavours you can do the Syntax check as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apache2ctl -t\nSimilarly you cause the command with -S switch to list all virtual hosts with essential information like configured ports, defined line number in configuration etc.\n<\/pre>\n\n\n<p>[root@server ~]<\/p>\n\n\n\n<p># httpd -S\nVirtualHost configuration:\n127.0.0.1:7080         is a NameVirtualHost<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Apache won&#8217;t start if the .htaccess file is not properly created.&nbsp;<\/h3>\n\n\n\n<p>It is required to&nbsp;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<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;\/VirtualHost&gt;\n&lt;Directory \/home\/eurovps\/public_html&gt;\n    Options Indexes FollowSymLinks\n    AllowOverride All\n    Require all granted\n&lt;\/Directory&gt;<\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Sample .htaccess file creation and permissions. Create the file with your favourite text editor.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/home\/eurovps\/public_html\/.htaccess\n#++++Sample_contents++++#\n# BEGIN WordPress\n&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php [L]\n&lt;\/IfModule&gt;\n#++++Sample_contents++++#\nEsc  + :wq\n\nchmod 644 \/home\/eurovps\/public_html\/.htaccess\nchown eurovps.eurovps  \/home\/eurovps\/public_html\/.htaccess<\/pre>\n\n\n\n<p>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.<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[17],"ht-kb-tag":[],"class_list":["post-98","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-how-to"],"_links":{"self":[{"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/ht-kb\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":1,"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/ht-kb\/98\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/ht-kb\/98\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/ht-kb-category?post=98"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.eurovps.com\/faq\/wp-json\/wp\/v2\/ht-kb-tag?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}