1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fastcgi (Fcgid) and php.ini per user

Discussion in 'General Discussion' started by speckados, Nov 29, 2008.

  1. speckados

    speckados Member

    Joined:
    May 21, 2003
    Messages:
    254
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Acequias :: Granada :: España
    Hello.

    The issue of implementing a user php.ini by using FastCGI (Fcgid) in this Cpanel me back a little bit crazy.

    The question is that following the manual and the post is in these forums, not that it is applied using a php.ini per user.

    According manual y use /usr/local/apache/conf/userdata/std/2/<user>/<domain>/*.conf and this work because if put any directive for managed php values, fails reload apache. Also Apache read config file put in this folder.

    Weel, on this folder i put a file named php.conf with several test. On last according FCgid, put
    DefaultInitEnv PHPRC=/home/censo/php

    Nothing.

    Imposible for me that apache read php.ini on user home.


    Any ideas?
     
  2. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    Running fcgid on one of our servers to test it out. So far it has significantly lowered the load on the machine but we're unable to use custom php.ini 's.

    Is there anyone who know's how to use custom php.ini's with fcgid, eaccelerator? We've tried both using a wrapper (even if fcgid is running as the default php option) and using php.ini in each folder where php executes. Nothing seems to be helping.

    Anyone?
     
  3. mikesta

    mikesta New Member

    Joined:
    Oct 30, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Hi, I just tried a few modifications for fcgi as apache handler and thereby I found something that might be interesting for you.

    For giving every account its own php.ini, I made the following.

    1. Make a backup of your files

    2. Within the accounts public_html folder put a .htaccess file with the following lines in it:
    PHP:
    AddHandler php5-fastcgi .html
    Action php5
    -fastcgi /cgi-bin/php5.fcgi 
    3. Move to the cgi-bin folder within your accounts public_html folder and add two files.

    --First one is the copy of your php.ini with your modifications

    --The second file name php5.fcgi and add the following lines in it:

    PHP:
    #!/bin/sh
    export PHP_FCGI_CHILDREN=1
    export PHP_FCGI_MAX_REQUESTS
    =10
    exec 
    /usr/local/cpanel/cgi-sys/php5
    4.Go to usr/local/apache/conf/php.conf and put the following lines in that file:

    PHP:
    # This file was automatically generated by the Cpanel PHP Configuration system
    # If you wish to change the way PHP is being handled by Apache on your system,
    # use the /usr/local/cpanel/bin/rebuild_phpconf script or the WHM interface.
    #
    # Manual edits of this file will be lost when Apache is updated.

    # This file was automatically generated by the Cpanel PHP Configuration system
    # If you wish to change the way PHP is being handled by Apache on your system,
    # use the /usr/local/cpanel/bin/rebuild_phpconf script or the WHM interface.
    #
    # Manual edits of this file will be lost when Apache is updated.
     
    # 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/php5.fcgi
    AddType application
    /x-httpd-php .php
     
    # End of autogenerated PHP configuration.
    So thats it and works fine for me. All you have to do is to add that files to all you accounts to make it work.

    Also be careful of the chmod you are giving to the php.ini for example. Depending if you wish to make your customers able to change it or if you just want to be the only one to administrate it.

    Only be careful, if you recompile or update your apache, the php.conf file will be overwritten and you have to rework it.

    Hope it helps.
     
    #3 mikesta, Jan 28, 2009
    Last edited: Jan 28, 2009
  4. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    Thanks Mikesta, gonna have a go at it now.
    You can probably add those changes to:

    /usr/local/apache/conf/includes/pre_virtualhost_global.conf

    to keep them between easyapache updates. So leave the default info in php.conf and add your other stuff in that file.

    I'll get back to you with my results ;)
     
  5. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    Made a few changes:

    2.
    Code:
    AddHandler php5-fastcgi .php
    Action php5-fastcgi /cgi-bin/php5.fcgi  
    I didnt want my .html files to be treated like php.

    4. Left php.conf as it was default and added:

    Code:
    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
    to /usr/local/apache/conf/includes/pre_virtualhost_global.conf and restarted apache.

    This makes it possible for users to choose through .htaccess if they want to use custom php.ini or not instead of enforcing it on them.

    Have one issue though. Custom php.ini with eaccelerator enabled in it will result in core dumps. Any idea why this happens?
     
  6. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    Found my old thread. The core dumps were because of mpm-worker being multithreaded and eaccelerator not. Switched to prefork instead for now - might switch back to worker later and use APC as an accelerator instead. (Magento got hooks for APC etc)
     
  7. mhodge

    mhodge New Member

    Joined:
    Apr 14, 2005
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    mikesta and internetfab. Thanks for this, it helped a lot.
     
  8. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    Just a heads up - easyapache comments out

    Code:
    AddHandler php5-fastcgi .php
    from .htaccess when it's done upgrading. Just noticed this a week ago and haven't had the time to play around with it (well, except using find and replace..).

    If anyone know a workaround to this "feature" let me know.
     
  9. onknown

    onknown New Member

    Joined:
    Feb 1, 2008
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine




    php works as suPHP on my server, but I need to enable fcgi-php handler for one account. Can I use this guide? I can't find /usr/local/cpanel/cgi-sys/php5 file, please help......
     
  10. momon

    momon New Member

    Joined:
    Jun 22, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I hope someone is still following this thread. I've been trying to figure this out for a few days now without success.

    I am running php5 with fastcgi, following this guide and using its configuration I am running in a problem when inserting the changes in my .htaccess.

    Code:
    AddHandler php5-fastcgi .php
    Action php5-fastcgi /home/usrname/public_html/cgi-bin/php5.fcgi
    Everytime I enter the changes, the website where I am testing this returns a 500 error.

    I've been reading over the logs and googling without success of what could be the issue.

    The error_log reports these entries when I get the 500 errors are:

    Code:
    [Tue Jun 22 04:11:43 2010] [warn] [client 190.166.162.190] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
    [Tue Jun 22 04:11:43 2010] [warn] [client 190.166.162.190] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request function

    Note in the path:
    Action php5-fastcgi /home/usrname/public_html/cgi-bin/php5.fcgi

    I am using the full path to the file, if I do not use the full path, then I get this error:

    Code:
    Not Found
    
    The requested URL /cgi-bin/php5.fcgi/index.php was not found on this server.
    
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    I hope someone is still looking at this and is able to provide some orientation.
     
  11. gfxpixeldesigns

    gfxpixeldesigns New Member

    Joined:
    Jul 14, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Exactly the same problem here. Did you figure it out at all ?
     
  12. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    By request I'm posting an internal bash script we have used to be able to have per virtual host php.ini.
    Be adviced, script is provided as-it-is so use at your own risk.

    https://www.oderland.se/clients/downloads/5/Scripts

    Useage:
    Put the php5.fcgi file in the cgi-bin folder of the domain / addondomain.
    If there is no cgi-bin folder, make sure you create one.
    Place the php.ini file you want to be used there as well.

    Unpack the setup_fcgid.sh file into /root or any other folder and run it.
    ./setup_fcgid.sh

    Insert customer's username.
    Select All or One virtual host.

    If All, make sure you put the php5.fcgi in all of the virtual hosts cgi-bin folders (or made symbolic links).

    If One, insert the virtual host. Be aware that for addon domains, the virtual host is the subdomain associated with it, like: subdomain.maindomain.

    You might need to restart Apache to reload the current php processes or at least kill them for the user.

    Good luck, post here if there are any questions.
    (awaiting php-fpm here..)
     
  13. ponch9

    ponch9 New Member

    Joined:
    Aug 16, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Getting an error:

    Code:
    -bash-3.2$ ./setup_fcgid.sh
    Insert username : domain-user
    You chose: domain-user Is that Correct? [Y/N]:Y
    Set Wrapper for ALL of user's virtual hosts or for One [A/1] : 1
    You chose: 1
    
    Insert domain : my-domain.com
    You chose: my-domain.com Is that Correct? [Y/N]:Y
    mkdir: cannot create directory `/usr/local/apache/conf/userdata/ssl/2/domain-user': Permission denied
    ./setup_fcgid.sh: line 47: /usr/local/apache/conf/userdata/ssl/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    ./setup_fcgid.sh: line 48: /usr/local/apache/conf/userdata/ssl/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    ./setup_fcgid.sh: line 49: /usr/local/apache/conf/userdata/ssl/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    ./setup_fcgid.sh: line 50: /usr/local/apache/conf/userdata/ssl/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    mkdir: cannot create directory `/usr/local/apache/conf/userdata/std/2/domain-user': Permission denied
    ./setup_fcgid.sh: line 53: /usr/local/apache/conf/userdata/std/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    ./setup_fcgid.sh: line 54: /usr/local/apache/conf/userdata/std/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    ./setup_fcgid.sh: line 55: /usr/local/apache/conf/userdata/std/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    ./setup_fcgid.sh: line 56: /usr/local/apache/conf/userdata/std/2/domain-user/my-domain.com/fcgid.conf: No such file or directory
    touch: cannot touch `/usr/local/apache/conf/_ensure_vhost_includes_vhostless_test_file.conf': Permission denied
    touch: cannot touch `/usr/local/apache/conf/_ensure_vhost_includes_vhostless_test_file.conf': Permission denied
    [2011-08-24 08:29:15 -0700] warn [verify_vhost_includes] Failed to create /usr/local/apache/conf/_ensure_vhost_includes_vhostless_test_file.conf: No such file or directory at /usr/local/cpanel/Cpanel/FileUtils/TouchFile.pm line 65
    	Cpanel::FileUtils::TouchFile::touchfile('/usr/local/apache/conf/_ensure_vhost_includes_vhostless_test_file.conf') called at /scripts/verify_vhost_includes line 52
    warn [verify_vhost_includes] Failed to create /usr/local/apache/conf/_ensure_vhost_includes_vhostless_test_file.conf: No such file or directory
    Use of uninitialized value in string ne at /scripts/verify_vhost_includes line 56.
    Use of uninitialized value in string ne at /scripts/verify_vhost_includes line 60.
    Default symlink for test failed at /scripts/verify_vhost_includes line 61.
    [2011-08-24 08:29:16 -0700] info [ensure_vhost_includes] Unable to read /etc/userdomains, permission denied
    info [ensure_vhost_includes] Unable to read /etc/userdomains, permission denied
    [2011-08-24 08:29:16 -0700] info [ensure_vhost_includes] Unable to read /etc/userdomains, permission denied
    info [ensure_vhost_includes] Unable to read /etc/userdomains, permission denied
    Invalid user: domain-user
    No valid --user arguments given at /scripts/ensure_vhost_includes line 232.
     
  14. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    You seem to be using an invalid username (domain-user). Please use the linux username for that cpanel account (max 8 characters).

     
  15. wwwcad

    wwwcad New Member

    Joined:
    Oct 4, 2006
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    - Make sure the host have cgi execution in the Hosting Plan in WHM.
    - Check if the virtualhost for the domain have an ScriptAlias in /usr/local/apache/conf/httpd.conf

    It should be something like:
    --
     
  16. wheelerc

    wheelerc New Member

    Joined:
    Mar 21, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Thank you for this - I just upgraded using EasyApache and spent a long time checking file permissions and other settings trying to figure out why custom php.ini files with FastCGI had stopped working.. I didn't notice that AddHandler line had been commented out.

    Why does EasyApache do this? It would be good to have an options to tell it not to (or if there is one, please let me know where it is...)

    What would be really nice is a solution where we can use PHP with FastCGI but have it read php.ini files in the same way that SuPHP does, so we can just put the php.ini file in the document root, rather than having to edit .htaccess, and create and set permissions on files in the cgi-bin folder, which is hard to explain to customers.
     
  17. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    There are two solutions that we've used for this. One is easy, the other is more complicated ;)

    1. The easy way
    If you're using php 5.3+, let users use the .user.ini file instead. It's default in 5.3+ and they can set their specific settings there using the normal php.ini syntax. Observe that not all ini settings can be set this way (check php.net which).
    If you're using 5.2 or earlier you need to install an extension from PECL (htscanner) which acts in more or less the same way. We've configured it to read .php52.ini files instead of .user.ini since it doesn't have the same syntax. It uses the php_flag / php_value syntax like .htaccess does.
    PECL :: Package :: htscanner

    2. The hard way
    Make use of cPanels apache include system to set addhandlers through an include file that gets included directly in httpd.conf. This way they're retained even after easyapache is run. Link to docs: Changes Contained within a VirtualHost Directive
     
    #17 internetfab, Jul 3, 2012
    Last edited: Jul 3, 2012
  18. ikillbill

    ikillbill Member

    Joined:
    Feb 18, 2008
    Messages:
    112
    Likes Received:
    0
    Trophy Points:
    16
    Hello internetfab
    could you more elaborate on how to fix easyapache commenting out entries on .htaccess?

    we use PHP 5.3 +FASTCGI+CentOS6
     
  19. internetfab

    internetfab Member

    Joined:
    Feb 20, 2003
    Messages:
    331
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Gothenburg, Sweden
    There's so apparent way to stop easyapache from commenting out entries in .htaccess.
    However, if YOU are the one adding entries to your customers .htaccess file, for example AddHandler entries, then you should put them in the virtual host instead.

    You can keep changes to virtual hosts several ways, one of them is to put them like described in this document:
    Changes Contained within a VirtualHost Directive

    As an example:
    Customer Domain: cpaneltest.com
    Customer Username: cpanelte
    You're running apache 2.x and it's for non ssl

    Create a conf file:

    Code:
    /usr/local/apache/conf/userdata/std/2/cpanelte/cpaneltest.com/fastcgi.conf
    Put your AddHandler entries there:

    Code:
    AddHandler php5-fastcgi .php
    Then run:

    Code:
    /scripts/verify_vhost_includes
    After that I usually run
    Code:
    /usr/local/apache/bin/apachectl -t
    and last a restart of apache.
     
    #19 internetfab, Aug 8, 2012
    Last edited: Aug 8, 2012
  20. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,318
    Likes Received:
    7
    Trophy Points:
    38
    The behavior occurs when you change the PHP handler and is not dependent upon EasyApache. To influence which .htaccess files are examined and updated, please change the value of the following tweak setting:

    Depth to recurse for .htaccess checks
     

Share This Page