Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member Miraenda's Avatar
    Join Date
    Jul 2004
    Location
    Coralville, Iowa USA
    Posts
    244

    Default Individual php.ini files for PHP FCGI and PHP CGI

    Since I figured these might be helpful to people running either FCGI or CGI handlers on PHP, I'm going to post my guides that I have on my own forum here. If this is in the wrong spot for such guides, please feel free to move them. I hope these will be helpful

    PHP FCGI Individual php.ini File

    The following steps will allow a custom php.ini file on an account when using FCGI as the PHP handler.

    Copy and Edit default php.ini

    Code:
    cd /home/user/public-html/cgi-bin
    cp /usr/local/lib/php.ini /home/user/public_html/cgi-bin
    vi php.ini
    As a test change one of the variables like register_globals from:

    Code:
    register_globals = Off
    To:

    Code:
    register_globals = On
    If yours was On, then do the reverse. This is simply to test it changes from the global php.ini file.

    Create php.fcgi file to load custom php.ini

    Code:
    vi php.fcgi
    Please note that you should still be in /home/user/public_html/cgi-bin location.

    Put into file:

    Code:
    #!/bin/sh
    export PHP_FCGI_CHILDREN=1
    export PHP_FCGI_MAX_REQUESTS=10
    exec /usr/local/cpanel/cgi-sys/php5
    Please note the path to php5 is due to using PHP5 on this system. If you are using php4, it might be /usr/local/cpanel/cgi-sys/php4 or some other path. Check /etc/httpd/conf/php.conf to see what it shows for cgi-sys path for your version of PHP.

    Save file, then made executable:

    Code:
    chmod +x /home/user/public_html/cgi-bin/php.fcgi
    Change ownership of files to correct user:

    Code:
    chown -R user:user /home/user/public_html/cgi-bin/
    Edit .htaccess to point to php.fcgi wrapper

    Code:
    cd /home/user/public_html
    vi .htaccess
    Put at top of file:

    Code:
    AddHandler php5-fastcgi .php
    Action php5-fastcgi /cgi-bin/php.fcgi
    Again, here php5 is listed.

    Add paths to php.conf file

    Add the following lines to /usr/local/apache/conf/php.conf file:

    Code:
    Action php5-fastcgi /cgi-bin/php.fcgi
    AddType application/x-httpd-php .php
    Yours will probably look similar to the following after those lines are added:

    Code:
    # Fastcgi configuration for PHP5
    LoadModule fcgid_module modules/mod_fcgid.so
    MaxRequestsPerProcess 500
    AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
    Action php5-fastcgi /cgi-bin/php.fcgi
    AddType application/x-httpd-php .php
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php5
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php4
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php3
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php2
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .phtml
    Distill and rebuild Apache, then restart Apache

    Run these commands:

    Code:
    /usr/local/cpanel/bin/apache_conf_distiller --update
    /scripts/rebuildhttpdconf
    /etc/init.d/httpd restart
    Load phpinfo page on account

    Code:
    cd /home/user/public_html
    vi php.php
    In file put:

    Code:
    <?php
    phpinfo();
    ?>
    Change ownership to the user:

    Code:
    chown user:user php.php
    Load the file at http://domain.com/php.php to see the results.

    Your phpinfo file should now show register_globals changed as well as have this at the top defining the new php.ini path:

    Code:
    Loaded Configuration File /home/user/public_html/cgi-bin/php.ini
    -----
    PHP CGI Individual php.ini File

    The following steps will allow a custom php.ini file on an account when using CGI as the PHP handler.

    Copy and Edit default php.ini

    Code:
    cd /home/user/public-html/cgi-bin
    cp /usr/local/lib/php.ini /home/user/public_html/cgi-bin
    vi php.ini
    As a test change one of the variables like register_globals from:

    Code:
    register_globals = Off
    To:

    Code:
    register_globals = On
    If yours was On, then do the reverse. This is simply to test it changes from the global php.ini file.

    Create php.cgi file to load custom php.ini

    Code:
    vi php.cgi
    Please note that you should still be in /home/user/public_html/cgi-bin location.

    Put into file:

    Code:
    #!/bin/sh
    /usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/
    Please note the path to php5 is due to using PHP5 on this system. If you are using php4, it might be /usr/local/cpanel/cgi-sys/php4 or some other path. Check /etc/httpd/conf/php.conf to see what it shows for cgi-sys path for your version of PHP.

    Save file, then made executable:

    Code:
    chmod +x /home/user/public_html/cgi-bin/php.cgi
    Change ownership of files to correct user:

    Code:
    chown -R user:user /home/user/public_html/cgi-bin/
    Edit .htaccess to point to php.cgi wrapper

    Code:
    cd /home/user/public_html
    vi .htaccess
    Put at top of file:

    Code:
    Action application/x-httpd-php5 /cgi-bin/php.cgi
    Again, here php5 is listed. If your PHP is different, use the Action listed for your version of PHP in /etc/httpd/conf/php.conf file.

    Load phpinfo page on account

    Code:
    cd /home/admin/public_html
    vi php.php
    In file put:

    Code:
    <?php
    phpinfo();
    ?>
    Change ownership to the user:

    Code:
    chown user:user php.php
    Load the file at http://domain.com/php.php to see the results.

    Your phpinfo file should now show register_globals changed as well as have this at the top defining the new php.ini path:

    Code:
    Loaded Configuration File /home/user/public_html/cgi-bin/php.ini

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Thumbs down Re: Individual php.ini files for PHP FCGI and PHP CGI

    Almost a year on and I cannot believe this is still an issue when installing or upgrading this product.

    I've just posted a link to this workaround here Sorry! Fusion can't be installed - Checking if magic quotes GPC is disabled | Kayako Community Forums

    With PHP 5 evolving, why are we still going through this pain?.

  3. #3
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Individual php.ini files for PHP FCGI and PHP CGI

    I don't understand the request being made. Kayako isn't a cPanel product, so if this concerns Kayako and what it requires, then this would need to be taken up with their support system. Likewise the fact CGI and FCGI do not default allow individual php.ini files would not be the fault of cPanel itself, but the very essence of how these PHP handlers work. Any system using CGI or FCGI PHP handlers (not just cPanel) will have to configure individual php.ini files in a similar manner. Now, the options I provided to enable individual php.ini files under CGI or FCGI do work provided the hosting provider hasn't restricted them from being used.

    There are many hosts who use suPHP, which has a more lax system for allowing individual php.ini files, so you could certainly try to find a server using suPHP instead.

    Also, of note, when I say "I provided" above, this thread was originally made using my non-staff account at the time, so I was the original poster (to avoid any confusion).
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    1

    Default Re: Individual php.ini files for PHP FCGI and PHP CGI

    Thanks for the guide. Very helpful. One thing worth mentioning... if you have suExec enabled it's particular about the permissions of the cgi-bin directory and scripts. Do a chmod -R 755 cgi-bin. If you get a 500 error like I did, check your permissions, and remember to check your logs too.

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    3

    Default Re: Individual php.ini files for PHP FCGI and PHP CGI

    Great artcile, contratz.

    You know what would be great? A guide discribing how to make cpanel create these files automatically when a New Account or Subdomain was created in CPanel. This will avoid problems like this:

    Not Found

    The requested URL /cgi-bin/php.fcgi/foo.php was not found on this server.
    This error is generated because I created New Account and not created the specified fastcgi files.

    Where I can find a way to make the creation of php.fcgi/php.ini into user's cgi-bin directory automated?

Similar Threads & Tags
Similar threads

  1. custom php.ini with php handler set as cgi
    By johny_gjx in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 02-16-2009, 03:54 AM
  2. Question about PHP security, setting up multiple php.ini files?
    By sirbrent in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 10-01-2008, 10:58 AM
  3. php.ini per dir with php running as cgi
    By vesko in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 04-18-2008, 08:39 AM
  4. howto parse php in .html files fcgi
    By mtech-hosting in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 09-16-2007, 11:58 AM
  5. php5(cgi) ignoring php.ini files in user dirs
    By panayot in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-09-2006, 02:21 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube