11

I use Ubuntu 16.02. When i try sudo service apache2 restart, it says:

Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

Then I type: journalctl -xe, and request:

-- 
-- Unit apache2.service has begun starting up.
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:  * Starting Apache httpd web server apache2
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:  *
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:  * The apache2 configtest failed.
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: Output of config test was:
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: AH00014: Configuration check failed
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: Action 'configtest' failed.
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: The Apache error log may have more information.
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: apache2.service: Control process exited, code=exited status=1
Jan 11 02:30:46 aleksandr-VirtualBox sudo[8171]: pam_unix(sudo:session): session closed for user root
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: Failed to start LSB: Apache2 web server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has failed.
-- 
-- The result is failed.
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: apache2.service: Unit entered failed state.
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: apache2.service: Failed with result 'exit-code'.
Jan 11 02:33:09 aleksandr-VirtualBox dhclient[792]: DHCPREQUEST of 192.168.56.101 on enp0s8 to 192.168.56.100 port 67 (xid=0x204f076f)
Jan 11 02:33:09 aleksandr-VirtualBox dhclient[792]: DHCPACK of 192.168.56.101 from 192.168.56.100
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:   [1484073189.4253]   address 192.168.56.101
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:   [1484073189.4260]   plen 24 (255.255.255.0)
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:   [1484073189.4266]   server identifier 192.168.56.100
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:   [1484073189.4273]   lease time 1200
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:   [1484073189.4279] dhcp4 (enp0s8): state changed bound -> bound
Jan 11 02:33:09 aleksandr-VirtualBox dbus[590]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Jan 11 02:33:09 aleksandr-VirtualBox systemd[1]: Starting Network Manager Script Dispatcher Service...
-- Subject: Unit NetworkManager-dispatcher.service has begun start-up
-- Defined-By: systemd
-- Support: 
-- 
-- Unit NetworkManager-dispatcher.service has begun starting up.
Jan 11 02:33:09 aleksandr-VirtualBox dhclient[792]: bound to 192.168.56.101 -- renewal in 559 seconds.
Jan 11 02:33:09 aleksandr-VirtualBox dbus[590]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Jan 11 02:33:09 aleksandr-VirtualBox systemd[1]: Started Network Manager Script Dispatcher Service.
-- Subject: Unit NetworkManager-dispatcher.service has finished start-up
-- Defined-By: systemd
-- Support: 
-- 
-- Unit NetworkManager-dispatcher.service has finished starting up.
-- 
-- The start-up result is done.
Jan 11 02:33:09 aleksandr-VirtualBox nm-dispatcher[8205]: req:1 'dhcp4-change' [enp0s8]: new request (1 scripts)
Jan 11 02:33:09 aleksandr-VirtualBox nm-dispatcher[8205]: req:1 'dhcp4-change' [enp0s8]: start running ordered scripts...

And when systemctl status apache2.service It`s reaqest:

* apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           `-apache2-systemd.conf
   Active: failed (Result: exit-code) since Wed 2017-01-11 02:30:46 +08; 33min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8023 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 2236 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 8177 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: AH00014: Configuration check failed
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: Action 'configtest' failed.
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: The Apache error log may have more information.
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: apache2.service: Control process exited, code=exited status=1
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: Failed to start LSB: Apache2 web server.
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: apache2.service: Unit entered failed state.
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]: apache2.service: Failed with result 'exit-code'.

What is wrong? Where is an interrupt? Please help!

8

There are two errors:


1. For some reason your /etc/apache2/envvars is missing:

  • from journalctl -xe:

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found
    ...        
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found
    
  • from systemctl status apache2.service:

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found
    

In my system this file has next permissions:

$ ls -l /etc/apache2/envvars

-rw-r--r--   1 root root  1782 мар 19  2016 envvars

And its content ($ cat /etc/apache2/envvars) is:

# envvars - default environment variables for apache2ctl

# this won't be correct after changing uid
unset HOME

# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
        SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
        SUFFIX=
fi

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy+1
export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale

export LANG

## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'

## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'

## If you would like to pass arguments to the web server, add them below
## to the APACHE_ARGUMENTS environment.
#export APACHE_ARGUMENTS=''

## Enable the debug mode for maintainer scripts.
## This will produce a verbose output on package installations of web server mod                                               ules and web application
## installations which interact with Apache
#export APACHE2_MAINTSCRIPT_DEBUG=1

You can create it manually: sudo nano /etc/apache2/envvars, paste above content inside, save ctrl+o and exit ctrl+x.


2. In your system, the folder /etc/apache2/logs also missing:

  • from journalctl -xe:

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log
    
  • from systemctl status apache2.service:

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log
    

This is not the default log folder, it is defined in your custom configuration, and must be created:

$ sudo mkdir /etc/apache2/logs
| improve this answer | |
  • I did as you wrote. Unfortunately, error still exist :( So will continue searching – A.Verber Jan 10 '17 at 20:01
  • @A.Verber Is still the same error or something has changed? – pa4080 Jan 10 '17 at 20:05
  • 1
    @A.Verber I'm have looked again your question. Is in your system the directory /etc/apache2/logs/ exists? Because this is the second error message. You can try sudo mkdir /etc/apache2/logs. – pa4080 Jan 10 '17 at 20:29
  • 1
    Yes! After making log dir, error disappeared! Thank you – A.Verber Jan 11 '17 at 6:32
5

I deleted .conf files in sites-available and did not delete the link files in sites- enabled .

Now I deleted those all files in sites-enabled

restarted apache2 server (sudo service apache2 restart)

worked for me

hope this might help someone :)

| improve this answer | |
5

I had the same problem. I got the same error with sudo service apache2 restart and ran sudo systemctl status apache2.service and the red line was Failed to start LSB: Apache2 web server.

Solution

run the bellow command:

sudo apache2ctl configtest

It'll check for errors (Syntax errors I think) and then you can debug the error.

| improve this answer | |
  • Your solution helped me to solve my apache2 issue, thanks. – S1awek Oct 16 '19 at 11:17
4

Try these commands:

sudo a2dismod mpm_event
sudo a2enmod mpm_prefork

Then restart apache2 service.

| improve this answer | |
  • sudo a2dismod mpm_event sudo a2enmod mpm_prefork – arnauld Apr 7 '17 at 14:47
0

In my case i do this:

uninstall and remove Apache2

sudo service apache2 stop

sudo apt-get purge apache2

sudo apt-get autoremove

whereis apache2

sudo rm -rf /etc/apache2

reinstall apache2

sudo apt-get install apache2

sudo apache2ctl configtest

It run for me

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.