How can I start and stop apache

Posted: 1st November 2014 by kunwardharmesh in Apache

You stop a service with the systemctl stop command.

$ systemctl stop httpd

There’s no additional output, you can still use systemctl status to verify the service stopped.

$ systemctl status httpd
   Active: inactive (dead) since Sat 2015-08-08 20:53:23 CEST; 25s ago
  Process: 28234 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 27482 (code=exited, status=0/SUCCESS)

The service is “inactive (dead)” and was cleanly shutdown (“code=exited, status=0”).

Alternatively, if you kill -9 a process, it’ll show you that in the systemctl status output.

$ systemctl status httpd
  Process: 28465 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=killed, signal=KILL)
 Main PID: 28465 (code=killed, signal=KILL)

Useful output right there.

Start a service on CentOS 7

Like stopping a service, you can start a service with systemctl start.

$ systemctl start httpd

Again, no output, unless something went wrong. Use systemctl status to check the status of your service.

If you made an error in your service configuration, you get output like this.

$ systemctl start httpd
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

To see why the service failed to start, check the specific service logs. Systemd also has a way to output the info, but I find it cumbersome and sometimes lacking info — the kind of info that’s logged in additional error logs from the particular service.

$ systemctl status httpd
Aug 08 20:57:38 ma httpd[29986]: AH00526: Syntax error on line 14 of /etc/httpd/conf.d/something.conf:
Aug 08 20:57:38 ma httpd[29986]: Invalid command 'syntax', perhaps misspelled or defined by a module not included in the server configuration

If you get an error, fix it and try to start your service again.

Hope you Enjoy!