libvips / php-vips

php binding for libvips
MIT License
618 stars 25 forks source link

BigSur, Laravel Valet and php-vips - 502 Bad Gateway on error pages #119

Closed johnvoncolln closed 3 years ago

johnvoncolln commented 3 years ago

What a journey. I've finally narrowed this down, still not sure what it means or how to fix it.

OS: Mac OS 11.4 Environment: Laravel Valet PHP: 7.3, or 7.4

Basically once the environment is setup, if I add extension=vips.so to my php.ini file, there is some strange behavior. Vips works fine, but now any error pages show a 502 Bad Gateway error.

Not great for development.

Also, this is the nginx error if I purposely create an error in a php file to show error page:

2021/06/03 18:26:55 [error] 82029#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /help HTTP/1.1", upstream: "fastcgi://unix:/Users/john/.config/valet/valet.sock:", host: "mysite.test"

This error is not in direct relation to a vips action.

BUT I can remove extension=vips.so, restart and it works fine.

jcupitt commented 3 years ago

Huh that's really weird, I'm sorry you're having trouble.

It's not necessarily caused by vips.so (which does very little). Could enabling the extension have done something else to your server config? What if you enable other binary extensions?

johnvoncolln commented 3 years ago

Yeah it's very weird. I've installed and enabled a few other extensions and they all perform normally. Last night I increased the memory on php with no change.

I'm certain that it's more of a OS / Valet issue, but I'm not really sure what else to try. Any suggestions are welcome! If I have time today, I'll see if I can replicate on a different computer

alexander-schranz commented 3 years ago

I'm not using laravel valet but with symfony cli and nginx I got lately also a 502 Bad Gateway:

I could temporary fix it:

OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES symfony serve

This seems to be related to: https://github.com/libvips/php-vips-ext/issues/42

EDIT: Upgrading Vips did also fix it for me:

brew upgrade vips
brew services restart php
jcupitt commented 3 years ago

Yes, it sounds like this should be fixed by 8.11.3, the head of the 8.11 branch. We'll push it out in the nest week or so, or you can build from git.

jcupitt commented 3 years ago

This should now be fixed. Please open a new issue if you still have problems.

jonny77 commented 2 years ago

@johnvoncolln
@jcupitt Hi there, recently i met this issue also. when i install vips with pecl , i can not run curl request .
i tried laravel and other framework . my os is macos 12.2.1 (21D62) curl version : curl 7.77.0 (x86_64-apple-darwin21.0) libcurl/7.77.0 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.42.0 vips version: latest

jcupitt commented 2 years ago

Did you try the OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES fix? Please open a new issue if that doesn't work.

johnvoncolln commented 1 week ago

I want to add this here, because I just spent a day and a half pulling my hair out after my dev environment stopped working.

Here's what I've got:

Apple Silicon Mac Studio M1 Max Mac OS 14.3 Running Laravel Valet 4.8.0

PHP 8.3.13 Nginx 1.27.2 Vips 8.16.0 jcupitt/vips 2.4

I kept getting that basted 502 Gateway error on a simple vips call: Image::vips_call();

I tried everything; installing Herd, deleting and reinstalling everything valet related, etc. In the end, I found some notes from a year or two back that I wrote, not sure the source of this fix.

Locate the plist file in the php folder, in my case it's: /opt/homebrew/Cellar/php/8.3.13_1/homebrew.mxcl.php.plist and add this:

<key>EnvironmentVariables</key>
<dict>
    <key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key>
    <string>YES</string>
</dict>

so that your file resembles this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.php</string>
    <key>LimitLoadToSessionType</key>
    <array>
        <string>Aqua</string>
        <string>Background</string>
        <string>LoginWindow</string>
        <string>StandardIO</string>
        <string>System</string>
    </array>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/homebrew/opt/php/sbin/php-fpm</string>
        <string>--nodaemonize</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/opt/homebrew/var/log/php-fpm.log</string>
    <key>WorkingDirectory</key>
    <string>/opt/homebrew/var</string>
    <key>EnvironmentVariables</key>
  <dict>
    <key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key>
    <string>YES</string>
  </dict>
</dict>
</plist>

Do a valet restart command and it should work. Don't forget the other requirements for Vips installation... Hope this helps someone, or me in the future...