Apache and Nginx Crashing, Port 80 Being Used, Can't Get Either to Start/Stop/Uninstall
https://askubuntu.com/questions/1045193/apache-and-nginx-crashing-port-80-being-used-cant-get-either-to-start-stop-un
I've been trying to set up a dev environment on a new Ubuntu 18.04 installation, and I'm running into an issue with Nginx and Apache.
First, I installed Apache2. Everything seemed in order.
Then I installed Composer, Laravel, and Valet. Running valet install gave me the following message:
[nginx] is not installed, installing it now via Apt... 🍻
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
nginx
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
1 not fully installed or removed.
Need to get 0 B/25.2 kB of archives.
After this operation, 36.9 kB of additional disk space will be used.
Selecting previously unselected package nginx.
(Reading database ... 172679 files and directories currently installed.)
Preparing to unpack .../nginx_1.14.0-0+bionic0_all.deb ...
Unpacking nginx (1.14.0-0+bionic0) ...
Setting up nginx-full (1.14.0-0+bionic0) ...
Job for nginx.service failed because the control process exited with error
code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
invoke-rc.d: initscript nginx, action "start" failed.
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2018-06-09 19:03:35 MST; 9ms ago
Docs: man:nginx(8)
Process: 4142 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 4138 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Jun 09 19:03:33 The-Lappy nginx[4142]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 09 19:03:33 The-Lappy nginx[4142]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 09 19:03:34 The-Lappy nginx[4142]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 09 19:03:34 The-Lappy nginx[4142]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 09 19:03:34 The-Lappy nginx[4142]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 09 19:03:34 The-Lappy nginx[4142]: nginx: [emerg] bind() to [::]:80 failed
(98: Address already in use)
Jun 09 19:03:35 The-Lappy nginx[4142]: nginx: [emerg] still could not bind()
Jun 09 19:03:35 The-Lappy systemd[1]: nginx.service: Control process exited,
code=exited status=1
Jun 09 19:03:35 The-Lappy systemd[1]: nginx.service: Failed with result 'exit-
code'.
Jun 09 19:03:35 The-Lappy systemd[1]: Failed to start A high performance web
server and a reverse proxy server.
dpkg: error processing package nginx-full (--configure):
installed nginx-full package post-installation script subprocess returned
error exit status 1
dpkg: dependency problems prevent configuration of nginx:
nginx depends on nginx-full (<< 1.14.0-0+bionic0.1~) | nginx-light (<< 1.14.0-0+bionic0.1~) | nginx-extras (<< 1.14.0-0+bionic0.1~); 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.14.0-0+bionic0) | nginx-light (>= 1.14.0-0+bionic0) | nginx-extras (>= 1.14.0-0+bionic0); 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
No apport report written because the error message indicates its a followup
error from a previous failure.
Errors were encountered while processing:
nginx-full
nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)
In Apt.php line 74:
Apt was unable to install [nginx].
install [--ignore-selinux]
Running sudo apt-get remove nginx gives me:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libnginx-mod-http-auth-pam libnginx-mod-http-dav-ext libnginx-mod-http-echo libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-subs-filter libnginx-mod-http-upstream-fair
libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common nginx-full
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
nginx
0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded.
2 not fully installed or removed.
After this operation, 36.9 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 172681 files and directories currently installed.)
Removing nginx (1.14.0-0+bionic0) ...
Setting up nginx-full (1.14.0-0+bionic0) ...
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
invoke-rc.d: initscript nginx, action "start" failed.
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2018-06-09 19:08:44 MST; 9ms ago
Docs: man:nginx(8)
Process: 4279 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 4278 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Jun 09 19:08:43 The-Lappy nginx[4279]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 09 19:08:43 The-Lappy nginx[4279]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 09 19:08:43 The-Lappy nginx[4279]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 09 19:08:43 The-Lappy nginx[4279]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 09 19:08:44 The-Lappy nginx[4279]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 09 19:08:44 The-Lappy nginx[4279]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 09 19:08:44 The-Lappy nginx[4279]: nginx: [emerg] still could not bind()
Jun 09 19:08:44 The-Lappy systemd[1]: nginx.service: Control process exited, code=exited status=1
Jun 09 19:08:44 The-Lappy systemd[1]: nginx.service: Failed with result 'exit-code'.
Jun 09 19:08:44 The-Lappy systemd[1]: Failed to start A high performance web server and a reverse proxy server.
dpkg: error processing package nginx-full (--configure):
installed nginx-full package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
nginx-full
E: Sub-process /usr/bin/dpkg returned an error code (1)
SO it looks like it was partially installed and then unable to remove nginx.
Running sudo nginx gives me:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
Running sudo apachectl start tells me the process failed with an error code and to check the logs. /var/log/apache2/error.log contains:
[Sat Jun 09 17:24:52.483178 2018] [mpm_event:notice] [pid 19739:tid 140694647565248] AH00489: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Sat Jun 09 17:24:52.483281 2018] [core:notice] [pid 19739:tid 140694647565248] AH00094: Command line: '/usr/sbin/apache2'
[Sat Jun 09 18:39:50.318815 2018] [core:warn] [pid 32508:tid 140277927611328] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat Jun 09 18:39:50.319348 2018] [mpm_event:notice] [pid 32508:tid 140277927611328] AH00489: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Sat Jun 09 18:39:50.319367 2018] [core:notice] [pid 32508:tid 140277927611328] AH00094: Command line: '/usr/sbin/apache2'
[Sat Jun 09 18:40:33.313855 2018] [core:warn] [pid 32625:tid 140576383269824] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat Jun 09 18:40:33.314401 2018] [mpm_event:notice] [pid 32625:tid 140576383269824] AH00489: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Sat Jun 09 18:40:33.314419 2018] [core:notice] [pid 32625:tid 140576383269824] AH00094: Command line: '/usr/sbin/apache2'
[Sat Jun 09 18:41:57.804899 2018] [mpm_event:notice] [pid 32625:tid 140576383269824] AH00491: caught SIGTERM, shutting down
So it's weird that I can't start Apache. However, visiting localhost in my browser brings me to the default ubuntu apache2 page.
Also, killing whatever's running on port 80 via fuser is no help.
So I'm kind of stumped here. Can anyone please help sort this out?
EDIT: I ran sudo apt-get remove nginx nginx-full and then ran a sudo netstat -ltnp | grep -w ':80' and got this:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 10008/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2151/nginx: master
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 713/systemd-resolve
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 5957/cupsd
tcp6 0 0 :::80 :::* LISTEN 2151/nginx: master
tcp6 0 0 ::1:631 :::* LISTEN 5957/cupsd