Apache start / stop / restart / status check
Explains how to start / stop / restart / check the status of Apache.
Apache status check
To check the status of Apache, use "status" of the systemctl command.
sudo systemctl status apache2
If it is running
If it is running, the following will be displayed.
● apache2.service --The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d mqapache2-systemd.conf Active: active (running) since Tue 2020-05-19 08:59:09 JST; 9s ago Process: 120415 ExecStop = / usr / sbin / apachectl stop (code = exited, status = 0 / SUCCESS) Process: 120947 ExecStart = / usr / sbin / apachectl start (code = exited, status = 0 / SUCCESS) Main PID: 120968 (apache2) Tasks: 55 (limit: 9479) CGroup: /system.slice/apache2.service tq120968 / usr / sbin / apache2 -k start tq120971 / usr / sbin / apache2 -k start mq120972 / usr / sbin / apache2 -k start
When stopped
If it is stopped, the following will be displayed.
● apache2.service --The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: Drop-In: /lib/systemd/system/apache2.service.d mqapache2-systemd.conf Active: inactive (dead) since Tue 2020-05-19 08:52:07 JST; 3min 51s ago Process: 120415 ExecStop = / usr / sbin / apachectl stop (code = exited, status = 0 / SUCCE Main PID: 104579 (code = exited, status = 0 / SUCCESS)
Starting Apache
To start Apache, use the systemctl command "start". Run with root privileges using the sudo command.
sudo systemctl start apache2
Even if the boot is successful, the message that it was successful is not returned. Please check the status.
Stop Apache
To stop Apache, use the systemctl command "stop". Run with root privileges using the sudo command.
sudo systemctl stop apache2
If the outage is successful, no successful message will be returned. Please check the status.
Restart Apache
To restart Apache, use the systemctl command "restart". Run with root privileges using the sudo command.
sudo systemctl restart apache2
restart simply executes the stop command and executes the start command. Normally, use the reload command as it will disconnect the processing from the HTTP client.
If the reboot is successful, you will not get a successful message. Please check the status.
Apache graceful restart
A graceful restart of Apache is done using the "reload" systemctl command. Run with root privileges using the sudo command.
sudo systemctl reload apache2
A restart called a graceful restart is a restart that uses a technology that allows Apache to be restarted while correctly returning an HTTP response to an HTTP client connected to Apache. .. It can handle all HTTP client processing correctly, so usually use this restart.
If the reboot is successful, you will not get a successful message. Please check the status.
To see the Apache start / stop log
Servers such as Apache are centrally managed by a program called systemd.
The Apache start / stop log is output to the systemd log.
Use the journalctl command to see the systemd logs. Specify the unit "apache2" with the "-u" option. Please note that you will not be able to see the Apache logs unless you run it with sudo. If you want to see only the last part of the log, combine the "-r" option.
sudo journalctl -r -u apache2
This is a sample log.
--Logs begin at Mon 2020-06-01 15:51:16 JST, end at Thu 2020-07-23 14:37:14 JST.- Jul 22 13:34:22 shinshina-development-app-00000001 systemd [1]: apache2.service: Failed with result'exit-code'. Jul 22 13:34:22 shinshina-development-app-00000001 systemd [1]: apache2.service: Main process exited, code = exited, status = 1 / FAILURE Jul 22 13:24:35 shinshina-development-app-00000001 systemd [1]: Started The Apache HTTP Server. Jul 22 13:24:35 shinshina-development-app-00000001 apachectl [1299]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.0.4. Set the'ServerName' direct Jul 22 13:24:33 shinshina-development-app-00000001 systemd [1]: Starting The Apache HTTP Server ... --Reboot - Jul 22 13:13:48 shinshina-development-app-00000001 systemd [1]: Stopped The Apache HTTP Server. Jul 22 13:13:47 shinshina-development-app-00000001 systemd [1]: Stopping The Apache HTTP Server ... Jul 22 06:25:03 shinshina-development-app-00000001 systemd [1]: Reloaded The Apache HTTP Server. Jul 22 06:25:03 shinshina-development-app-00000001 systemd [1]: Reloading The Apache HTTP Server.
Check if the Apache configuration file is correct before rebooting
Before restarting Apache (graceful restart), use "apachectl -t" to confirm that the Apache configuration file is correct. If you forget this, the reboot may fail and the web system may stop. It's easy to do, so be careful.
#Apache configuration file test apachectl -t
To see the Apache systemd configuration file
You can see the Apache systemd configuration file with "systemctl status apache2".
Let's take a look at the configuration file with the cat command.
cat /lib/systemd/system/apache2.service
Start, stop, reloadYou can check the mand definition and so on.
[Unit] Description = The Apache HTTP Server After = network.target remote-fs.target nss-lookup.target [Service] Type = forking Environment = APACHE_STARTED_BY_SYSTEMD = true ExecStart = / usr / sbin / apachectl start ExecStop = / usr / sbin / apachectl stop ExecReload = / usr / sbin / apachectl graceful PrivateTmp = true Restart = on-abort [Install] WantedBy = multi-user.target
Other Apache information
To install Apache
The following article explains how to install Apache.
Installation of apache2 --Apache version 2 series which is a web server
Apache configuration file
The Apache configuration file will be discussed in another article.