Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    6
    cPanel/Enkompass Access Level

    Root Administrator

    Default Adding mod_fastcgi option as php handler in whm to enable APC cache

    As the title imply. I am requesting adding mod_fastcgi as PHP handler in whm-->Configure PHP and SuExec to make APC ( and other opcode caching) work efficiently.


    now the details

    refer to this wonderful blog by Brandon
    /http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/
    (I don't know what is wrong with this url I have added a copy of google cached page in attachment)


    let's quote this from the blog:

    Both mod_fcgid and mod_fastcgi can be told to limit the number of PHP processes to 1 per user. The PHP process can then be told how many children to spawn. Unfortunately mod_fcgid will only send one request per child process. The fact that PHP spawns its own children is ignored by mod_fcgid. If we use mod_fcgid with our setup, we can only handle one concurrent PHP request. This is not good. A long running request could easily block multiple smaller requests.

    mod_fastcgi will send multiple simultaneous requests to a single PHP process if the PHP process has children that can handle it. This is the reason we must use mod_fastcgi to achieve our goal of one cache per user.
    Things are clear now. we need to enable and improve PHP opcode caching. PHP opcode cache is really vital and make the server really fast, reduce memory consumption at the peak load. reduce CPU load to very low rates .. etc.


    The options that are enabled now in WHM are:

    suPHP: secure right .. but it is also the worst option for opcode caching mechanism.
    fastcgi (as mod_fcgid): read the quote above:
    cgi: as CPanel said: it is neither secure nor efficient php handler. I have concluded that it never work with opcode cache.
    None: .. it is really none. PHP files will be served as text files unless you define your own handler in Apache config (as I did)

    Other (supported) optoin not listed here is to use mod_php. APC caching work with mod_php and it is fast. But mod_php have several other drawbacks you can read about in tons of blogs in internet.


    I have tested mod_fcgid by my self. with 20 concurrent request for a single user account, mod_fcgid initiate 20 standalone php process (for that user) . each one with its own APC cache memory. that's make my server reach the memory limit too often. Also the concurrent request utilize different APC memories and that is really inefficient.


    It seems that mod_fastcgi is the only good, efficient and secure handler that work very well with opcode cache liek APC. I have searched the whole internet for other solution, I have read tons of blogs. but I couldn't find better solution.

    I decided to implement mod_fastcgi by myself. since neither hostgator nor Cpanel accept to do it for me. Firstly I must install and compile mod_fastcgi to work with my Apache. this blog was really nice:

    /http://www.cyberciti.biz/tips/rhel-centos-fedora-apache2-fastcgi-php-configuration.html

    also see this url:

    /http://www.fastcgi.com/cvs/mod_fastcgi/INSTALL.AP2

    after installing .. now configure Apache to use that module instead of mod_fcgid (I hate its name by the way)

    in pre_virtualhost_global.conf (do not copy and paste):

    LoadModule fastcgi_module modules/mod_fastcgi.so
    <IfModule fastcgi_module>
    FastCgiConfig -idle-timeout 20 -maxClassProcesses 1
    FastCgiWrapper On
    AddHandler php5-fcgi .php
    Action php5-fcgi /fcgi-bin/php-fastcgi
    <Location "/fcgi-bin/php-fastcgi">
    Order Deny,Allow
    Deny from All
    Allow from env=REDIRECT_STATUS
    Options ExecCGI
    SetHandler fastcgi-script
    </Location>
    SuexecUserGroup username username
    Alias /fcgi-bin/ /var/www/bin/username/
    </IfModule>
    ##### End ######

    the wrapper script:

    #!/bin/sh
    PHP_FCGI_CHILDREN=5
    export PHP_FCGI_CHILDREN
    PHP_FCGI_MAX_REQUESTS=500
    export PHP_FCGI_MAX_REQUESTS
    umask 0022
    exec /usr/bin/php-cgi
    ##### End ######

    disable PHP handler in whm -->Configure PHP and SuExec (select none for php 5 handler)




    surely this could be better. I can define a wrapper script for each user and define suexec rule inside virtual hosts. but since I am the only user in the server.. I can define my directives globally. I am not a server administrator. I am just a good read. Most of the information here based on Brandon blog so read it .. read it ten times if you have to ( I put a copy of the blog in the attachment)

    I know this make me unsupported . but this is the best solution ever found. I have now 20 php child can handle 20 concurrent request. all them utilize the same APC cache memory (150M). and the overall ram used by account is only about 730M. and the server is very stable even on high load and for long time.



    I wish the feature added to whm in that way:

    Adding mod_fastcgi option as php handler in whm to enable APC cache-1-25-2012-4-44-46-pm.png


    So it is the admin preference to use mod_fastcgi or mod_fcgid

    thanks.

  2. #2
    Member
    Join Date
    Jan 2012
    Posts
    10
    cPanel/Enkompass Access Level

    Website Owner

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    +1 I agree, I would like to see this in WHM.

    I tried installing fastCGI myself using the above tutorials however every time I call a .php from my server it returns the raw, un-compiled .php script!

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

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    I did want to post the following link about mod_fastcgi versus mod_fcgid:

    Apache :: mod_fcgi is NOT a replacement for mod_fastcgi

    I bring this up as you will most definitely have the following three points noted by anyone who would prefer not to see mod_fastcgi included with EasyApche:

    1. Very little development of mod_fastcgi
    2. Possible memory leaks
    3. mod_fastcgi and mod_fcgid do the same thing and so only one needs to be available (it would be too confusing to offer both)

    The above forum thread covers points 1 and 3 to discuss why mod_fastcgi should be available for a machine to use.
    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
    Member
    Join Date
    Apr 2011
    Posts
    145
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    If you're willing to wait until cPanel implements it with PHP 5.4, the below feature request for php-fpm will give you what you want:

    http://forums.cpanel.net/f145/case-4...161210-p3.html

    I do want to mention that Simsim's quote from that blog is slightly misleading -- fcgid "can only handle one concurrent PHP request" ONLY if you enable PHP_FCGI_CHILDREN, which Apache specifically tells you not to do:

    PHP child process management (PHP_FCGI_CHILDREN) should always be disabled with mod_fcgid, which will only route one request at a time to application processes it has spawned; thus, any child processes created by PHP will not be used effectively. (Additionally, the PHP child processes may not be terminated properly.)
    Ref: mod_fcgid - Apache HTTP Server

    One last note:
    Quote Originally Posted by Simsim View Post
    Other (supported) optoin not listed here is to use mod_php. APC caching work with mod_php and it is fast. But mod_php have several other drawbacks you can read about in tons of blogs in internet.
    Most of the arguments against using mod_php center around:
    1. Security issues in shared hosting environments
    2. Issues with uploaded files being owned by 'nobody'.
    However, the OP stated he/she is the only user on the system, which minimizes #1. Using mod_ruid2 with mod_php eliminates both #1 and #2. Just something to consider.

  5. #5
    Member
    Join Date
    Jan 2012
    Posts
    6
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    Edit:

    though My server now looking good for first sight and I have achieved my main goal, but I have really big problems.

    1- php instantly create 20 child after server restart. they are idle most of time except the peak load time (between 7 pm to 10pm)
    2- In Vz, though I have really low memory consumption. but kmemsize reach 80% of its limit in my VPS.
    3- I told mod_fastcgi to spawn only one php process with (-maxClassProcesses) option. but I have seen that after one day or two of server uptime, there are more than one php main process each one with its own 20 childs.

    the third problem mean that mod_fastcgi didn't respect my restriction to spawn only one php process (one leader process). Or it had created (by mistake) another php main process then didn't try to kill it. I had to restart the VPS to get things back to noraml. I have to do this once per day or two days

    Oh .. I don't know what to do .... Cpanel should find a good and efficient solution to use opcode cache. I wonder why Cpanel put Xcache and excelerator as options in easyapache though no body can use them practically .. and the big problem ..no one tell me what I can do. I will cry
    Last edited by Simsim; 02-20-2012 at 12:21 PM.

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

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    Have you tried DSO + mod_ruid2 which is now in EDGE and CURRENT (11.32.0.1) for EasyApache? DSO works with OPCode caching mechanisms and doesn't run as the user nobody under mod_ruid2. This was already mentioned as a viable alternative by alphawolf50's last post.
    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

  7. #7
    Member
    Join Date
    Jan 2012
    Posts
    6
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    Quote Originally Posted by alphawolf50 View Post
    If you're willing to wait until cPanel implements it with PHP 5.4, the below feature request for php-fpm will give you what you want:

    http://forums.cpanel.net/f145/case-4...161210-p3.html
    OK I have read about php-fpm. seems to solve my problem as well as many other people problems. But I don't know when php 5.4 will be released. further more Cpanel then may find another problem or something cause them to wait for php 6.0 or whatever future release. until that time. I have to remember to restart my server once per day or two days.

    except this stability problem fastcgi look very well and really really fast and light wait.

  8. #8
    Member
    Join Date
    Jan 2012
    Posts
    6
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    Have you tried DSO + mod_ruid2 which is now in EDGE and CURRENT (11.32.0.1) for EasyApache? DSO works with OPCode caching mechanisms and doesn't run as the user nobody under mod_ruid2. This was already mentioned as a viable alternative by alphawolf50's last post.
    at the first glance I don't know how to get this work together. Also I didn't see such option (mod_ruid2) in easy apache up to now. further more regarding this:

    The mod_ruid2 Module

    I have to switch from MPM worker to perfork or whatever. I have read worker is faster (or more efficient) than perfork. I don't know really if that have impact on my server. I am serving both static contents and php scripts.

    any way thanks for everybody wrote something here. certainly I retreat my feature request since mod_fastcgi is not that stable though it resolve the problem of php opcode cache utilization. Let's wait and see what Cpanel will do for their costumers sake

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

    Root Administrator

    Default Re: Adding mod_fastcgi option as php handler in whm to enable APC cache

    If you are still on 11.30, then mod_ruid2 will not show up in EasyApache in the Apache modules short options list. It is only available in EDGE and CURRENT (11.32) right now.
    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

Similar Threads & Tags
Similar threads

  1. Replies: 1
    Last Post: 02-25-2012, 10:03 PM
  2. APC 3.1.9 Cache Frequently Restarts!
    By Gene Steinberg in forum cPanel and WHM Discussions
    Replies: 11
    Last Post: 11-30-2011, 03:13 PM
  3. fcgid (FastCGI) and APC shared cache
    By larwilliams in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 11-05-2009, 01:21 PM
  4. [StepByStep] Decreasing server CPU load with PHP APC cache extension
    By FractalizeR in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 01-28-2008, 09:11 AM
  5. APC (Alternative PHP Cache) or Xcache works with the phpsuexec ?
    By duranduran in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 04-23-2007, 11:29 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube