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
Maybe a bit late, but I had the same issue, but then with ip6tables that gave an error :
$ sudo ifup ens160
run-parts: failed to exec /etc/network/if-pre-up.d/ip6tables: Exec format error
run-parts: /etc/network/if-pre-up.d/ip6tables exited with return code 1
Failed to bring up ens160.
My /etc/network/if-pre-up.d/ip6tables
looked like this:
ip6tables-restore < /etc/ip6tables.conf
I solved the issue by adding a shebang on top of the script to make it look like this:
#!/bin/sh
ip6tables-restore < /etc/ip6tables.conf
Now my interface is willing to come up.
I hope this solution might help you (and others that stumble across this post).
Best Answer
The reason Apache fails to start is because something is already listening on the port/ip combination. The log entries of "Address already in use" indicate this.
You need to identify what other service is running on those ports and then go and shut it off before turning on Apache.
However, since your log snippets ONLY are partial (and not from
sudo systemctl -l status apache2
so we can see all the actual useful information in large form, or from/var/log/apache2/error.log
directly), we can't really point you at which application(s) to look at since we can't determine the ports in use (my assumption is Port 80, in which casesudo ss -ntlp 'sport = 80'
will get us a better idea of what is already listening on Port 80. Please replace '80' with whatever other port is actually in use according to the long log data, which is cut off in what you pasted here.)