laravel / homestead

MIT License
3.87k stars 1.44k forks source link

vagrant provision crashes in the middle of many Sites (vhosts) because Apache can't bind to port 80 #1948

Open mikeziri opened 9 months ago

mikeziri commented 9 months ago

Versions

Host operating system

MacOS 14.3 (23D56) on Apple M2 Pro

Expected behavior

I have more than 100 vhosts on my Homestead.yaml. After upgrading to the new box homestead (not -arm), did a full provision and expected the provision to end.

Actual behavior

The vagrant provision fails in different places after consecutive runs. After provisioning the last "Site" before crashing, the vagrant provision outputs:

    homestead: Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
    homestead: Executing: /lib/systemd/systemd-sysv-install disable nginx
    homestead: Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
    homestead: Executing: /lib/systemd/systemd-sysv-install enable apache2
    homestead: Job for apache2.service failed.
    homestead: See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.

I then login via ssh with vagrant ssh and run journalctl -xeu apache2.service outputing (in the end):

░░ A reload job for unit apache2.service has begun execution.
░░
░░ The job identifier is 32278.
Jan 31 15:39:06 homestead apachectl[96200]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.2.1. Set the 'ServerName' directi>
Jan 31 15:39:06 homestead apachectl[96200]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Jan 31 15:39:06 homestead apachectl[96200]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Jan 31 15:39:06 homestead apachectl[96200]: no listening sockets available, shutting down
Jan 31 15:39:06 homestead apachectl[96200]: AH00015: Unable to open logs
Jan 31 15:39:06 homestead apachectl[96200]: httpd not running, trying to start
Jan 31 15:39:06 homestead apachectl[96197]: Action 'graceful' failed.
Jan 31 15:39:06 homestead apachectl[96197]: The Apache error log may have more information.
Jan 31 15:39:06 homestead systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE

It seems the problem lies in the ipv4 (or ipv6) version:

(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80

Where Apache tries to bind to port 80 but fails.

My suspicion is the fact that on each Site provisioning, Nginx is disabled and then Apache is enabled. But sometimes, Nginx didn't yet release it's port 80 (socket) and Apache fails to bind.

There's not a clear pattern on which Site (vhost) it fails when provisioning. Almost always a different one.

Would it be possible to add an X seconds sleep in between Nginx disable and Apache enable commands while provisioning? Better yet, is it possible to completely disable Nginx as an installed service as we only use Apache?

Although this is on Mac M2 (Arm), I have colleagues on Intel machines with the same problem.

Our workaround is to place the vhost we need to work on, on top of the Sites list on Homestead.yaml and provision again, hoping it goes past the first one.

lachmart commented 6 months ago

I'm encountering the same issue on an Intel Mac using the VirtualBox provider.

svpernova09 commented 5 months ago

https://github.com/svpernova09/homestead/issues/2

jakub-vozenilek commented 4 months ago

I'm also having the same issue on an Intel Windows using the VirtualBox provider.

lachmart commented 4 months ago

I am only using Apache for all my websites. Here's a workaround that seems to be working, in case anyone else needs it:

  1. edit file scripts\site-types\apache.sh - remove lines with nginx and apache (lines 24-27 and 148-154)
    sudo service nginx stop
    sudo systemctl disable nginx
    sudo systemctl enable apache2
    
    service apache2 restart
    service php"$5"-fpm restart

if [ $? == 0 ] then service apache2 reload fi


2. add this to /after.sh

sudo service nginx stop sudo systemctl disable nginx sudo systemctl enable apache2 sudo service apache2 restart sudo service php5.6-fpm restart sudo service php7.0-fpm restart sudo service php7.1-fpm restart sudo service php7.2-fpm restart sudo service php8.0-fpm restart sudo service php8.1-fpm restart sudo service php8.2-fpm restart sudo service php8.3-fpm restart sudo service apache2 reload