Apache2 cannot be started and an error is reported for apache2.service failed because the control process exited with error code.

Today, when I was preparing to use Kali to build a website, The Apache server could not run normally. After patiently understanding the error code and Baidu finally solved the problem.
1. Error problem:
When you started apache2, the following error occurred. At first I thought it was not root, but switching to root still reported an error.

root@kali:/root# service apache2 start
Job for apache2.service failed because the control process exited with error code.
See "systemctl  status apache2.service" and "journalctl  -xe" for details.

At that time, I felt that KALI had not been used for a long time, because the software package was too old, so I updated it first.

root@kali:~# apt-get update

But the same error is reported, so you view the error message through the apache2 –help command.

apache2 --help
[Mon Apr 13 23:45:17.772837 2020] [core:warn] [pid 24587] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot

No new Apache environment variables were imported due to a change in the Apache configuration file after the upgrade. Solutions:

source /etc/apache2/envvars

Update later and still report an error, but the error message is different. The reasons for the error are:

root@kali:/root# apache2 --help
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

2. Solution:
Through the error code, we can know that it should not be able to bind to port 80, because the default port of Apache is 80. Of course, now there are two choices, one is to kill the process occupying the port, and the other is the better default port of Apache. I choose the first one.
First look at what process is occupying the port.

root@kali:/root# netstat -lnp|grep 80
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      18594/gsad          
unix  2      [ ACC ]     STREAM     LISTENING     18198    808/VGAuthService    /var/run/vmware/guestServicePipe

Then kill the process.

root@kali:/root# kill -9 18594

Finally, apache2 was successfully restarted.

root@kali:/root# /etc/init.d/apache2 start
[ ok ] Starting apache2 (via systemctl): apache2.service.

You can also change the default port for apache2, as shown in the response on StackOverflow.

Read More: