Apache web service is one of the key services for our websites, if it is down, our business is down. So it is very important to keep this service smooth, up and running. In a web hosting environment, especially when we talk about the shared hosting plans, thousands of web sites are being hosted on a single server. So if web service gets down, it means all the websites are down and a huge no. of customers is getting affected. One of my seniors once told me, If Apache is down, it means your server is down. So we need to make sure everything that Apache is alive.
Bad User Error
There can be multiple reasons because of which Apache won’t restart. One of the errors is bad user error that you might get while restarting apache. I have experienced this error for numerous times, so decided to write some info and tips about it.
Here is the bad user error that you’ll get while restarting apache:
Warning: DocumentRoot [/home/faisal/public_html] does not exist
httpd: bad user name faisal
On a cPanel/WHM server, it means that the user is missing a Virtual Host in the apache configuration file httpd.conf. A quick fix for that is to add that user on temporary basis with the following command:
And restart apache server again, it should be back online.
The major reason of the bad user error can be that the account was removed recently from the server but the apache configuration file wasn’t updated. Since the both files /etc/userdomains and /etc/passwd and synced with each other on a cPanel server, and both have the same database for the user accounts on the server, so if a user is missing from any of these files, apache won’t restart. That is why, we add the user temporarily to get the web service back online.
But for a server with huge amount of user database, apache will prompt for the next unavailable user on every restart, which is a time taking thing, so please execute the below command to get it fixed:
This is the easy way to fix the problem. On the other hand, you can remove the virtual host entry of the bad users from apache configuration file, but take the backup of the file first and then do the changes. Finally execute the following command to get any syntax errors fixed in httpd.conf:
Or the below command will work too:
If you are still facing any issues and can’t load the website, check the error logs in /usr/local/apache/logs directory. Check the error_log file to find the exact error, try to fix and if still no luck, contact your hosting provider 🙂