Recently, I had a friend setup a CentOS server for me as I personally have experience setting up and managing lamp on Ubuntu servers but needed a CentOS expert. Anyhow, the way to manage Apache on CentOS is a bit different than how it’s done on Ubuntu or debian based Linux. So I was trying to open my site and it wouldn’t connect. After ssh-ing into my box, I realized apache is not working and I needed to restart. Usually on Ubuntu you’d do
but it doesn’t really work, so after a couple minutes of googling, I found it
And, here is the error I got
Syntax error on line 295 of /etc/httpd/conf/httpd.conf: DocumentRoot '/var/www/html' is not a directory, or is not readable
Now issue was, I deleted the directory without checking if it’s used by apache as I usually remove the default config of apache using `html` directory for default site config. I know, noob mistake. Anyhow, I created that director again and this time
worked like a charm. But I didn’t give up on the httpd command just yet. So tried it again
# httpd restart Usage: httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-S] Options: -D name : define a name for use in directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings) -S : a synonym for -t -D DUMP_VHOSTS -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files
This time I realized I was doing it without the extra params I had to give to httpd command, so here we go:
Now I just wanted to try it
# httpd -k stop # httpd -k restart
So the first one stops it, I checked after and the site won’t load. That means it worked. Then I simply used restart ( I could have used -k start to start as well) to get it up and running.
This time, above command works perfectly. So a little but of learning today. Moral of the story, just try a little harder before googling it.
Hope this helps 🙂
Link to official CentOS page regarding starting and stopping apache. https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-apache-startstop.html