APACHE NOT STARTING

While working on our clients’ servers , here at InstaCarma , we have come across this issue where the Apache webserver does not want to Start/Restart. So, I thought of jotting down some possible reasons for this and the solution for the same.

Apache is the most common webserver used at present.
Hopefully, this would be helpful for those associated with Web-Hosting in any way.

To get to the solution for a problem, we need to determine the cause upfront.

Some of the probable reasons for Apache not starting are :-

BROKEN MODULES / MISCONFIGURATION

Many modules like mod_evasive, mod_security, mod_rewrite etc are compiled with Apache. If any of the modules are not installed properly or if they are broken then they might cause problems in starting Apache.

For example,

While trying to restart Apache on a server , I got the following error :

root@server [~]# /etc/init.d/httpd restart

/etc/init.d/httpd restart: configuration broken, ignoring restart
/etc/init.d/httpd restart: (run ‘apachectl configtest’ for details)

Configtest

As mentioned in the error message, a ‘configtest’ can be done to locate the exact problem.

root@server [~]# /usr/local/apache/bin/apachectl configtest

Syntax error on line 378 of /usr/local/apache/conf/httpd.conf:
Invalid command ‘BandWidthDataDir’, perhaps mis-spelled or defined by a module not included in the server
configuration

Just go to the the given file, fix the error and thats it!

root@server [~]# /etc/init.d/httpd restart
/etc/init.d/httpd restart: httpd restarted

So, the ‘configtest’ is a great utility which helps you in fixing broken modules and configuration related issues.

Rebuilding

The apache configuration file can be rebuilt as well. There’s a built-in cPanel script in order to achieve this.

root@server [~]# /scripts/rebuildhttpdconf

Rollback

You can also use the ‘Configuration file rollback’ feature available in WHM>>Backup
This utility will let you restore any of the available previous working configurations.

ULIMIT

‘ulimit’ is a shell command used to define/limit the number of processes or resource usage on the server.

More details on this is available at http://wiki.linuxquestions.org/wiki/Ulimit

Suppose you have a server with hundreds of websites . Each of them will be contributing to the number of open files on the server. If this number goes very high then it might cause Apache to crash and/or not let it start. In that case, you can do the following :

Open the apache start-up file ( /etc/rc.d/init.d/httpd )
Look for the variable ‘ulimit’ . If it is already there then increase the value.
Else, you can add it at the top of the file.

For example,
ulimit -n 1024

-Restart the web-server.

This should resolve the issue.

LOG FILES

Another common reason for Apache not starting is huge log files (error_log and suphp_log) . You can either clear these or to be on the safer side, you can make a compressed copy and keep it aside for any future reference.

SEMAPHORES

Semaphores could also be another reason. ‘Semaphores’ are a technique for co-ordinating or synchronizing activities in which multiple processes compete for the same operating system resources.

Apache hangs with following error in error_log,

semget: No space left on device

Either the user running apache or the whole system has run out of semaphores. i.e. semaphores are used but not released. If apache is running as nobody try,

ipcs -s

to list the semaphores. Remove the unwanted ones with

ipcrm -s “semaphores id”

If there is lots of lines owned by “nobody” it is apache.

/usr/bin/ipcrm sem $(/usr/bin/ipcs -s | grep nobody | awk ‘{print$2}’)

and restart apache.

Otherwise you can try increasing the limit,

echo 250 32000 32 250 > /proc/sys/kernel/sem

Note : Your Apache installation fails to clean allocated Semaphore arrays. Increasing the max semaphore or clearing it is not a permanent fix.

STRACE

Sometimes, your application/software would fail without giving you any errors. Neither would you find anything in the logs. ‘Strace’ might be of great help in such situations. It is not concerned with the configuration or the internals of the application. ‘Strace’ knows only about the syscalls (calls to the kernel).
It is usually used with the options -f ( to follow the child processes) and -o (to save the output to a file)

Let us see how we can diagnose the Apache problem using strace. For this we need to first start apache with strace :

root@server [~]# strace -f -o strace.txt /etc/rc.d/init.d/httpd start

The above command will try to start apache and save the output of the strace command in a file named strace.txt. By analysing this file, we can see the syscalls made and the processes being carried out. This will give us a clear idea of where the problem is occurring and what the error is which can be fixed accordingly.

So, these are some of the causes and fixes that we encountered at work. Feel free to put in any inputs and suggestions from your experience.


Shares
Contact Us On WhatsApp