When I start apache then it gives me below error -

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

I executed below command -

 systemctl status apache2.service

I got below error

  apache2.service - LSB: Apache2 web server
  Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
  Active: failed (Result: exit-code) since Wed 2017-05-31 17:01:40 IST; 1min 34s ago
  Docs: man:systemd-sysv-generator(8)
  Process: 11884 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 3171 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 12696 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

 May 31 17:01:40 itadmin systemd[1]: Starting LSB: Apache2 web server...
 May 31 17:01:40 itadmin apache2[12696]:  * Starting Apache httpd web server apache2
 May 31 17:01:40 itadmin apache2[12696]: mktemp: failed to create file via template ‘/tmp/tmp.XXXXXXXXXX’: Read-only file system
May 31 17:01:40 itadmin apache2[12696]: /etc/init.d/apache2: 72: /etc/init.d/apache2: cannot create : Directory nonexistent
 May 31 17:01:40 itadmin apache2[12696]:  *
 May 31 17:01:40 itadmin apache2[12696]:  * The apache2 configtest failed.
 May 31 17:01:40 itadmin systemd[1]: apache2.service: Control process exited, code=exited status=1
 May 31 17:01:40 itadmin systemd[1]: Failed to start LSB: Apache2 web server.
May 31 17:01:40 itadmin systemd[1]: apache2.service: Unit entered failed state.
May 31 17:01:40 itadmin systemd[1]: apache2.service: Failed with result 'exit-code'.

I am not understanding anything. Please anyone can help me?

  • did you try to run sudo systemctl status apache2.service? it seems that mktemp has no right privilege to create temporary file – Lety May 31 '17 at 15:37
  • @Lety - yes there was permission issue – Jesni Johnson Jun 1 '17 at 7:17
  • this askubuntu.com/questions/647527/… could help – Lety Jun 1 '17 at 8:04

I also encountered the same error (while working with Saltstack) and managed to solve it. There are four ways.

  1. For some reason your /etc/apache2/envvars is missing:
    To solve this, you can create the file manually and add the default envvars content below

    sudo vim /etc/apache2/envvars
    # 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
    # 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 modules and web application
    ## installations which interact with Apache

    Then restart apache service as usual.

    sudo service apache2 restart
  2. If your envvars file is ok then it may be a case of missing packages. Reinstall the missing packages using below command, then restart the Apache service.

    sudo apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2
    sudo service apache2 restart 
  3. Alternatively you can uninstall Apache and all its config files then reinstall it.

    sudo apt-get purge apache2
    sudo apt-get install apache2
  4. And finally if all the options above don't work, you can try installing package libapache2-mod-php7.0 or disable the PHP7 module by running

    sudo a2dismod php7.0
| improve this answer | |
  • 1
    Your link does not work anymore, and this is the reason why we don't like links. you have a 30000 character limit for your answer, this should be enough to put the contents into your answer itself. This way you ensure your answer to be valid for a long time. – Videonauth Nov 8 '17 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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