0

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  
  • some server , perhaps apache ? who knows, is running already on port 80. List what with sudo lsof -i – Panther Jun 10 '18 at 6:56
  • To uninstall nginx try sudo apt-get remove nginx nginx-full. You can't have two processes listening on port 80. Only one at a time is possible. If you need nginx you should disable or uninstall apache2. Your apache error log looks fine, can you add the output when you try to start apache to your question? – Lienhart Woitok Jun 10 '18 at 7:27
  • It seems that valet install will install nginx for you. Is there any reason you need to install another web server (apache) beforehand? Please show output of netstat -ltnp | grep -w ':80' , if apache is using the port 80, stop the apache process via sudo service apache2 stop. – Kong Chun Ho Jun 10 '18 at 8:21
  • @panther lsof shows that nginx, avahi-dae, systemd-r, cupsd, mysqld, and webkitnet are running. The only thing that shows 80 anywhere in that list is avahi-dae, which has a device value of 24680 – qotsa42 Jun 10 '18 at 23:47
0

I fiddled around with it for awhile and then ran sudo apt-get remove nginx-core nginx-full nginx-light nginx-extras nginx-naxsi nginx-common.

However, netstat was still showing that nginx was still running:

tcp6       0      0 :::80                   :::*                    LISTEN      2151/nginx: master

So at that point I rebooted my machine, and when i ran netstat it just showed me that apache was running and listening on port 80. So I stopped apache and ran valet install and valet installed successfully.

I'm not sure what to conlcude here except that under no circumstances should you try to install nginx via valet while apache2 is running in the background.

My only remaining question is why I had to do a full system reboot to fix the issue.

0

Ubuntu 18.04. The port 80 is used for another process.

netstat -ltnp | grep -w ':80'

tcp6       0      0 :::80                   :::*                    LISTEN     4114/httpd

In my case the pid process 4114 corresponds to the program nextcloud. (I installed it erroneously before nginx which is a prerequisite). Then you have to change the port in the nginx default configuration if you do not want to change the configuration of nexcloud or another process or if you do not want to kill it (both are good alternatives in any case). Edit the file:

sudo gedit /etc/nginx/sites-enabled/

At the beginning of that file, after the comments, you will find two lines:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

Edit that file and put 81 instead of 80 if you are willing to put 81 as your port for nginx. This edit has its validity even if apache2 is running in the same system and it has already owned that standard port. If any other process is occupying the port 80 you have to stop it before you install other programs like nginx. On Ubuntu 18.04 you get dependency errors which are almost impossible to clear but the reason is only that nginx cannot use the standart port 80. If you do not want to uninstall the process which is occupying the port 80 then you have at least to kill it before you do something:

fuser -k -n tcp 80

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.