Apache2 无法启动

Apache2 无法启动

我最近在让 Apache2 与 php7.1 一起工作时遇到了麻烦。我通过使用启用了 php 模块,sudo a2enmod php7.1并且成功了。

我使用以下方法更新了我的服务器:

sudo apt-get update

进而

sudo apt-get upgrade

更新服务器后我重新启动了它。

我的 wordpress 网站不再工作并且它只是再次将 .php 页面显示为纯文本。

我以为这是我之前遇到的相同问题,所以我尝试使用上面提到的相同命令 () 手动重新启用 php7.1 模块sudo a2enmod php7.1。运行该命令后,我尝试使用以下命令重新启动 Apache2:

sudo service apache2 restart

仅向我提供此错误:

    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 - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Mon 2018-06-25 23:54:16 CDT; 7min ago
  Process: 1163 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Jun 25 23:54:16 UndergroundSpecInc systemd[1]: Starting The Apache HTTP Server...
Jun 25 23:54:16 UndergroundSpecInc apachectl[1163]: apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax e
Jun 25 23:54:16 UndergroundSpecInc apachectl[1163]: Action 'start' failed.
Jun 25 23:54:16 UndergroundSpecInc apachectl[1163]: The Apache error log may have more information.
Jun 25 23:54:16 UndergroundSpecInc systemd[1]: apache2.service: Control process exited, code=exited status=1
Jun 25 23:54:16 UndergroundSpecInc systemd[1]: apache2.service: Failed with result 'exit-code'.
Jun 25 23:54:16 UndergroundSpecInc systemd[1]: Failed to start The Apache HTTP Server.

因此,为了追踪线索,我调查了第 146 行,/etc/apache2/apache2.conf发现了以下内容:

IncludeOptional mods-enabled/*.load

这时我感到很困惑,因为我看不出那一行有什么问题。

答案1

我似乎已经回答了我自己的问题!

为了解决这个问题,我必须首先完全删除所有与 php 相关的已安装程序。(这是因为我在这个 Ubuntu 安装中更新过几次 php,所以与以前的版本有冲突。)

sudo apt-get purge php*

接下来,我发现了这篇文章,其中解释了在最新版本的 Ubuntu (18.04) 上,只需在 apt-get 命令中使用“php”即可自动安装 php7.2。因此,要重新安装,我只需使用:

sudo apt-get update
sudo apt-get upgrade

然后,一旦完成从清除 php* 调整软件包的操作,我使用以下命令重新安装 php:

sudo apt-get install php

完成后,我通过运行以下命令仔细检查了我的安装版本:

php -v

这给了我一个输出,表明我正在运行 php 7.2。太棒了!

我仍然需要重新安装 php7.2 的模块,因为它们在清除后被删除了。这是通过以下方式完成的:

apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php

完成后,我通过运行以下命令重新启用了 Apache2 的 php 模块:

sudo an2enmod php7.2

成功了!为了确保一切正常运行,最后一步是使用以下命令重新启动 Apache 2:

sudo service apache2 restart

重启成功!我打开浏览器,导航到该服务器上运行的 php 站点,加载完美!

我想本网站给予了我很大的帮助!

相关内容