In CentOS and other Red Hat environments Apache2 service goes by the name \u2018httpd\u2019, so use this command instead.<\/p>\n\n\n\n
sudo systemctl restart httpd<\/pre>\n\n\n\nDepending on your choice of distribution the output from the restart command will vary. Subjectively Ubuntu usually gives the most helpful reply as shown below.<\/p>\n\n\n\n
* Restarting web server apache2 [ OK ]<\/pre>\n\n\n\nCentOS and Debian probably do not say anything as long as the restart didn\u2019t fail.<\/p>\n\n\n\n
If your system wasn\u2019t 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.<\/p>\n\n\n\n
apache2: unrecognized service<\/pre>\n\n\n\nFailed to restart apache2.service: Unit apache.service failed to load: No such file or directory.<\/pre>\n\n\n\nShould you see these type of errors, try installing the service again. On servers running Debian or Ubuntu use the following command.<\/p>\n\n\n\n
sudo apt-get install apache2<\/pre>\n\n\n\nAnd on CentOS install httpd instead with the next command.<\/p>\n\n\n\n
sudo yum install httpd<\/pre>\n\n\n\nOnce you are sure the web server is fully installed go ahead and restart the service again with the same command you used before.<\/p>\n\n\n\n
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.<\/p>\n\n\n\n
sudo systemctl status apache2<\/pre>\n\n\n\nsudo systemctl status httpd<\/pre>\n\n\n\nThe 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.<\/p>\n\n\n\n
\u25cf apache2.service - LSB: Apache2 web server\n Loaded: loaded (\/etc\/init.d\/apache2)\n Active: active (running) since Fri 2015-07-31 10:44:26 EEST; 2h 14min ago\n Process: 9704 ExecStop=\/etc\/init.d\/apache2 stop (code=exited, status=0\/SUCCESS)\n Process: 9711 ExecStart=\/etc\/init.d\/apache2 start (code=exited, status=0\/SUCCESS)\n CGroup: \/system.slice\/apache2.service\n \u251c\u25009726 \/usr\/sbin\/apache2 -k start\n \u251c\u25009730 \/usr\/sbin\/apache2 -k start\n \u251c\u25009731 \/usr\/sbin\/apache2 -k start\n \u251c\u25009732 \/usr\/sbin\/apache2 -k start\n \u251c\u25009733 \/usr\/sbin\/apache2 -k start\n \u251c\u25009734 \/usr\/sbin\/apache2 -k start\n \u2514\u25009747 \/usr\/sbin\/apache2 -k start\n Jul 31 10:44:26 debian.example.com apache2[9711]: Starting web server: apache2.<\/pre>\n\n\n\nThe 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.<\/p>\n\n\n\n
Next check the processes by their name for either apache2 or httpd.<\/p>\n\n\n\n
sudo ps aux | grep -E 'apache2|httpd'<\/pre>\n\n\n\nFor 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.<\/p>\n\n\n\n
root 1457 0.0 1.5 321908 16132 ? Ss Jul30 0:02 \/usr\/sbin\/apache2 -k start\nwww-data 1461 0.0 2.8 326532 29172 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nwww-data 1462 0.0 3.1 327480 32364 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nwww-data 1463 0.0 2.9 326688 30260 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nwww-data 1464 0.0 3.1 326496 32148 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nwww-data 1465 0.0 2.7 326816 28040 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nwww-data 1841 0.0 2.0 323132 21044 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nwww-data 1871 0.0 2.2 323396 23280 ? S Jul30 0:00 \/usr\/sbin\/apache2 -k start\nuser 11669 0.0 0.0 11744 928 pts\/0 S+ 15:32 0:00 grep --color=auto -E apache2|httpd<\/pre>\n\n\n\nSince the service restart command didn\u2019t 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.<\/p>\n\n\n\n
sudo killall apache2<\/pre>\n\n\n\nOn 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.<\/p>\n\n\n\n
sudo kill -a httpd<\/pre>\n\n\n\nAfter 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.<\/p>\n\n\n\n
sudo systemctl status apache2<\/pre>\n\n\n\nsudo systemctl status httpd<\/pre>\n\n\n\nThis should get the web service running provided that it has not been misconfigured.<\/p>\n\n\n\n
Check your server configuration<\/h2>\n\n\n\n
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.<\/p>\n\n\n\n
sudo apache2ctl -t<\/pre>\n\n\n\nOn CentOS machines just call httpd instead.<\/p>\n\n\n\n
sudo httpd -t<\/pre>\n\n\n\nThe 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.<\/p>\n\n\n\n
Syntax OK<\/pre>\n\n\n\nAnother troubleshooting option for the web service is to show parsed virtual host and run settings with commands for Debian\/Ubuntu and CentOS respectively.<\/p>\n\n\n\n
sudo apache2ctl -S<\/pre>\n\n\n\nsudo httpd -S<\/pre>\n\n\n\nBelow is an example of the command output from a CentOS system. Make sure the server and document roots point to the correct directories.<\/p>\n\n\n\n
VirtualHost configuration:\nServerRoot: \"\/etc\/httpd\"\nMain DocumentRoot: \"\/var\/www\/html\"\nMain ErrorLog: \"\/etc\/httpd\/logs\/error_log\"\nMutex proxy: using_defaults\nMutex authn-socache: using_defaults\nMutex default: dir=\"\/run\/httpd\/\" mechanism=default\nMutex mpm-accept: using_defaults\nMutex authdigest-opaque: using_defaults\nMutex proxy-balancer-shm: using_defaults\nMutex rewrite-map: using_defaults\nMutex authdigest-client: using_defaults\nPidFile: \"\/run\/httpd\/httpd.pid\"\nDefine: DUMP_VHOSTS\nDefine: DUMP_RUN_CFG\nUser: name=\"apache\" id=48\nGroup: name=\"apache\" id=48<\/pre>\n\n\n\nIf 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.<\/p>\n\n\n\n
sudo nano \/etc\/apache2\/sites-enabled\/000-default.conf<\/pre>\n\n\n\nThis 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.<\/p>\n\n\n\n
<VirtualHost *:80>\n ServerName www.example.com\n ServerAdmin webmaster@localhost \n DocumentRoot \/var\/www\/html\n #LogLevel info ssl:warn \n ErrorLog ${APACHE_LOG_DIR}\/error.log\n CustomLog ${APACHE_LOG_DIR}\/access.log combined\n #Include conf-available\/serve-cgi-bin.conf\n<\/VirtualHost><\/pre>\n\n\n\nCentOS 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.<\/p>\n\n\n\n
sudo vi \/etc\/httpd\/conf\/httpd.conf<\/pre>\n\n\n\nLook for the same parameters ServerName and DocumentRoot, and make sure they are correctly set.<\/p>\n\n\n\n
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.<\/p>\n\n\n\n
sudo systemctl reload apache2<\/pre>\n\n\n\nsudo systemctl reload httpd<\/pre>\n\n\n\nCheck Logs<\/h2>\n\n\n\n
When everything on the service side is working as expected and you cannot find a fault, but the website just still won\u2019t load, it\u2019s 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\u2019s log directory using the commands below.<\/p>\n\n\n\n
sudo ls \/var\/log\/apache2\/<\/pre>\n\n\n\nsudo ls \/var\/log\/httpd\/<\/pre>\n\n\n\nThe 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.<\/p>\n\n\n\n
An easy way to start reading the logs, when you don\u2019t necessarily know what you are looking for, is to use the filtering app \u2018grep\u2019. Search for any errors using one of the commands below which corresponds with your system\u2019s web application name.<\/p>\n\n\n\n
sudo grep -i -r error \/var\/log\/apache2\/<\/pre>\n\n\n\nsudo grep -i -r error \/var\/log\/httpd\/<\/pre>\n\n\n\nUbuntu and Debian users might also need to check through the compressed log files. This can be done using \u2018zgrep\u2019 instead, but due to its limitations, you can only search one log at the time, for example using this following command.<\/p>\n\n\n\n
sudo zgrep error \/var\/log\/apache2\/error.log.2.gz<\/pre>\n\n\n\nNot 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.<\/p>\n\n\n\n
[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<\/pre>\n\n\n\nYou 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 \u2018LogLevel\u2019 in the configuration file. On Debian and Ubuntu systems, open your configuration file with the following command.<\/p>\n\n\n\n
sudo nano \/etc\/apache2\/apache2.conf<\/pre>\n\n\n\nWith CentOS and other Red Hat based server use the command here instead.<\/p>\n\n\n\n
sudo vi \/etc\/httpd\/conf\/httpd.conf<\/pre>\n\n\n\nFind the LogLevel parameter and change it from the default \u2018warn\u2019 value to \u2018debug\u2019 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.<\/p>\n\n\n\n
sudo systemctl reload apache2<\/pre>\n\n\n\nsudo systemctl reload httpd<\/pre>\n\n\n\nTo generate some new entries using the new log levels, try to access your website again a couple of times even if it doesn\u2019t work. The more verbose logs should help with narrowing down any underlying issues.<\/p>\n\n\n\n
Check other services<\/h2>\n\n\n\n
If your website still won\u2019t load after all the troubleshooting with Apache, check other related services on your cloud server such as databases, firewall and network connection<\/a>, which also have their own troubleshooting instructions.<\/p>\n\n\n\nDo 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.<\/p>\n","protected":false},"featured_media":27308,"comment_status":"open","ping_status":"closed","template":"","community-category":[116,123],"class_list":["post-24481","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry","community-category-web-hosting","community-category-troubleshooting"],"acf":[],"_links":{"self":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/tutorial\/24481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/types\/tutorial"}],"replies":[{"embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/comments?post=24481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/media\/27308"}],"wp:attachment":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/media?parent=24481"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/community-category?post=24481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}