502 Bad Gateway nginx php7 fpm

54,356

Solution 1

It is likely that an older libpcre3 is installed and satisfies the dependency in the php7.0 package, but only the newer library package provides pcre_jit_stack_free.

If this is the case, do an apt-get install libpcre3, and you’re good to go.

Ref.: https://github.com/oerdnj/deb.sury.org/issues/372

Solution 2

Try to check your nginx's www.conf file and make sure the socket path is correct and socket file is present at that location while these services are running.

ie, /var/run/php/php7.0-fpm.sock or

/dev/shm/php-fpm-www.sock

try to start php-fpm from init.d

/etc/init.d/php-7.0.0-fpm start

and check your php.ini file also

add the following to the end of the file

[apc]
apc.write_lock = 1
apc.slam_defense = 0

Solution 3

I'd literally been fighting this for days, when I found the solution. It was a typo in /etc/nginx/sites-available/www (copied originally from ...sites-available/default and modified).

I'd overlooked this in both the file itself and the /var/log/nginx/error.log --even though the error log was clear

connect to unix: /var/run/php/php7.0-fpm-sock failed (2: No such file or directory)

The connection line should have read unix: /var/run/php/php7.0-fpm.sock.

Duh.

Share:
54,356

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I tried to install nginx and PHP7 with fpm using this tutorail https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04

    When i try to access any php file I get 502 Bad Gateway and when I try to restart php7.0-fpm I get this:

    sudo service php7.0-fpm restart
    stop: Unknown instance: 
    php7.0-fpm start/running, process 5379
    

    My nginx config:

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    

    My server is Ubuntu Server 14.04

    • Thomas Ward
      Thomas Ward almost 8 years
      Check the /etc/php7.0/fpm/pool.d/www.conf configuration file and verify that the run path you think PHP is listening on is actually where it listens. Once PHP is started and running, do you clear your cache on your browser and try and access the PHP again? Do you see any errors in /var/log/nginx/error.log?
    • Admin
      Admin almost 8 years
      2016/06/18 19:00:02 [crit] 5601#0: *6 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 109.236.47.141, server: kida.al, request: "GET /i.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "kida.al"
    • Thomas Ward
      Thomas Ward almost 8 years
      My apologies I mistyped the directory path. Check /etc/php/7.0/fpm/pool.d/www.conf. What does the entry for the listen = item say?
    • Admin
      Admin almost 8 years
      listen = /run/php/php7.0-fpm.sock
  • kotsos
    kotsos almost 8 years
    /var/run/php and /dev/shm/ are empty. /etc/init.d/php-7.0.0-fpm: No such file or directory
  • kotsos
    kotsos almost 8 years
    You can make sure php is running by applying the command for checking the version php -v. if php and nginx are alive, then try to find out the php-fpm sock file location.
  • kotsos
    kotsos almost 8 years
    I get this error when i run php -v: php: symbol lookup error: php: undefined symbol: pcre_jit_stack_free
  • Zanna
    Zanna almost 7 years
    what did it say before you corrected it?
  • InsOp
    InsOp over 6 years
    he replaced a dash with a dot