Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_pre.php on line 387

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 337

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 341

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 343
Individual php.ini files for PHP FCGI and PHP CGI - cPanel Forums


Results 1 to 13 of 13

Thread: Individual php.ini files for PHP FCGI and PHP CGI

  1. #1
    Registered Member Miraenda's Avatar
    Join Date
    Jul 2004
    Location
    Coralville, Iowa USA
    Posts
    243

    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 Member lanquest-it's Avatar
    Join Date
    Apr 2008
    Posts
    9

    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
    /http://forums.kayako.com/threads/sorry-fusion-cant-be-installed-checking-if-magic-quotes-gpc-is-disabled.23644/#post-124861 (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
    7,611
    cPanel/WHM 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, Technical Analyst III, Forums Specialist, 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?

  6. #6
    Registered Member
    Join Date
    Jun 2010
    Posts
    14

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

    Okay I followed this exactly to the tee and spend about 5 hours trying to understand why it would not WORK. I even put in a support ticket and Cpanel support could not figure it out either.

    So here are some CRITICAL STEPS MISSING from the above tutorial.

    First the ACCOUNT itself must be a NEW account and you MUST ENABLE CGI-ACCESS from the SETTINGS.

    If Cgi is not enabled in the account setup then you will get SUPHP and many other errors.

    Second - the permissions and group permissions must be PERFECT. The first account I tried this on I did from
    a backup from another server and it would not work. So if you

    1. Create a new account and choose ENABLE on CGI Privilege
    2. Make sure to +755 the pgp.fcgi
    3. Make sure your groups are OK

    Then it works 100% every time and ive messed this up for about 20 hours so I have fiddled with every possible variable.

    Its funny how 1 stupid setting can RUIN your whole day - even Cpanel support didn't think to check that stupid CGI permission in the account page. So before you kill yourself in frustration make sure its ON.

    Thanks to the support forums, we seem to solve more crap then staff sometimes!

  7. #7
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    7,611
    cPanel/WHM Access Level

    Root Administrator

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

    If you are changing something from the default settings, then you should try to note this in the ticket or on the server. Unchecking CGI on account creation is not something done very often. Since you are trying to create CGI-based files for the individual php.ini files to work for FCGI, then it's pretty important to note you've made that change to someone, I agree.
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Technical Analyst III, Forums Specialist, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  8. #8
    Registered Member
    Join Date
    Jun 2010
    Posts
    14

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

    Yes but when you make a packages you choose many options, OTHER then doing this process, you NEVER need cgi-access so enabling it is just an extra security risk you don't need. I ran a server for 3 years under FCGI never needing it. I would never think to go back and check something I set years ago in WHM. And though everyone bashed their heads for hours to fix it nobody thought of it. Supports recommendation was to abandon the idea and undo any changes. One of the things you do when you debug is backstep over all possible reasons things don't work, but because this one is not on the list, its very easy to overlook it. Its like a hidden kill switch buried way back, and unless someone warns you, you can suffer the same fate as me. If it wasn't for my refusal to let it go, and continued experiments on my own, I would have failed. I doubt you could think of a single other item that effects this OTHER then that lol. There is nothing, its the last piece. Also support has full WHM access which is what they ask for. And the errors that get thrown have nothing to do with CGI enabled. There is no nice warning - SORRY CGI DISABLED or anything remotely like that. Maybe its something you want to add to the next update, often when features are disabled the errors contain a hint.

  9. #9
    Registered Member
    Join Date
    Dec 2009
    Posts
    28

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

    Here's a simpler solution:

    Edit the file called /usr/local/cpanel/cgi-sys/php5 -- insert the line above exec /usr/bin/php as follows:

    Code:
    #!/bin/sh
    
    # If you customize the contents of this wrapper script, place
    # a copy at /var/cpanel/conf/apache/wrappers/php5
    # so that it will be reinstalled when Apache is updated or the
    # PHP handler configuration is changed
    
    [ -f ~/php.ini ] && exec /usr/bin/php -c ~/
    exec /usr/bin/php
    Copy the file over to /var/cpanel/conf/apache/wrappers/php5 as indicated at the top of the file.

    Now, if any account has a php.ini file in their home directory (not public_html) then it will be used instead of the system-provided one.

  10. #10
    Registered User
    Join Date
    May 2013
    Posts
    1
    cPanel/WHM Access Level

    Root Administrator

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

    Hi Tylerl,

    Thank you for your solution...
    If I can find the var/cpanel/conf/apache/ I do not have /wraappers/ do I have to create it?? and put the php5 file inside this folder?

    Is that the line we have to add in the file ?
    "
    [ -f ~/php.ini ] && exec /usr/bin/php -c ~/
    "
    Thank you

    Frank

  11. #11
    Registered Member
    Join Date
    Feb 2003
    Posts
    189

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

    Quote Originally Posted by tylerl View Post
    Here's a simpler solution:

    Edit the file called /usr/local/cpanel/cgi-sys/php5 -- insert the line above exec /usr/bin/php as follows:

    Code:
    #!/bin/sh
    
    # If you customize the contents of this wrapper script, place
    # a copy at /var/cpanel/conf/apache/wrappers/php5
    # so that it will be reinstalled when Apache is updated or the
    # PHP handler configuration is changed
    
    [ -f ~/php.ini ] && exec /usr/bin/php -c ~/
    exec /usr/bin/php
    Copy the file over to /var/cpanel/conf/apache/wrappers/php5 as indicated at the top of the file.

    Now, if any account has a php.ini file in their home directory (not public_html) then it will be used instead of the system-provided one.

    Does this work with FCGI?

  12. #12
    Registered User
    Join Date
    Nov 2009
    Posts
    3

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

    Yes, it does work with FCGI. Just tried it, and it's a much simpler solution indeed
    Where with the original solution I was getting 500 Internal Server error on all php pages.

  13. #13
    Registered User
    Join Date
    Oct 2011
    Posts
    1
    cPanel/WHM Access Level

    Website Owner

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

    If you don't have a wrappers directory or php5 file just create them. The file doesn't have an extension php5 not php.txt .htm .bin etc just php

Similar Threads

  1. Individual/Custom PHP Configuration on FCGI Server
    By vectro in forum General Discussion
    Replies: 2
    Last Post: 12-14-2012, 07:40 PM
  2. custom php.ini with php handler set as cgi
    By johny_gjx in forum General Discussion
    Replies: 0
    Last Post: 02-16-2009, 03:54 AM
  3. Replies: 0
    Last Post: 10-01-2008, 10:58 AM
  4. php.ini per dir with php running as cgi
    By vesko in forum General Discussion
    Replies: 3
    Last Post: 04-18-2008, 08:39 AM
  5. php5(cgi) ignoring php.ini files in user dirs
    By panayot in forum General Discussion
    Replies: 1
    Last Post: 06-09-2006, 02:21 PM
bargain