Apache2 restart failed in Ubuntu 16.04
Solution 1
Install package libapache2-mod-php7.0
or disable the PHP7 module by running
sudo a2dismod php7.0
Solution 2
I also got the same issue and the reason it caused was something like this ,
I created a virtual host example.com.conf in etc/apache2/sites-available
, so it created a link of it in etc/apache2/sites-enabled
when u enable the virtual host for that particular host.
Later on i deleted the file example.com.conf from etc/apache2/sites-available
, but forgot to disable the host so the link of that host is still available at etc/apache2/sites-enabled
, so that causes the error in my case so i simply deleted that linked file from etc/apache2/sites-enabled
and my apache started working.
Solution 3
If you use php7 be sure to disable php5 module:
sudo a2dismod php5
this worked for me
Solution 4
Your issue is with your 2 lines in your config file. The 2 log paths cause an error with Apache.
I had this same issue and when I removed the two log file lines exactly like you had them I was able to restart apache.
Related videos on Youtube
![Anuj TBE](https://i.stack.imgur.com/iL5FE.jpg?s=256&g=1)
Anuj TBE
I am a software engineer persuing B.Tech with Computer Science. Like to write and deploy softwares,programs and website/web programs for windows,android and many...
Updated on September 18, 2022Comments
-
Anuj TBE almost 2 years
I am trying to use
domain
for mylocalhost
instead oflocalhost
or127.0.0.1
I have added a configuration file
myconfig.conf
insites-availbale
I also have enabled it usingsudo a2ensite myconfig.conf
When I restart
apache2
server usingsudo sudo systemctl restart apache2
, I get error asJob for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
I reinstalled
apache2
by uninstalling it but it gives error asJob for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details. invoke-rc.d: initscript apache2, action "start" failed.
Output of sudo
journalctl -xe
May 26 12:42:51 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:52 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:53 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:54 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:55 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:56 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:57 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:58 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:42:59 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:00 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:01 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:02 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:03 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:04 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:05 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:06 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:07 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:08 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:09 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:10 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:11 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:12 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:13 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:14 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:15 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:16 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:17 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:18 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:19 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:20 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:21 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:22 vostro-tbe gnome-session[2123]: GET /chrome HTTP/1.1 May 26 12:43:22 vostro-tbe sudo[16839]: anuj : TTY=pts/1 ; PWD=/etc/apache2/sites-available ; USER=root ; COMMAND=/bin/journalctl -xe May 26 12:43:22 vostro-tbe sudo[16839]: pam_unix(sudo:session): session opened for user root by anuj(uid=0)
Output of
systemctl status apache2.service
● 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 Thu 2016-05-26 12:42:43 IST; 53s ago Docs: man:systemd-sysv-generator(8) Process: 16781 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE) May 26 12:42:43 vostro-tbe apache2[16781]: * May 26 12:42:43 vostro-tbe apache2[16781]: * The apache2 configtest failed. May 26 12:42:43 vostro-tbe apache2[16781]: Output of config test was: May 26 12:42:43 vostro-tbe apache2[16781]: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 2 of /etc/apache2/mods-enabled/php7.0.load: Cannot load /usr/lib/apache2/modules/libphp7.0.so May 26 12:42:43 vostro-tbe apache2[16781]: Action 'configtest' failed. May 26 12:42:43 vostro-tbe apache2[16781]: The Apache error log may have more information. May 26 12:42:43 vostro-tbe systemd[1]: apache2.service: Control process exited, code=exited status=1 May 26 12:42:43 vostro-tbe systemd[1]: Failed to start LSB: Apache2 web server. May 26 12:42:43 vostro-tbe systemd[1]: apache2.service: Unit entered failed state. May 26 12:42:43 vostro-tbe systemd[1]: apache2.service: Failed with result 'exit-code'.
Output of
sudo apache2ctl configtest
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 2 of /etc/apache2/mods-enabled/php7.0.load: Cannot load /usr/lib/apache2/modules/libphp7.0.so into server: /usr/lib/apache2/modules/libphp7.0.so: cannot open shared object file: No such file or directory Action 'configtest' failed. The Apache error log may have more information.
content of
myconfig.conf
<VirtualHost *:80> ServerAdmin [email protected] ServerName website.com ServerAlias www.website.com DocumentRoot /var/www/html/website ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
-
MKay about 8 yearsSomething is wrong in your myconfig.conf.
-
Anuj TBE about 8 yearsupdated question with contents of
myconfig.conf
-
-
Anuj TBE about 8 yearsInstalled
libapache2-mod-php7.0
but still same error onsudo systemctl restart apache2
-
Anuj TBE about 8 yearsSolved! installed
libapache2-mod-php7.0
-
Shubham Agarwal over 7 yearsThis works perfectly thnks
-
CSharpened over 7 yearsThis was the solution for me also after removing a conf file and attempting a restart.
-
Cie6ohpa about 7 yearsSolved my problem too. On Ubuntu / Kubuntu 16.04.2 LTS Xenial (with a previous php5 installation).
sudo apt-get install libapache2-mod-php7.0
and thenapache2ctl configtest
(better than journal -xe) and finallysudo service apache2 start
-
Renaat De Muynck almost 7 yearsThis solved my problem too. I had my log file config pointing to a non existing location. Solved after doing
mkdir -p /my/log/location/