I am getting a 502 Bad Gateway on my Laravel projects running Laravel valet.
I have tried many of the solutions online and with no success. i.e. https://gist.github.com/adamwathan/6ea40e90a804ea2b3f9f24146d86ad7f
At the moment the error I see is 502 bad gateway and an error in my command line when running valet install is an error when it gets to the updating PHP configuration. It gives the following error:
Warning: file_get_contents(/usr/local/etc/php/7.3/php-fpm.d/www.conf): failed to open stream: No such file or directory in /Users/username/.composer/vendor/laravel/valet/cli/Valet/Filesystem.php on line 112
Warning: file_get_contents(/usr/local/etc/php/7.3/php-fpm.d/www.conf): failed to open stream: No such file or directory in /Users/username/.composer/vendor/laravel/valet/cli/Valet/Filesystem.php on line 125
Has anybody had similar issues?
Thanks
If you're anyone like me who're seeing 502 Bad Gateway while using Laravel Valet after updating it composer global update to the latest version, you most probably forgot to run valet install command. Laravel Valet requires (in most cases) to run valet install command after updating to the latest version.
in most cases running valet install will solve the issue.
Had the same symptoms after updating to php 7.3 and then installing a new Laravel project.
It appears that brew install php73 doesn't install php-fpm
Solution is to uninstall php
brew uninstall php73
brew uninstall php72
brew uninstall php71 ... whatever versions you have
brew uninstall --force php
Now reinstall php
brew install php --build-from-source
I encountered permission errors mkdir: /usr/local/etc/php/7.3/php-fpm.d: Permission denied so sudo chown -R: <yourusercode> /usr/local/etc/php fixed that and then brew install php --build-from-source again. Once it builds php 7.3 successfully reinstall valet:
valet install
None of the above answers worked for me, but found the solution here: https://janostlund.com/2019-06-20/502-bad-gateway-laravel-valet
~/.config/valet/Log/nginx-error.log shows:
[error] 17423#0: *1 upstream sent too big header while reading response header from upstream [...]
Solved by adding two lines to http in /usr/local/etc/nginx/nginx.conf
http {
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
//...
}
and then running valet restart
I solved this by doing:
php -v
PHP 8.0.1 (cli) (built: Jan 8 2021 09:07:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies
followed by:
valet use php#8.0 --force
Unlinking current version: php
Linking new version: php#8.0
Updating PHP configuration...
Restarting php...
Restarting nginx...
Valet is now using php#8.0.
Valet seemed to be confused over which PHP it was using.
I ran into the same problem with Laravel 8. Both Valet and Expose seemed to work, but the webpage always gave a 502 response.
The solution I found when I updated composer and tried to reinstall Valet was that Valet didn't know which version of php to use.
To fix this, use the following command to tell valet which version of php to use.
valet use php#7.4
Try this
brew services start php
If it didn’t work, try to reinstall php from source
brew uninstall php
brew install php --build-from-source
valet install
Source: laravel/valet github issues
Well, normally "valet install" solves the issue but for me it was different.
For my case, I was using valet isolate for a different project with different PHP versions. So, I have to do the binding process again.
I did,
valet install
valet isolate php#7.1 (Here you have to use the selected version)
this solves the issue for me.
In my case I reinstalled different version of php. I just run
valet install
and it worked fine.
I had the same problem. I solved it by upgrading mariadb. brew upgrade mariadb
Following the config above, but put it in the file.
~/.valet/Nginx/all.conf
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
This did catch on all the sites "Im use Valet plus"
If the valet restart or valet install didn't work, try to change the PHP version.
valet use php#7.4
Or
valet isolate php#7.4
My nginx-error.log file was full of messages like this
*3 connect() to unix:/home/oakbox/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1
It took me too long to figure out that php-fpm was running, but that Nginx could not 'see' that socket. Look in your Nginx configuration file for the line that starts with
fastcgi_pass unix:/home/oakbox/.valet/valet.sock;
And then look to see if that socket actually exists. In my setup, an update of my system moved my default PHP installation from version 8.1 to 8.2. The actual socket file was renamed from valet.sock to valet82.sock.
I edited my Nginx configuration files to point to the real location of the socket
fastcgi_pass unix:/home/oakbox/.valet/valet82.sock;
A restart of Nginx and my 502 Bad Gateway went away.
Related
My existing version was php8.1 using Laravel Valet 3.3.2. I did a brew php install and the php version was updated to php8.2
The site loaded fine on php8.2. When I switched to use the older version using
valet use php#8.1
I get this error
Warning: require(/MY_LARAVEL_PROJECT/public/index.php): Failed to open stream: Operation not permitted in /MY_DIRECTORY_NAME/.composer/vendor/laravel/valet/server.php on line 250
Fatal error: Uncaught Error: Failed opening required '/MY_LARAVEL_PROJECT/public/index.php' (include_path='.:/usr/local/Cellar/php#8.1/8.1.15/share/php#8.1/pear') in /MY_DIRECTORY_NAME/.composer/vendor/laravel/valet/server.php:250 Stack trace: #0 {main} thrown in /MY_DIRECTORY_NAME/.composer/vendor/laravel/valet/server.php on line 250
However, these scenarios below worked fine
valet use php#8.0
valet use php
valet use php#8.1
valet stop
php artisan serve
For this last one, the site could work if I used artisan serve instead of valet and loaded the page via 127.0.0.1:8000
I have tried most of the solutions I could find online. The most comprehensive being to uninstall and reinstall everything related to valet.
valet uninstall --force
sudo brew services stop nginx
sudo brew services stop php
sudo brew services stop dnsmasq
brew uninstall nginx
brew uninstall composer
brew uninstall php
brew uninstall php#8.1
brew uninstall php#8.0
brew uninstall dnsmasq
rm -rf ~/.config/valet
And then reinstall php, composer and valet. I tried this a few times using different combinations and ensuring the config files are removed when prompted by brew.
I've also tried setting the public folder and index.php file to 777.
The problem still persisted.
On console, when doing
php -v
I get
PHP 8.1.15 (cli) (built: Feb 3 2023 12:44:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.15, Copyright (c) Zend Technologies
with Zend OPcache v8.1.15, Copyright (c), by Zend Technologies
So it seems that this error occurs under the scenario when valet uses php8.1, which was my previous default php version. Probably some config or links related to valet that was not updated / removed.
I would appreciate if anyone can point me in any direction to investigate further. Thanks in advance!
I updated my MacOS to Monterey (12.0.1) and my PHP stopped working.
MacOS 12 seem to have removed PHP support.
I'm currently trying to configure everything using homebrew.
After installation, when I try to start the httpd, I'm getting the following errors-
user#Laptop folder % /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
dyld[15738]: Symbol not found: _apr_bucket_file_set_buf_size
Referenced from: /opt/homebrew/Cellar/httpd/2.4.51/bin/httpd
Expected in: /usr/lib/libaprutil-1.0.dylib
zsh: abort /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
Am I missing any package for _apr_bucket_file_set_buf_size?
Yeah, what a nightmare! PHP is no longer supported natively in MacOS 12. I switched to Homebrew's Apache (httpd) package.
But switching from native Apache to Homebrew's Apache wasn't easy.
There are lots of guides out there on how to install Homebrew's Apache. I won't go into them here.
But after installing, configuring, and starting, I was receiving a similar error to your "apr_bucket" error. I ran brew reinstall apr-util and that did the trick.
Found it here: https://stackoverflow.com/a/41871228/1623341
After that, I removed Homebrew's Apache brew remove httpd, then reinstalled brew install httpd, then updated the httpd.conf file, then started brew services start httpd. That seemed to do the trick for me.
I had to sign the homebrew PHP module using MacOS codesign.
Finally, Apache and PHP are working in my MacOS Monterey.
Kudos to the original author for the detailed solution
https://www.simplified.guide/macos/apache-php-homebrew-codesign
I'm running valet 2.0.5 and it is using the wrong version of PHP. When starting valet I get
$ valet start
Restarting php71...
Restarting nginx...
Valet services have been started.
But phpinfo() gives PHP Version 5.6.30 and Loaded Configuration File: /usr/local/etc/php/5.6/php.ini.
I've installed and relinked php using brew,
$ which php
/usr/local/opt/php71/bin/php
$ php -v
PHP 7.1.7
I've tried uninstalling and reinstalling valet, to no avail.
The old version of PHP (in my case 7.4) was "stuck" for some reason in Valet. Even though php -v returns me php 8.0. The way to force Valet to choose the right version you can use the following command:
valet use php#8.0 --force
Uncommenting LoadModule php5_module libexec/apache2/libphp5.so in /etc/apache2/httpd.conf did the trick. I don't really know why this worked, but I'm not complaining.
Had a similar problem when upgrading from 7.1 to 7.2.
For me the solution was that I removed the symlinks for php7.1 from /usr/local/opt/
I used Homebrew to install apache 2.4 and php 5.4 (also tried 5.6) (using Mac Osx Mavericks). When I try to load the php5 module I get the following error:
httpd: Syntax error on line 157 of /usr/local/apache-2.4.9/conf/httpd.conf: Cannot load /usr/local/opt/php56/libexec/apache2/libphp5.so into server: dlopen(/usr/local/opt/php56/libexec/apache2/libphp5.so, 10): Symbol not found: _unixd_config\n Referenced from: /usr/local/opt/php56/libexec/apache2/libphp5.so\n Expected in: /usr/local/apache-2.4.9/bin/httpd\n in /usr/local/opt/php56/libexec/apache2/libphp5.so
I tried re-installing php a few different ways I saw online with users having the same error, but to no avail:
brew install php55 --homebrew-apxs
brew install php56 --with-mysql --with-homebrew-apache
brew install -s php56
Anyone know how I could resolve this issue? Thanks in advance!
I was able to fix the issue by running the following:
brew install 56 --with-apache
I'm not sure if that's ideal way to fix and am still having an issue rendering the php page (which might be related to a separate issue), but hopefully this helps someone.
OK, so (retrospectively, quite stupidly), I upgraded my mac osx PHP version (not mamp php) from 5.3.28 to 5.4.10, to try and install composer. Now my MAMP sites don't seem to be loading. (I am not a backender.)
1. I upgraded mamp
At the end of the upgrade the final messages in terminal were as follows:
Create symlink /usr/local/php5/entropy-php.conf /etc/apache2/other/+php-osx.conf
Restarting Apache
httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.2 for ServerName
Syntax OK
But when I checked the php version in terminal, it still said 5.3.28.
2. MAMP start page loaded, sites didn't work
Suddenly none of my MAMP sites were working. I have set the virtual hosts in httpd-vhosts.conf (and using sudo vim /etc/hosts). These have been working for like 3 years with no problem.
MAMP still loads the start page, but when I load a site I get:
Not Found
The requested URL / was not found on this server.
Apache/2.2.26 (Unix) PHP/5.4.41 DAV/2 Server at domain.dev Port 80
3. Reinstalled MAMP
So I then uninstalled and reinstalled MAMP, and restored all my settings, which again still loads up fine (the MAMP php version is now 5.6.7).
4. Tried downgrading mac php back to 5.3.28
I then tried to downgrade back to PHP 5.3.28, but that wouldn't work when I tried to use:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.3.28
So I just used:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.3
And it appears to have downgraded to 5.3.29, but with the following error at the end:
Executing post-install script /tmp/5.3-frontenddev-post-install
Restarting Apache
httpd: Syntax error on line 665 of /private/etc/apache2/httpd.conf: Syntax error on line 8 of /etc/apache2/other/+php-osx.conf: Cannot load /usr/local/php5/libphp5.so into server: dlopen(/usr/local/php5/libphp5.so, 10): Symbol not found: _libiconv\n Referenced from: /usr/local/php5/lib/libintl.8.dylib\n Expected in: /usr/lib/libiconv.2.dylib\n in /usr/local/php5/lib/libintl.8.dylib
When I check the php version, it still says '5.3.28' :(
5. Someone save me
The exact same problem persists. I have no idea what's gone wrong or how to fix it. Any help would be super appreciated!
Running Mac Lion 10.7.5
OK. So MAMP then stopped working completely. But against all odds, I managed to fix it.
I followed this guide and reinstalled PHP 5.3:
http://benedmunds.com/php/2014/10/16/fixing-homebrew-php-apache-after-yosemite/
I got an error when I got to this line:
$ brew reinstall php53 --with-mysql --with-pgsql --with-apache
So I followed the beginning of this guide:
https://rtcamp.com/tutorials/mac/osx-brew-php-mysql-nginx/
Until I got to the install line tried it again to install 5.3:
brew search php
brew tap josegonzalez/php
brew tap homebrew/dupes
brew options php53
brew reinstall php53 --with-mysql --with-pgsql --with-apache
Took a little while, finished up. Restarted MAMP, and everything works again.
Phew.
Update
Had issues loading the MAMP start page too afterwards. Solved them by stopping OSX apache from running. It must have been taking over or something...
sudo apachectl stop