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.

PHP-FPM Directory Index index.html file not found problem

Discussion in 'EasyApache' started by kdean, Feb 28, 2016.

  1. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    I've been setting up FPM using the tutorial for EA4 and for the most part it's working with straight PHP sites, but sites with mixed content (index.html) have a problem.

    My fpm.conf files following this pattern:

    Code:
    <IfModule proxy_fcgi_module>
         ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/home/username/run/php56-fpm.sock|fcgi://localhost/home/username/public_html"
         DirectoryIndex index.php
     </IfModule> 
    
    From what I've read, the above looks for .php files and if it's a directory index returns index.php. The problem is apache doesn't pass the full path here so a folder like /foldername/ that normally loads /foldername/index.html tries to load /foldername/index.php instead even though it doesn't exist. Loading /foldername/index.html directly works.

    I tried adding other index.html, etc. names to the DirectoryIndex here but no difference.

    This is the method from the tutorial so cPanel may not be aware of this problem yet. Anyone have any ideas that can be done at the configuration level instead of site htaccess changes / filename changes?

    Anyway to know that the directoryindex is index.html before the proxy kicks in?
     
  2. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    It seems to break FancyIndexing as well.
     
  3. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    I am finding it works better if I place an index.html before index.php, but FancyIndexing still doesn't work.

    Code:
    <IfModule proxy_fcgi_module>
         ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/home/username/run/php56-fpm.sock|fcgi://localhost/home/username/public_html"
         DirectoryIndex index.html index.php
    </IfModule>
    
    I'm also looking into using SetHandler instead of ProxyPassMatch as recommended here:

    PHP-FPM and HTTPD 2.4 improvement - Remi's RPM repository - Blog

    ...but not much luck there. I end up getting indexes and html to work but php breaks.
     
  4. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,382
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Does:

    Code:
    <IfModule proxy_fcgi_module>
       <FilesMatch "\.php$">
         SetHandler "proxy:unix:/home/%user%/run/php56-fpm.sock|fcgi://localhost"
       </FilesMatch>
       ProxyErrorOverride on
    </IfModule>
    Not work? This seems to work for me.
     
  5. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    That works great. Thank you very much.

    When I tried SetHandler before, I used the full "localhost/home/username/public_html" as in the tutorial, but it looks like that doesn't work on SetHandler and needs to be trimmed to how you provided.

    This also solved a number of other issues i was researching in addition to the html indexing and FancyIndexes problem, such as seeing apache error messsages and problems with Wordpress Multisite not loading some pages.

    All looks good now.

    cPanel, you should revise your tutorial (linked below) to indicate that people running Apache 2.4.10 and above should use the this method instead since it appears to be much more compatible.

    Tutorial: Configure PHP-FPM with User Pools for EasyApache 4 - cPanel Knowledge Base - cPanel Documentation
     
  6. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,382
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    The Apache error is now displayable because of the ProxyErrorOverride on

    Are you still having issues with FancyIndexing? That would appear to be more of a general Apache issue and unrelated to PHP-FPM

    I am also curious as to why DirectoryIndex is being included in the userdata file for each VirtualHost (as per the cPanel docs). Am I missing a reason for why that should be there?
     
  7. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    When they use ProxyPassMatch the directory index of the server no longer appears to work, so they added back index.php so those would work.

    FancyIndexing is now fine. Basically only a minor use case for a few folders where I needed people to see files. Normally auto indexing is off.

    Interesting thing about the ProxyErrorOverride. I had to disable that because every 404 was returning an Error 500 instead and in one case a wordpress plugin was causing me to use up all my pools and then lock out further connections simply becuase there was a stylesheet in the plugin referring to iamges that didn't exist and I guess some kind of plugin check for wordpress would trigger it. Basically I just log into wordpress dashboard and immediately watch the pools grow to the limit. Weird.

    So, after deleting ProxyErrorOverride, I still see the correct error messages so it seems fine without it. Perhaps that was more important with the ProxyPassMatch method.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    The "Configure PHP-FPM with User Pools for EasyApache 4" document is still a work in-progress. It looks like some tweaks to this document are planned and under review at this time. Could you provide a list of any items that still require an update on this document, and we can report them to our documentation team?

    Thank you.
     
  9. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    Here's a variety of things I came across while implementing the tutorial, researching online and referring to posts made by other cPanel users who had already gone down this path.

    • Either replace Step 6b’s code with the following or indicate that Apache 2.4.10+ users should use this code instead for better compatibility.

    Code:
    <IfModule proxy_fcgi_module>
      <FilesMatch "\.php$">
        SetHandler "proxy:unix:/home/$<user>/run/php56-fpm.sock|fcgi://localhost"
      </FilesMatch>
    </IfModule>
    

    • Step 6b might also mention that the fpm.conf can be placed in the <useraccount> folder to set a default PHP-FPM config for all domains for that user account. fpm.con files placed in <useraccount>/<vhost> as directly would still override the default for the useraccount. This just speeds up the manual configuration process when setting up a bunch of accounts.

    • Step 2 should also indicate to create a session folder

    Code:
    mkdir -p /home/$<user>/tmp/session
    
    …or another folder if cPanel prefers something different. The sessions need a user-owned folder to write.

    • Step 4f

    Change the Session save path to the folder created above.

    Code:
    php_value[session.save_path]    = /home/$<user>/tmp/session
    
    • After Step 4d

    I’d recommend either mentioning the following setting or recommending it especially for servers with a lot of accounts so that initial memory consumption is a lot less before more advanced configuration is made. The “dynamic” default launches a minimum of 1 pool per user, while “on demand” only launches the pools as needs and sticks around for the amount of time set by “pm.process_idle_timeout”. Previous FCGID users should find these options similar.

    Code:
    pm = ondemand
    
    Some in general notes...

    • The php.ini’s as configured within WHM do not apply and must be manually configured at the following locations. These are individually set per PHP version.

    Code:
    /opt/cpanel/ea-php56/root/etc/php.ini
    /opt/cpanel/ea-php55/root/etc/php.ini
    /opt/cpanel/ea-php70/root/etc/php.ini
    
    • If you want to make use of the OPCache ini to activate and configure, go here:

    Code:
    /opt/cpanel/ea-php56/root/etc/php.d/opcache.ini
    /opt/cpanel/ea-php55/root/etc/php.d/opcache.ini
    /opt/cpanel/ea-php70/root/etc/php.d/opcache.ini
    
    • Right now as instructed the OPCache is shared amongst all sites running the same version of PHP. You may want to move in the direction of setting up master processes per user so the OPCache is only shared amongst each user account alone. This would be a much more complex config but likely more secure. Reloading or Restarting the FPM Master processes would be more difficult as well, but I’m sure a script could facilitate that once FPM is integrated into EasyApache.

    • Some script options to be aware of as shown in Step 5. If you’ve made changes to the conf files you can do a Reload to apply those changes. This waits for current pool processes to complete before reloading. This resets the OPCache as well.

    Code:
    /etc/init.d/ea-php70-php-fpm reload
    /etc/init.d/ea-php55-php-fpm reload
    /etc/init.d/ea-php70-php-fpm reload
    
    If you’ve made changes to the main php.ini files you need to do a Restart to apply those changes. This also applies the conf changes and OPCache reset.

    Code:
    /etc/init.d/ea-php70-php-fpm restart
    /etc/init.d/ea-php55-php-fpm restart
    /etc/init.d/ea-php70-php-fpm restart
    
    • I also noticed that the WHM / cPanel interface for creating the user’s php.ini file creates a php.ini file as expected, but the main php.ini for each version of PHP is not actually configured to use it so it doesn’t work by default. Setting the following fixes that.

    Code:
    user_ini.filename = "php.ini"
    
    • Also since FPM currently required manually configuration for changes, I looked to disable the MultiPHP Manager in the Feature Manager while keeping the MultiPHP INI Editor active, but unfortunately disabling MultiPHP Manager disables both sections from appearing. This will be moot once FPM is fully integrated.
     
    graham_w, lkraav and sparek-3 like this.
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Thank you taking the time to formulate that response. There's a new internal case open (HB-1471) that aims to explore using PHP-FPM in several different environments that would address these types of issues. There's no specific time frame to provide on when it might get implemented, but I'll update this thread once more information is available.

    Thank you.
     
  11. lkraav

    lkraav Registered

    Joined:
    Mar 26, 2013
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I can confirm, majority of the above advice is correct. `SetHandler` is the way to go, first of all. And you shouldn't append additional path items to the proxy definitions, because it will throw off the DocumentRoot calculation.

    Speed improvements going to PHP7 + FastCGI are massive. A PHP7 page building in 0.80s before now builds consistently in 0.15s, similar to what I'm seeing on my fully optimize Gentoo staging site. Compared to PHP5, it's even more - possible a 10x+ raw build speed improvement.

    EDIT another optimization is to use php-fpm's built-in $pool variable for $<user>.conf, instead of repeating hardcoded username everywhere. This also paves way for better automating.

    EDIT slowlog parameter path value should be adjusted to /home/$<user>/logs
     
    #11 lkraav, Mar 23, 2016
    Last edited: Mar 23, 2016
  12. ITGabs

    ITGabs Well-Known Member

    Joined:
    Jul 30, 2013
    Messages:
    81
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Configure PHP-FPM with User Pools for EasyApache 4 - cPanel Knowledge Base - cPanel Documentation


    • <user>represents the name of a user on the system.
    • example.com represents the domain's base directory.
    • <useraccount>represents the user's account.
    • <vhost> represents the name of the virtual host.


    What is the difference between <user> and <useraccount>?

    And example.com and <vhost>?

    it's a bit confusing since both values looks the same

    Testing in PHP-FPM, MPM-event in EA4 PHP56 Centos 6.7 cPanel 56.x for few sites first
     
  13. ITGabs

    ITGabs Well-Known Member

    Joined:
    Jul 30, 2013
    Messages:
    81
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
  14. ITGabs

    ITGabs Well-Known Member

    Joined:
    Jul 30, 2013
    Messages:
    81
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    I found another problem with the documentation
    only this script restart php-fpm /scripts/restartsrv_cpanel_php_fpm

    Also it's not clear if the run directory should be inside /home/user or /var/home/user (as in other documents)
    https://features.cpanel.net/attachments/1210
     
  15. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
  16. ITGabs

    ITGabs Well-Known Member

    Joined:
    Jul 30, 2013
    Messages:
    81
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Thanks, actually I was reading that thread, but
    help me to figure out a problem with exim also thanks!
     
  17. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    You can follow the progress of enhanced FPM support referenced in my previous post at:

    Enhance FPM support

    It's tentatively scheduled for the version 58 release cycle. Please feel free to add feedback to this feature request.

    Thank you.
     
  18. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    Just discovered another issue when I rebooted, the user PHP-FPM processes weren't starting under Centos 6.7.

    Looks like the /etc/rc.d runlevels for the php-fpm scripts were not created correctly and every runlevel was set to kill the process even for startups.

    K16ea-php54-php-fpm
    K16ea-php55-php-fpm
    K16ea-php56-php-fpm
    K16ea-php70-php-fpm

    So for the startup runlevels (rc2.d, rc3.d, rc4.d, rc5.d) it looks like I needed to change them to:

    S16ea-php54-php-fpm
    S16ea-php55-php-fpm
    S16ea-php56-php-fpm
    S16ea-php70-php-fpm

    I'll see if it works the next time I need to reboot for a kernel update.
     
  19. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,382
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    One issue I seem to have found with using:

    Code:
    <IfModule proxy_fcgi_module>
      <FilesMatch "\.php$">
      SetHandler "proxy:unix:/home/$<user>/run/php56-fpm.sock|fcgi://localhost"
      </FilesMatch>
    </IfModule>
    Is that there is a long delay in processing a file not found.

    If you set this and then try to vist:

    http://example.tld/filethatdontexist.php

    It takes about 15 seconds for the 404 to generate.

    It has to be a timeout issue in the proxy system, but I don't exactly know how to overwrite that. Or where you might do that.

    Is anybody else seeing the same thing?

    Any suggested fixes?
     
  20. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,382
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Actually what I had was

    Code:
    <IfModule proxy_fcgi_module>
      <FilesMatch "\.php$">
      SetHandler "proxy:unix:/home/$<user>/run/php56-fpm.sock|fcgi://localhost"
      </FilesMatch>
      ProxyErrorOverride on
    </IfModule>
    On a WordPress site. Apparently some combination of WordPress's file not found .htaccess code and ProxyErrorOverride on causes significant delays.
     
Loading...

Share This Page