The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

FastCGI questions

Discussion in 'General Discussion' started by fearlsgroove, Jul 26, 2008.

  1. fearlsgroove

    fearlsgroove Member

    Joined:
    Jul 26, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I'm trying to setup FastCGI with apache 2.2 and php 5. It's on a VPS with only a few vhosts that will be running apps (drupal, etc) so I'm interested in performance gains of fcgi over cgi, however I don't want to deal with permissions and file ownership problems with mod_php.

    So I have 2 issues, first that every post re: cPanel and FCGI that I've seen indicates it will require some tweaking, but I can't find a shred of info on what kind of tweaking may need to be done. Can anyone point me somewhere useful that may give me some insight there?

    Second, one process that runs is an import that works basically like this: it performs a request that doesn't finish on the server until the import has finished. An ajax process periodically checks the status of the import. The problem is that the "parent" request is getting squished after 40 seconds and returns a 500 error. I presume this is due to a timeout issue with FCGI (mod_php or normal cgi doesn't exhibit this problem). Where exactly might I find FastCGI settings in the WHM/cPanel setup that might let me tweak this timeout?

    Thanks
     
  2. wizzy420

    wizzy420 Well-Known Member

    Joined:
    Nov 13, 2007
    Messages:
    125
    Likes Received:
    2
    Trophy Points:
    18
    In your apache configuration you need to set IPCCommTimeout to something higher than 40 seconds. No way to do it via WHM like a setting where you type something in above 40.

    Just use EasyApache to compile in Mod FCGID

    If you are looking at running Drupal you might want to look at buying your VPS from a company like - Removed - that specialize in drupal hosting, they can probably help you with stuff like this.

    W
     
    #2 wizzy420, Jul 27, 2008
    Last edited by a moderator: Sep 21, 2016
  3. fearlsgroove

    fearlsgroove Member

    Joined:
    Jul 26, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the help. I had gotten mod_fcgid up and running ok, but I was having a hard time finding out how to add settings for it, and where. One of my issues was that I was trying to use the FastCgiConfig directive, which doesn't seem to work in this setup. Adding individual directives did work.

    IPCCommTimeout did indeed fix the "40 second squish" issue. I'm placing settings in the php.conf file created by cpanel after an apache build, which means I guess I"ll have to re-add those every time I rebuild. Is there a way to modify the template for FCGI in cPanel? usually the comments at the top of cpanel conf files tell you what file to modify for the template, but for php.conf's case it just says "don't edit this manually or you'll lose your changes."
     
  4. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    If you add your settings to the Pre-VirtualHost include file, that should overload what is set in php.conf as it is loaded after php.conf. You can edit the Pre-VirtualHost include file within WHM. It is in Apache Setup.
     
  5. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
    My proposition to best php4 and php5 configurable Fastcgi:

    apache php.conf
    PHP:
    # Fastcgi configuration for PHP5
    LoadModule fcgid_module modules/mod_fcgid.so
    MaxRequestsPerProcess 500
    MaxProcessCount 1000
    DefaultMaxClassProcessCount 100
    IPCConnectTimeout 60
    IPCCommTimeout 60
    PHP_Fix_Pathinfo_Enable 1
    IdleTimeout 900
    IdleScanInterval 120
    BusyTimeout 300
    BusyScanInterval 120
    ErrorScanInterval 9
    ZombieScanInterval 9
    ProcessLifeTime 3600

    AddHandler fcgid
    -script .php5 .php .php3 .php2 .phtml
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php55 .php5
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php55 .php4
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php55 .php
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php55 .php3
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php55 .php2
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php55 .phtml



    AddHandler fcgid
    -script .php4
    FCGIWrapper 
    /usr/local/cpanel/cgi-sys/php44 .php4

    Go to /usr/local/cpanel/cgi-sys/

    vi php44

    PHP:
    #!/bin/sh
    exec ~/php/php44
    vi php55

    PHP:
    #!/bin/sh
    exec ~/php/php55
    chmod php44 and php55 chmod 755
    chown php44 and php55 chown root.wheel


    Go to user account


    Create in /home/user php catalog, /home/user/php


    PHP:
    #!/bin/sh
    export PHP_FCGI_CHILDREN=2
    export PHP_FCGI_MAX_REQUESTS
    =2000
    exec 
    /usr/local/cpanel/cgi-sys/php4 -~/php/php.ini

    vi php55

    PHP:
    #!/bin/sh
    export PHP_FCGI_CHILDREN=2
    export PHP_FCGI_MAX_REQUESTS
    =2000
    exec 
    /usr/local/cpanel/cgi-sys/php5 -~/php/php.ini

    chmod php44 and php55 chmod 755
    chown php44 and php55 chown user.user
    chattr +i php44 and php55
    cp /usr/local/lib/php.ini /home/user/php/php.ini
    chmod 644 php.ini
    chown user.user php.ini
    chattr +i php.ini (user cant edit php.ini to change example open_basedir)

    Restart apache


    Now you have to user option to change .php interpreter to example php4 or php5, if user want to php files execute with php4 go to /home/user/php/php55 and change exec /usr/local/cpanel/cgi-sys/php5 -c ~/php/php.ini to
    exec /usr/local/cpanel/cgi-sys/php4 -c ~/php/php.ini
    Thise user .php files will be executed by php4 :)

    Its only way to give users choice for Fastcgi to use php4 or php5 to handle .php files.


    Any security hole? I dont see :)
     
  6. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Europe
    Have you tried to use the above solution with suphp/suexec?

    I'm interested to use FastCGI but i'd like the php files to run as the user who owns/runs them.

    PS:
    how can the user add new extensions? for example .html files to act like php files, right now they use the following line in their .htaccess: AddHandler application/x-httpd-php .html
     
  7. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
    Yes it work with suexec (php work under user not apache user) :)

    I dont test new extensions i think that will be the problem :(
     
  8. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
    Only add to httpd.conf for that user to virtual host
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php55 .php5

    Will help...
     
  9. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Europe
    My problem is that our users use custom extensions and define them in .htaccess via AddHandler. Once we switch to FastCGI, all those sites will break.

    Have you tried eAccelerator and see if that works?
     
  10. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
  11. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
    OK i have super information, i know how to do thise:

    php.conf

    PHP:
    # Fastcgi configuration for PHP5
    LoadModule fcgid_module modules/mod_fcgid.so
    MaxRequestsPerProcess 500
    MaxProcessCount 1000
    DefaultMaxClassProcessCount 100
    IPCConnectTimeout 60
    IPCCommTimeout 60
    PHP_Fix_Pathinfo_Enable 1
    IdleTimeout 900
    IdleScanInterval 120
    BusyTimeout 300
    BusyScanInterval 120
    ErrorScanInterval 9
    ZombieScanInterval 9
    ProcessLifeTime 3600


    AddHandler php5
    -fastcgi .php
    Action php5
    -fastcgi /cgi-bin/php55
    Action php4
    -fastcgi /cgi-bin/php44

    AddType application
    /x-httpd-php .php



    and user must have in cgi-bin

    php55 (chattr +i)

    PHP:
    #!/bin/sh
    export PHP_FCGI_CHILDREN=1
    export PHP_FCGI_MAX_REQUESTS
    =10
    exec 
    /usr/local/cpanel/cgi-sys/php5

    Then you can add to .htaccess

    PHP:
    AddHandler php5-fastcgi .html
    Action php5
    -fastcgi /cgi-bin/php55
    And it work, if you upload to cgi-bin php.ini user will have own php.ini :)


    Propabbly is the best way :)


    I have only one problem how to all cgi-bin folders upload php55 (fcgi wrapper) i will write to cPanel how do add subdomain, new domain upload php55 wrapper to cgi-bin directory :)
     
  12. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Europe
    I don't quite understand your english, but i see what you are doing.

    I still don't understand how to implement this in a way that when WHM creates new accounts, to automatically install the required files into the users home dir.
     
  13. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
    Sory for my english :(

    [root]# vi /scripts/postwwwacct

    PHP:
    #!/usr/bin/perl
    my %OPTS = @ARGV;
    my $user $OPTS{'user'};
    system("cp /root/fastcgi/php44 /home/$OPTS{'user'}/public_html/cgi-bin/php44");
    system("cp /root/fastcgi/php55 /home/$OPTS{'user'}/public_html/cgi-bin/php55");
    system("chown $OPTS{'user'}.$OPTS{'user'} /home/$OPTS{'user'}/public_html/cgi-bin/*");

    But cPanel dont have any idea how to add thise cgi-bin scripts when user add domain, subdomain, you must write some shell script for that
     
  14. hekri

    hekri Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    149
    Likes Received:
    2
    Trophy Points:
    18
    OK when you install FastCGI or CGI (yes php as CGI also) it isnt possible to block users to edit own php.ini the if user want will delete open_basedir and disable_functions :(

    I think that someone who upload
    N3tShell
    c99shell
    r57shell

    can compromise my system or not, when edit php.ini and delete disable_functions and open_basedir???
     
  15. Jgnr

    Jgnr Member

    Joined:
    Oct 24, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I get these segfaults while running the above with Apache 2.2.10 MPM Worker and fastcgi. The server seems to function correctly not quite sure what is causing it.

    Code:
    root@s1 [~]# tail -f /var/log/messages
    Dec  8 22:27:47 s1 kernel: php5[526]: segfault at 000000000000000f rip 00002ab9044a4dec rsp 00007fffa6be2a50 error 4
    Dec  8 22:27:47 s1 kernel: php5[529]: segfault at 000000000000000f rip 00002ac3297d7dec rsp 00007fff818b1720 error 4
    Dec  8 22:27:47 s1 kernel: php5[530]: segfault at 000000000000000f rip 00002b492a3c2dec rsp 00007fff80cc4b30 error 4
    Dec  8 22:27:47 s1 kernel: php5[531]: segfault at 000000000000000f rip 00002aebc35c5dec rsp 00007fffe7ac3930 error 4
    strace -o output.txt /usr/local/cpanel/cgi-sys/php5

    Code:
    execve("/usr/local/cpanel/cgi-sys/php5", ["/usr/local/cpanel/cgi-sys/php5"], [/* 26 vars */]) = 0
    brk(0)                                  = 0x3a77000
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ac3aca3b000
    uname({sys="Linux", node="s1.jesusshare.com", ...}) = 0
    access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib/tls/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib/tls/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib/tls/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib/tls", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/opt/xml2/lib/tls/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/xml2/lib/tls/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/xml2/lib/tls/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/xml2/lib/tls", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/xml2/lib/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/xml2/lib/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/xml2/lib/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/xml2/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/opt/curl//lib64/tls/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib64/tls/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib64/tls/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib64/tls", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib64/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib64/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/curl//lib64", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/opt/php_with_imap_client//lib64/tls/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/php_with_imap_client//lib64/tls/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/php_with_imap_client//lib64/tls/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/php_with_imap_client//lib64/tls", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/php_with_imap_client//lib64/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/php_with_imap_client//lib64/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/opt/php_with_imap_client//lib64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/opt/php_with_imap_client//lib64", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/usr/lib64/tls/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/tls/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/tls/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/tls/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/tls/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/tls", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/usr/lib64/x86_64/libstdc++.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/x86_64", 0x7ffffe06acf0) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/libstdc++.so.6", O_RDONLY) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\364$]<\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0755, st_size=976312, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ac3aca3c000
    mmap(0x3c5d200000, 3145600, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3c5d200000
    mprotect(0x3c5d2e6000, 2093056, PROT_NONE) = 0
    mmap(0x3c5d4e5000, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe5000) = 0x3c5d4e5000
    mmap(0x3c5d4ee000, 73600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3c5d4ee000
    close(3)                                = 0
    open("/opt/curl//lib/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/opt/xml2/lib/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib64/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/opt/php_with_imap_client//lib64/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/tls/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/libcrypt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY)      = 3
    fstat(3, {st_mode=S_IFREG|0644, st_size=73406, ...}) = 0
    mmap(NULL, 73406, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2ac3aca3d000
    close(3)                                = 0
    open("/lib64/libcrypt.so.1", O_RDONLY)  = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\t\300\3518\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0755, st_size=48600, ...}) = 0
    mmap(0x38e9c00000, 2322880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x38e9c00000
    mprotect(0x38e9c09000, 2093056, PROT_NONE) = 0
    mmap(0x38e9e08000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8000) = 0x38e9e08000
    mmap(0x38e9e0a000, 184768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x38e9e0a000
    close(3)                                = 0
    open("/opt/curl//lib/libmysqlclient_r.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/opt/xml2/lib/libmysqlclient_r.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/opt/curl//lib64/libmysqlclient_r.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/opt/php_with_imap_client//lib64/libmysqlclient_r.so.15", O_RDONLY) = -1 ENOENT (No such file or directory)
     
    #15 Jgnr, Dec 8, 2008
    Last edited: Dec 8, 2008
Loading...

Share This Page