Apache2 cannot bind to socket, and httpd cannot be killed

6,204

Noticing the problem

I noticed my apache server wasn't working as expected.

$sudo service apache2 status

Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: no listening sockets available, shutting down
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: AH00015: Unable to open logs
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: Action 'start' failed.
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: The Apache error log may have more information.
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]:  *
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4430]:  * Stopping Apache httpd web server apache2
Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4430]:  *
Jan 03 16:34:22 vmi120100.contaboserver.net systemd[1]: Started LSB: Apache2 web server.

The line stating "could not bind to address [::]:80" states that another program is using port 80.

Investigating the problem

To figure out what program uses port 80, i ran netstat.

$sudo netstat -tulpn | grep :80
tcp6       0      0 :::80               :::*                LISTEN      3979/httpd 

The output told me that process id 3979 with the name httpd is the one using up port 80.

To find out what runs httpd, i used ps aux

$ps aux | grep httpd
root      4995  0.0  0.0   4512  1708 ?        Ss   16:38   0:00 /bin/sh /snap/nextcloud/4371/bin/run-httpd -k start -DFOREGROUND
root      5129  0.0  0.0   4512  1668 ?        S    16:38   0:00 /bin/sh /snap/nextcloud/4371/bin/httpd-wrapper -k start -DFOREGROUND
root      5152  0.0  0.0  50712  4544 ?        S    16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
root      5153  0.0  0.0 413920  6324 ?        Sl   16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
root      5154  0.0  0.0 348352  6028 ?        Sl   16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
root      5155  0.0  0.0 348304  6028 ?        Sl   16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND

I see that it is run from /snap/nextcloud , which means that my nextcloud is the one who is messing about.

Fix

Further investigation, showed that i had both a snap and a regular install of nextcloud. All i had to do was to remove the snap, and everything was working fine.

If anyone has a similar problem, remember to assess how to resolve the issue. Uninstalling might not be the right option for you.

Share:
6,204
Bok
Author by

Bok

Updated on September 18, 2022

Comments

  • Bok
    Bok over 1 year

    I recently missed a payment on my VPS, and when i reactivated it the apache server isn't working correctly.

    I have a setup with various sites, seperated by subdomains (cloud.mydomain.com, wiki.mydomain.com etc.) and of course a mydomain.com front page.

    After the reactivation, all my subdomains point to cloud.mydomain.com, which is running nextcloud. I find it wierd it does not atleast point to my usual frontpage.

    Starting apache produces the following result:

    $sudo service apache2 stop
    $sudo service apache2 start
    $sudo service apache2 status
    
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: no listening sockets available, shutting down
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: AH00015: Unable to open logs
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: Action 'start' failed.
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]: The Apache error log may have more information.
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4414]:  *
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4430]:  * Stopping Apache httpd web server apache2
    Jan 03 16:34:22 vmi120100.contaboserver.net apache2[4430]:  *
    Jan 03 16:34:22 vmi120100.contaboserver.net systemd[1]: Started LSB: Apache2 web server.
    

    the output of netstat is:

    $sudo service apache2 stop
    $sudo netstat -tulpn | grep :80
    tcp6       0      0 :::80                   :::*                    LISTEN      3979/httpd  
    

    killing the process produces the following:

    $sudo netstat -tulpn | grep :80
    tcp6       0      0 :::80                   :::*                    LISTEN      3979/httpd      
    $sudo kill 3979
    $sudo netstat -tulpn | grep :80
    $ sudo netstat -tulpn | grep :80
    tcp6       0      0 :::80                   :::*                    LISTEN      5152/httpd 
    

    This all worked perfectly before the failed payment, made the company take the server down.

    EDIT: In response to the comment by panther: I already tried rebooting, but that produced the same result.

    There is nothing new in the logs since the reactivation.. last entry is before the server was taken down.

    Edit 2:
    output of ps aux:

    $ps aux | grep httpd
    root      4995  0.0  0.0   4512  1708 ?        Ss   16:38   0:00 /bin/sh /snap/nextcloud/4371/bin/run-httpd -k start -DFOREGROUND
    root      5129  0.0  0.0   4512  1668 ?        S    16:38   0:00 /bin/sh /snap/nextcloud/4371/bin/httpd-wrapper -k start -DFOREGROUND
    root      5152  0.0  0.0  50712  4544 ?        S    16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
    root      5153  0.0  0.0 413920  6324 ?        Sl   16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
    root      5154  0.0  0.0 348352  6028 ?        Sl   16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
    root      5155  0.0  0.0 348304  6028 ?        Sl   16:38   0:00 httpd -d /snap/nextcloud/4371 -k start -DFOREGROUND
    

    This could be a misconfigured nextcloud perhaps?

    • Panther
      Panther over 6 years
      What is in the apache log ? Perhaps reboot
    • vidarlo
      vidarlo over 6 years
      Have by any chanced installed two separate instances of Apache? For instance one from repositories (apt install apache2) and one from some other source? Because on Ubuntu the process name should be apache2, not httpd, if installed from repositories.
    • Bok
      Bok over 6 years
      I am quite confident i installed apache with apt-get. Is there a way to verify tis isnt the issue?
    • vidarlo
      vidarlo over 6 years
      Run ps aux | grep httpd and edit your question with this information.
    • Panther
      Panther over 6 years
      Looks as if apache is running via a snap package