Posted by on 2017年1月23日

其实这个问题我不是第一次遇到了,第一次遇到是很久之前在树莓派上遇到的。

先说结论:实际上是由于 apt-get install nginx php5  时,apt先安装了php5的依赖,其中有apache2,而且后面setting up的时候也是先set up的apache2,当dpkg configure nginx的时候由于80端口已经被apache2使用,所以无法继续configure nginx

  • 解决方案就是删掉apache2,然后apt purge nginx,最后重新apt-get install nginx即可。

 

[email protected]****:~# apt-get install nginx php5
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd3 liblua5.1-0 libonig2 libqdbm14 libvpx1 libxpm4 libxslt1.1 nginx-common nginx-full
php5-cli php5-common php5-json php5-readline ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine apache2-suexec-custom php-pear libgd-tools fcgiwrap nginx-doc php5-user-cache openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd3 liblua5.1-0 libonig2 libqdbm14 libvpx1 libxpm4 libxslt1.1 nginx nginx-common
nginx-full php5 php5-cli php5-common php5-json php5-readline ssl-cert
0 upgraded, 25 newly installed, 0 to remove and 0 not upgraded.
Need to get 8,989 kB of archives.
After this operation, 32.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main libapr1 amd64 1.5.1-3 [95.3 kB]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Creating config file /etc/php5/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php5
Setting up nginx-common (1.6.2-5+deb8u4) ...
Setting up nginx-full (1.6.2-5+deb8u4) ...
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript nginx, action "start" failed.
dpkg: error processing package nginx-full (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of nginx:
nginx depends on nginx-full (>= 1.6.2-5+deb8u4) | nginx-light (>= 1.6.2-5+deb8u4) | nginx-extras (>= 1.6.2-5+deb8u4); however:
Package nginx-full is not configured yet.
Package nginx-light is not installed.
Package nginx-extras is not installed.
nginx depends on nginx-full (<< 1.6.2-5+deb8u4.1~) | nginx-light (<< 1.6.2-5+deb8u4.1~) | nginx-extras (<< 1.6.2-5+deb8u4.1~); however:
Package nginx-full is not configured yet.
Package nginx-light is not installed.
Package nginx-extras is not installed.

dpkg: error processing package nginx (--configure):
dependency problems - leaving unconfigured
Setting up php5 (5.6.29+dfsg-0+deb8u1) ...
Setting up php5-readline (5.6.29+dfsg-0+deb8u1) ...

Creating config file /etc/php5/mods-available/readline.ini with new version
php5_invoke: Enable module readline for apache2 SAPI
php5_invoke: Enable module readline for cli SAPI
Setting up ssl-cert (1.0.35) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...
Processing triggers for systemd (215-17+deb8u6) ...
Processing triggers for libapache2-mod-php5 (5.6.29+dfsg-0+deb8u1) ...
Errors were encountered while processing:
nginx-full
nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

  • 从上面可以看出dpkg configure nginx时出现了错误,先是从nginx-full开始,无法启动导致后面一系列的无法configure。

[email protected]****:~# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Tue 2017-01-17 15:57:57 HKT; 13s ago
Process: 3757 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 3754 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Jan 17 15:57:55 jaded nginx[3757]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 17 15:57:55 jaded nginx[3757]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 17 15:57:56 jaded nginx[3757]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 17 15:57:56 jaded nginx[3757]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 17 15:57:56 jaded nginx[3757]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 17 15:57:56 jaded nginx[3757]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 17 15:57:57 jaded nginx[3757]: nginx: [emerg] still could not bind()
Jan 17 15:57:57 jaded systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 17 15:57:57 jaded systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Jan 17 15:57:57 jaded systemd[1]: Unit nginx.service entered failed state.

  • 从systemctl status nginx.service中我们可以看出nginx无法bind到80端口,导致无法启动。

[email protected]****:~# systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2)
Drop-In: /lib/systemd/system/apache2.service.d
└─forking.conf
Active: active (running) since Tue 2017-01-17 15:47:45 HKT; 11min ago
CGroup: /system.slice/apache2.service
├─3138 /usr/sbin/apache2 -k start
├─3141 /usr/sbin/apache2 -k start
├─3142 /usr/sbin/apache2 -k start
├─3143 /usr/sbin/apache2 -k start
├─3144 /usr/sbin/apache2 -k start
└─3145 /usr/sbin/apache2 -k start

Jan 17 15:47:44 jaded systemd[1]: Starting LSB: Apache2 web server...
Jan 17 15:47:45 jaded apache2[3124]: Starting web server: apache2.
Jan 17 15:47:45 jaded systemd[1]: Started LSB: Apache2 web server.

而apache2却已经启动了。

  • 不要继续尝试dpkg –configure nginx了,因为还是会返回同样的错误信息,而且这时候你连apt purge nginx都做不到。

[email protected]****:~# apt purge nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libgd3 libvpx1 libxpm4 libxslt1.1 nginx-common nginx-full
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
nginx*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 102 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 30618 files and directories currently installed.)
Removing nginx (1.6.2-5+deb8u4) ...
Setting up nginx-full (1.6.2-5+deb8u4) ...
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript nginx, action "start" failed.
dpkg: error processing package nginx-full (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
nginx-full
E: Sub-process /usr/bin/dpkg returned an error code (1)

 

[email protected]****:~# apt-get remove apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libgd3 libvpx1 libxpm4 libxslt1.1 nginx-common nginx-full
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
php5-cgi
Suggested packages:
php-pear
The following packages will be REMOVED:
apache2 libapache2-mod-php5
The following NEW packages will be installed:
php5-cgi
0 upgraded, 1 newly installed, 2 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 4,316 kB of archives.
After this operation, 7,656 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian/ jessie/main php5-cgi amd64 5.6.29+dfsg-0+deb8u1 [4,316 kB]
Fetched 4,316 kB in 0s (4,418 kB/s)
Selecting previously unselected package php5-cgi.
(Reading database ... 30614 files and directories currently installed.)
Preparing to unpack .../php5-cgi_5.6.29+dfsg-0+deb8u1_amd64.deb ...
Unpacking php5-cgi (5.6.29+dfsg-0+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
dpkg: libapache2-mod-php5: dependency problems, but removing anyway as you requested:
php5 depends on libapache2-mod-php5 (>= 5.6.29+dfsg-0+deb8u1~) | libapache2-mod-php5filter (>= 5.6.29+dfsg-0+deb8u1~) | php5-cgi (>= 5.6.29+dfsg-0+deb8u1~) | php5-fpm (>= 5.6.29+dfsg-0+deb8u1~); however:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • apt purge nginx后再次apt-get install nginx,问题解决