当我启动 Apache 时,它给出了以下错误 -
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
我执行了以下命令 -
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 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'.
我什么都不懂。有人能帮帮我吗?
答案1
我也遇到了同样的错误(使用 Saltstack 时),并设法解决了它。有四种方法。
由于某种原因,您的
/etc/apache2/envvars
缺失:
为了解决这个问题,您可以手动创建文件并在下面添加默认的环境变量内容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 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 modules and web application ## installations which interact with Apache #export APACHE2_MAINTSCRIPT_DEBUG=1
然后照常重新启动 apache 服务。
sudo service apache2 restart
如果您的
envvars
文件没有问题,则可能是缺少软件包。使用以下命令重新安装缺少的软件包,然后重新启动 Apache 服务。sudo apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2 sudo service apache2 restart
或者,您可以卸载 Apache 及其所有配置文件,然后重新安装它。
sudo apt-get purge apache2 sudo apt-get install apache2
最后,如果以上所有选项都不起作用,您可以尝试安装软件包
libapache2-mod-php7.0
或通过运行禁用 PHP7 模块sudo a2dismod php7.0