PHP FastCGI mode does not work: Premature end of script headers

Refers to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux
  • Plesk 11.0 for Linux
  • Plesk 11.5 for Linux
  • Plesk 12.0 for Linux

Created:

2016-11-16 13:18:18 UTC

Modified:

2017-02-18 13:04:01 UTC

1

Was this article helpful?


Have more questions?

Submit a request

PHP FastCGI mode does not work: Premature end of script headers

Symptoms

  1. A secondary PHP is not working while switching the PHP mode to FastCGI:

    # tailf /var/www/vhosts/domain.tld/logs/error_log

    (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
    Premature end of script headers: index.php

    OR

    [fcgid:warn] [pid 1175:tid 140298957072128] (104)Connection reset by peer: [client xx.xx.xx.xx:50320] mod_fcgid: error reading data from FastCGI server
    [core:error] [pid 1175:tid 140298957072128] [client xx.xx.xx.xx:50320] End of script output before headers: index.php
    [fcgid:warn] [pid 1174:tid 140298982250240] (104)Connection reset by peer: [client xx.xx.xx.xx:50324] mod_fcgid: error reading data from FastCG
  2. Apache logs show a memory error:

    # less /etc/httpd/logs/error_log

    Apache/2.2.15 (Unix) DAV/2 mod_fcgid/2.3.7 mod_python/3.3.1 Python/2.6.6 mod_ssl/2.2.15 OpenSSL/1.0.0-fips SVN/1.6.11 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
    [Errno 12] Cannot allocate memory
  3. Syslog shows suhosin alerts

    # less /var/log/syslog

    hosting suhosin[32242]: ALERT - zend_mm_head corrupted at 0x2e02420 (attacker '203.0.113.2', file '/var/www/vhosts/example.com/httpdocs/index.php')
  4. The Suexec log shows an error:

    # tailf /var/log/httpd/suexec_log

    uid: (10033/ftpuser) gid: (504/504) cmd: cgi_wrapper
    unknown error in docroot check (10033)

Cause

  1. PHP is not compiled with FastCGI.

  2. There is not enough memory on the server.

  3. The domain php.ini is customized, contains misprinted errors, or an invalid configuration.

  4. Permissions on the /etc/passwd file are incorrect.

  5. A problem with particular php module compatibility.

Resolution

  1. Make sure PHP is compiled with FastCGI. You can use the below command to check whether the fastcgi module is enabled or not.

    # /usr/local/psa/admin/bin/php_handlers_control --list
    id: display name: version: type: cgi-bin: php.ini:
    fastcgi-5.2.17 5.2.17 5.2.17 cgi /usr/local/php5.2.17/bin/php-cgi /usr/local/lib/php.ini

    Check the PHP version:

    # /usr/local/php5.2.17-cgi/bin/php-cgi -v
    PHP 5.2.17 (cgi) (built: Mar 27 2014 20:28:44)
    Copyright (c) 1997-2010 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

    As it shown, 5.2.17 (cgi) is used. This means that PHP works in CGI mode only. PHP that works in CGI and FastCGI modes looks as below:

    # php-cgi -v
    PHP 5.3.3 (cgi-fcgi) (built: Jul 12 2013 20:34:01)
    Copyright (c) 1997-2010 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd.

    If PHP is not compiled with FastCGI mode, please recompile the custom php with option --enable-fastcgi .

  2. Make sure there is enough memory on the server using the command:

    # free -m

    If the server is a virtual container, you can check resource limits with the command:

    # cat /proc/user_beancounters
  3. The domain php.ini may be customized manually or contain an error. For example: megabytes set in php.ini as 128MB instead of 128M.

    Back up the original domain php.ini and reconfigure a domain:

     # mv  /var/www/vhosts/system/domain.tld/etc/php.ini /var/www/vhosts/system/domain.tld/etc/php.ini_orig

    # /usr/local/psa/admin/bin/httpdmng --reconfigure-vhost --vhost-name=domain.tld

    For Plesk 11.5 and higher, use the following command:

     # /usr/local/psa/admin/bin/httpdmng --reconfigure-domain --domain-name=domain.tld
  4. Make sure that permissions for the /etc/passwd file looks as follow:

    # ls -la /etc/passwd
    -rw-r--r-- 1 root root 7643 Mar 3 12:54 /etc/passwd
Have more questions? Submit a request

8 Comments

  • 0
    Avatar
    Israel Diaz

    I am having problems with the server, I stay 2 years and not have problem I update to onyx and the problems begin.

    Give me error 500 more times!! I dont know what is the problem and where I have to find the log file.


    log of error_log

    [Mon Jan 23 03:38:07.927584 2017] [core:error] [pid 12287:tid 140401327412992] [client 163.172.65.215:33462] End of script output before headers: index.php
    [Mon Jan 23 03:39:03.762652 2017] [fcgid:warn] [pid 12287:tid 140401463781120] [client 37.113.130.68:56497] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 03:39:03.762711 2017] [core:error] [pid 12287:tid 140401463781120] [client 37.113.130.68:56497] End of script output before headers: index.php
    [Mon Jan 23 03:39:19.886691 2017] [fcgid:warn] [pid 12287:tid 140401274963712] [client 185.59.58.48:57381] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 03:39:19.886736 2017] [core:error] [pid 12287:tid 140401274963712] [client 185.59.58.48:57381] End of script output before headers: index.php
    [Mon Jan 23 03:39:51.790649 2017] [fcgid:warn] [pid 12285:tid 140401337902848] [client 180.76.15.160:19429] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 03:39:51.790706 2017] [core:error] [pid 12285:tid 140401337902848] [client 180.76.15.160:19429] End of script output before headers: index.php
    [Mon Jan 23 04:03:28.072585 2017] [fcgid:warn] [pid 12287:tid 140401432311552] [client 107.191.38.52:60282] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:03:28.072632 2017] [core:error] [pid 12287:tid 140401432311552] [client 107.191.38.52:60282] End of script output before headers: index.php
    [Mon Jan 23 04:04:09.499743 2017] [fcgid:warn] [pid 12287:tid 140401453291264] [client 95.141.233.82:60988] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:04:09.499804 2017] [core:error] [pid 12287:tid 140401453291264] [client 95.141.233.82:60988] End of script output before headers: index.php
    [Mon Jan 23 04:05:23.763649 2017] [fcgid:warn] [pid 12287:tid 140401243494144] [client 186.46.43.2:54368] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:05:23.763713 2017] [core:error] [pid 12287:tid 140401243494144] [client 186.46.43.2:54368] End of script output before headers: index.php
    [Mon Jan 23 04:06:58.361720 2017] [fcgid:warn] [pid 12285:tid 140401463781120] [client 178.34.110.122:57428] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:06:58.361768 2017] [core:error] [pid 12285:tid 140401463781120] [client 178.34.110.122:57428] End of script output before headers: index.php
    [Mon Jan 23 04:07:19.837826 2017] [fcgid:warn] [pid 12287:tid 140401411331840] [client 223.30.106.78:34447] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:07:19.837861 2017] [core:error] [pid 12287:tid 140401411331840] [client 223.30.106.78:34447] End of script output before headers: index.php
    [Mon Jan 23 04:07:56.667566 2017] [fcgid:warn] [pid 12287:tid 140401474270976] [client 212.58.194.154:51358] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:07:56.667606 2017] [core:error] [pid 12287:tid 140401474270976] [client 212.58.194.154:51358] End of script output before headers: index.php
    [Mon Jan 23 04:08:32.191520 2017] [fcgid:warn] [pid 12287:tid 140401555822336] [client 178.169.82.216:56097] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:08:32.191576 2017] [core:error] [pid 12287:tid 140401555822336] [client 178.169.82.216:56097] End of script output before headers: index.php
    [Mon Jan 23 04:08:51.703663 2017] [fcgid:warn] [pid 12287:tid 140401463781120] [client 40.77.167.49:16190] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:08:51.703710 2017] [core:error] [pid 12287:tid 140401463781120] [client 40.77.167.49:16190] End of script output before headers: index.php
    [Mon Jan 23 04:09:33.318919 2017] [fcgid:warn] [pid 12285:tid 140401243494144] [client 88.147.153.96:15693] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 04:09:33.318970 2017] [core:error] [pid 12285:tid 140401243494144] [client 88.147.153.96:15693] End of script output before headers: index.php
    [Mon Jan 23 05:02:37.634830 2017] [fcgid:warn] [pid 12287:tid 140401432311552] [client 31.181.136.1:2322] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 05:02:37.634875 2017] [core:error] [pid 12287:tid 140401432311552] [client 31.181.136.1:2322] End of script output before headers: index.php
    [Mon Jan 23 06:03:00.760693 2017] [fcgid:warn] [pid 12287:tid 140401411331840] [client 77.240.168.179:54333] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 06:03:00.760737 2017] [core:error] [pid 12287:tid 140401411331840] [client 77.240.168.179:54333] End of script output before headers: index.php
    [Mon Jan 23 06:03:20.061658 2017] [fcgid:warn] [pid 12287:tid 140401316923136] [client 90.188.6.161:55051] mod_fcgid: read data timeout in 45 seconds
    [Mon Jan 23 06:03:20.061700 2017] [core:error] [pid 12287:tid 140401316923136] [client 90.188.6.161:55051] End of script output before headers: index.php
    [Mon Jan 23 06:03:22.087656 2017] [fcgid:warn] [pid 12287:tid 140401474270976] [client 59.89.205.162:4962] mod_fcgid: read data timeout in 45 seconds

    I execute

    /usr/local/psa/admin/bin/php_handlers_control --list


    id: display name: version: type: cgi-bin: cli-bin: php.ini: system: service: pool.d:
    module 5.5.9 5.5.9 module /usr/bin/php5-cgi /usr/bin/php5 /etc/php5/apache2/php.ini *
    fastcgi 5.5.9 5.5.9 fastcgi /usr/bin/php5-cgi /usr/bin/php5 /etc/php5/cgi/php.ini *
    fpm 5.5.9 5.5.9 fpm /usr/sbin/php5-fpm /usr/bin/php5 /etc/php5/fpm/php.ini * php5-fpm /etc/php5/fpm/pool.d
    cgi 5.5.9 5.5.9 cgi /usr/bin/php5-cgi /usr/bin/php5 /etc/php5/cgi/php.ini *

    php-cgi -v

    PHP 5.5.9-1ubuntu4.20 (cgi-fcgi) (built: Oct 3 2016 13:02:14)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with the ionCube PHP Loader v4.6.0, Copyright (c) 2002-2014, by ionCube Ltd., and
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies


    free -m

    total used free shared buffers cached
    Mem: 8192 1702 6489 452 0 907
    -/+ buffers/cache: 795 7396
    Swap: 0 0 0


    cat /proc/user_beancounters

    Version: 2.5
    uid resource held maxheld barrier limit failcnt
    2427019: kmemsize 54264078 288714752 9223372036854775807 9223372036854775807 0
    lockedpages 1 16 2097152 2097152 0
    privvmpages 418339 1109565 9223372036854775807 9223372036854775807 0
    shmpages 99488 393716 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    numproc 189 294 9223372036854775807 9223372036854775807 0
    physpages 315925 649188 2097152 2097152 0
    vmguarpages 0 0 2097152 2097152 0
    oomguarpages 70369 189531 2097152 2097152 0
    numtcpsock 36 92 9223372036854775807 9223372036854775807 0
    numflock 9 35 9223372036854775807 9223372036854775807 0
    numpty 3 18 9223372036854775807 9223372036854775807 0
    numsiginfo 8 66 9223372036854775807 9223372036854775807 0
    tcpsndbuf 726072 26229616 9223372036854775807 9223372036854775807 0
    tcprcvbuf 589824 6379432 9223372036854775807 9223372036854775807 0
    othersockbuf 321368 1504528 9223372036854775807 9223372036854775807 0
    dgramrcvbuf 0 10304 9223372036854775807 9223372036854775807 0
    numothersock 192 320 9223372036854775807 9223372036854775807 0
    dcachesize 35299255 262991126 9223372036854775807 9223372036854775807 0
    numfile 3160 6230 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    numiptent 106 106 9223372036854775807 9223372036854775807 0

     

    but not resolve the problem

    Edited by Israel Diaz
  • 0
    Avatar
    Nikolay Zhmuk

    2 Israel

    1. Try to restart fpm process - service fpm restart.

    2. Try to change PHP handler for the domain.

    If above steps do not help, it would be more productive to investigate it in scope of a support ticket, which can be created by the link - https://www.plesk.com/contact-us/support/#content-body

  • 0
    Avatar
    Israel Diaz

    hello Nikolay.

    It is not only one web is all. I change to onyx versions and the problems begining. I restart all the day the vps..

    https://www.youtube.com/watch?v=C415Y_IIC7E

    I can not open a ticket because my license it is stratto servers

     

     

  • 0
    Avatar
    Vitaly Zhidkov

    @Israel, this case should be investigated on server. Please contact your hosting provider, in case our assistance will be needed they will raise a ticket for you

  • 0
    Avatar
    Israel Diaz

    Hello @Vitaly.

    I said at saturday at Stratto Server but clean his hands and say that are working good.

    I wrote to a forum of plesk

    https://talk.plesk.com/threads/i-update-to-onyx-and-the-problems-arrive.341269/

    But they say me that think that work good, but I see that the server are working and not working... This morning better than yesterday.

    But I have orphan domains, I have modules that I can not installed... and a domains than freeze and block include plesk.

    Thank you

     

  • 0
    Avatar
    Israel Diaz

    Vitaly good morning,

     

    Finally not resolve the problem, I call to stratto and not resolve the vps works very bad. I rent another server but when I put to migrate but not works also..

    Give me errors to migrate to a new server of plesk.

     

    Please open the ticket and revised. I rent another server to fix the problem because you say that it is hardware faliure,

  • 0
    Avatar
    Israel Diaz

  • 0
    Avatar
    Vitaly Zhidkov

    @Israel, check that file /etc/psa/psa.conf file exists and has correct ownership:

    # stat /etc/psa/psa.conf
    File: `/etc/psa/psa.conf'
    Size: 2462 Blocks: 8 IO Block: 4096 regular file
    Device: eec0b6f1h/4005607153d Inode: 547145 Links: 1
    Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

    And make sure that you run migration under root user.

Please sign in to leave a comment.