Learn about Centmin Mod LEMP Stack today
Register Now

PHP-FPM 502 Bad Gateway

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Roman Kh, Mar 29, 2017.

  1. Roman Kh

    Roman Kh New Member

    11
    2
    3
    Mar 29, 2017
    Ratings:
    +2
    Local Time:
    9:16 PM
    1.11.12
    10.1.22
    This morning I'm getting 502 Bad Gateway on my server.
    My Setup:

    CentOS Version: CentOS 7 64bit ?
    Centmin Mod Version Installed: 123.09beta01
    Nginx Version Installed: i.e. 1.11.12
    PHP Version Installed: 7.0.15
    MariaDB MySQL Version Installed: 10.1.22
    When was last time updated Centmin Mod code base ? : today

    NGINX log:
    Code:
    [error] 1052#1052: *5 connect() failed (111: Connection refused) while connecting to upstream, client: ***.87.161.***, server: *****.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.*****.com"
    Tried to restart PHP-fmp:
    Code:
    # bash -x /etc/init.d/php-fpm restart
    + '[' -f /proc/user_beancounters ']'
    + '[' '!' -d /var/run/php-fpm ']'
    + prefix=/usr/local
    + exec_prefix=/usr/local
    + php_fpm_BIN=/usr/local/sbin/php-fpm
    + php_fpm_CONF=/usr/local/etc/php-fpm.conf
    + php_fpm_PID=/var/run/php-fpm/php-fpm.pid
    + php_opts='--fpm-config /usr/local/etc/php-fpm.conf'
    ++ cat /var/run/php-fpm/php-fpm.pid
    + kill -0
    + running=1
    + case "$1" in
    + /etc/init.d/php-fpm stop
    Gracefully shutting down php-fpm kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
    ................................... failed. Use force-exit
    + /etc/init.d/php-fpm start
    Starting php-fpm /etc/init.d/php-fpm: line 76:  3526 Illegal instruction     $php_fpm_BIN $php_opts
     failed
    I'm not running multiple pools.
    Any suggestions?
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    4:16 AM
    Nginx 1.13.x
    MariaDB 5.5

    I ask as the illegal instruction error is a clue as similar to https://community.centminmod.com/posts/45122/ and https://community.centminmod.com/posts/23675/
    Code (Text):
    Starting php-fpm /etc/init.d/php-fpm: line 76:  3526 Illegal instruction     $php_fpm_BIN $php_opts
     failed
    

    It's when you use betainstaller-latest.sh (which enables GCCINTEL_PHP='y') or manually enable GCCINTEL_PHP='y' in /etc/centminmod/custom_config.inc as GCCINTEL_PHP='y' enables GCC intel optimised compile options for PHP install but this could cause problems on very very old Intel cpus and I thought I accounted for them all with fix at https://community.centminmod.com/threads/update-inc-php_configure-inc.5596/. Edit: okay i actually made GCCINTEL_PHP='y' the default in 123.09beta01 now so that might explain it. Will confirm when i find out your /proc/cpuinfo output from above cat command.

    If you do have in enabled GCCINTEL_PHP='y' in /etc/centminmod/custom_config.inc, you can disable it via removing entry or setting it to GCCINTEL_PHP='n', then re-run centmin.sh menu option 5 and upgrade to PHP 7.0.17 which is latest and that should disable the Intel optimised GCC compiler options.
     
    Last edited: Mar 29, 2017
  3. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    4:16 AM
    Nginx 1.13.x
    MariaDB 5.5
    that could be a separate issue altogether

    If on Centmin Mod 123.09beta01, you may have ran into the new tools/autoprotect.sh cronjob feature outlined at Beta Branch - autoprotect.sh - apache .htaccess check & migration to nginx deny all | Centmin Mod Community You uploaded scripts may have .htaccess deny from all type files in their directories which may need bypassing autoprotect. It's a security feature that no other nginx based stack has as far as I know :)

    So instead, all .htaccess 'deny from all' detected directories now get auto generated Nginx equivalent location match and deny all setups except if you want to manually bypass the directory from auto protection via a .autoprotect-bypass file - details below here.

    You can read a few threads below on how autoprotect.sh may have caught some folks web apps falsely and the workarounds or improvements made to autoprotect.sh with the help of users feedback and troubleshooting.
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    4:16 AM
    Nginx 1.13.x
    MariaDB 5.5
    i actually set GCCINTEL_PHP to default to enable now, so to disable create persistent config file at /etc/centminmod/custom_config.inc and set in it
    Code (Text):
    GCCINTEL_PHP='n'
    

    then recompile php via centmin.sh menu option 5 for PHP 7.0.17
     
  5. Roman Kh

    Roman Kh New Member

    11
    2
    3
    Mar 29, 2017
    Ratings:
    +2
    Local Time:
    9:16 PM
    1.11.12
    10.1.22
    I had this server running from September with PHP 7 and centminmod
    one liner install for centminmod
    I honestly don't recall if I installed php5 and then upgraded to php7 or I installed php7 from the beginning

    CPU:
    Code:
    # cat /proc/cpuinfo
    processor       : 0
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 42
    model name      : Intel Xeon E312xx (Sandy Bridge)
    stepping        : 1
    microcode       : 0x1
    cpu MHz         : 2399.998
    cache size      : 4096 KB
    physical id     : 0
    siblings        : 1
    core id         : 0
    cpu cores       : 1
    apicid          : 0
    initial apicid  : 0
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 13
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov                         pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc                         rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcn                        t tsc_deadline_timer aes xsave avx hypervisor lahf_lm xsaveopt
    bogomips        : 4799.99
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 46 bits physical, 48 bits virtual
    power management:
    
    processor       : 1
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 42
    model name      : Intel Xeon E312xx (Sandy Bridge)
    stepping        : 1
    microcode       : 0x1
    cpu MHz         : 2399.998
    cache size      : 4096 KB
    physical id     : 1
    siblings        : 1
    core id         : 0
    cpu cores       : 1
    apicid          : 1
    initial apicid  : 1
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 13
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov                         pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc                         rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcn                        t tsc_deadline_timer aes xsave avx hypervisor lahf_lm xsaveopt
    bogomips        : 4799.99
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 46 bits physical, 48 bits virtual
    power management:
    
    I can be wrong but I think this is related issues.
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    4:16 AM
    Nginx 1.13.x
    MariaDB 5.5
    ah then could be a different reason then. Since you had it installed for that long, make sure to update Centmin Mod 123.09beta01 branch code via centmin.sh menu option 23 submenu option 2 to be on latest code before just trying centmin.sh menu option 5 to update to PHP 7.0.17 as that is latest and had bug fixes since 7.0.16 https://community.centminmod.com/threads/php-7-0-16-is-available.10462/ and 7.0.17 https://community.centminmod.com/threads/php-7-0-17-is-available.10778/

    Upgrading Centmin Mod Code to Latest Version



    Getting Started Guide step 19 outlines also how to keep Centmin Mod code updated or how to switch version branches.

    Centmin Mod LEMP stack's script code is constantly updated for improvements, bug fixes and security fixes so keeping the Centmin Mod code up to date is important. With Centmin Mod 1.2.3-eva2000.08) (123.08stable) and higher releases, a newly added centmin.sh menu option 23 allows much easier code updates and version branch swicthing via Git backed environment you can setup. For full details read the following links:
    Upgrading Centmin Mod involves 2 parts.
    1. Upgrading the actual Centmin Mod code outlined at Upgrade Centmin Mod. This is heart of Centmin Mod where the code is the engine that runs centmin.sh shell based menu and all the automation you're accustomed to. You can easily update within a Centmin Mod version branch or switch version branches via centmin.sh menu option 23 outlined here.
    2. Upgrade software that Centmin Mod installed or manages. For this part following outline at How to upgrade Centmin Mod software installed on your server.
     
  7. Roman Kh

    Roman Kh New Member

    11
    2
    3
    Mar 29, 2017
    Ratings:
    +2
    Local Time:
    9:16 PM
    1.11.12
    10.1.22
    Once I updated to Centmin Mod 123.09beta01 and PHP 7.0.17 all problems are gone.
    Appreciate your help George!
     
    • Like Like x 1
  8. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    4:16 AM
    Nginx 1.13.x
    MariaDB 5.5
    ah you may ran into PHP 7.0.15 bugs :)