Issue with non-existent php files

Discussion in 'Installation/Configuration' started by bch, Oct 15, 2017.

  1. bch

    bch Member

    I have this issue on a newly installed perfect server with ISPConfig 3.1.7p1, Debian 9.2, Apache 2.4.25 and PHP-FPM.

    Action:
    example.com/non-existent-file.php

    Browser output:
    "File not found."

    Error.log:
    [proxy_fcgi:error] [client] AH01071: Got error 'Primary script unknown\n'

    Expected:
    Handled by ErrorDocument (like any other file types).

    Another issue, I cannot run PHP files in the default /error folder of a website anymore. The source code is sent to the browser.

    Thanks for helping out :)

    Edit: this post should probably have been posted in the Server Operation forum. Sorry for that.
     
    Last edited: Oct 15, 2017
  2. I guess you are missing php handler for the website, Make sure you enable php for the website by selecting any handler like fast-cgi, suphp etc..
     
  3. bch

    bch Member

    That's not the case. PHP works fine.
     
  4. bch

    bch Member

  5. bch

    bch Member

    This issue is unfortunately still present on 18.04. Several StackOverflow questions without a solution. I guess it's a bug in Apache.
    It's not possible to create errordocument pages when the file extension is .php. The log says
    Code:
    AH01071: Got error 'Primary script unknown\n'
     
  6. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    sooo please post output of
    Code:
    a2query -m
    do you have any rewrites for that page like forward all requests to index.php?
    In rare situations there can be an issue where php gets its request before the correct rewrite. If you have, please post your rewrites / htaccess/additional vhost entries.

    Maybe attach the vhost file from /etc/apache2/sites-enabled/

    edit: oh yeah and I assume you're running using php-fpm
     
  7. bch

    bch Member

    Hi, no rewrites. Everything is default perfect server. The ISPConfig standard error document page should show up but it does not.

    Yes, PHP-FPM as I wrote in the first line of the first post :)
     
    Last edited: May 30, 2018
  8. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    no you just mentioned the howto ;) you still could've set it to fastcgi or mod_php with deprecated _prefork mpm ,)
    So I miss the list of modules to check against aswell as vhost file - hmm but I still missed something, normal php outside /error works fine?
    "ErrorDocument 404 /" or as mentioned to a existent .php file?
    Have you checked what your webserver's doing by setting log level very low and watch what happens while you try to load a page?
     
  9. bch

    bch Member

    No, see the last word on line 1 :) The php files in /error is unrelated and just a sidenote.
    The error is simply: Create a website with PHP-FPM. Go to that website and append /something.php to the URL. The ISPConfig standard error document page should show ERROR 404 - NOT Found! And it does with .html and so on, but not with .php.

    Loaded Modules:
    core_module (static)
    so_module (static)
    watchdog_module (static)
    http_module (static)
    log_config_module (static)
    logio_module (static)
    version_module (static)
    unixd_module (static)
    access_compat_module (shared)
    actions_module (shared)
    alias_module (shared)
    auth_basic_module (shared)
    auth_digest_module (shared)
    authn_core_module (shared)
    authn_file_module (shared)
    authz_core_module (shared)
    authz_host_module (shared)
    authz_user_module (shared)
    autoindex_module (shared)
    cgi_module (shared)
    dav_module (shared)
    dav_fs_module (shared)
    deflate_module (shared)
    dir_module (shared)
    env_module (shared)
    expires_module (shared)
    fcgid_module (shared)
    filter_module (shared)
    headers_module (shared)
    http2_module (shared)
    include_module (shared)
    mime_module (shared)
    mpm_event_module (shared)
    negotiation_module (shared)
    proxy_module (shared)
    proxy_fcgi_module (shared)
    python_module (shared)
    reqtimeout_module (shared)
    rewrite_module (shared)
    setenvif_module (shared)
    socache_shmcb_module (shared)
    ssl_module (shared)
    status_module (shared)
    suexec_module (shared)

    <Directory /var/www/hostname.mydomain.com>
    AllowOverride None
    Require all denied
    </Directory>

    <VirtualHost 192.168.2.166:80>

    DocumentRoot /var/www/clients/client1/web1/web

    ServerName hostname.mydomain.com
    ServerAdmin [email protected]


    ErrorLog /var/log/ispconfig/httpd/hostname.mydomain.com/error.log

    Alias /error/ "/var/www/hostname.mydomain.com/web/error/"
    ErrorDocument 400 /error/400.html
    ErrorDocument 401 /error/401.html
    ErrorDocument 403 /error/403.html
    ErrorDocument 404 /error/404.html
    ErrorDocument 405 /error/405.html
    ErrorDocument 500 /error/500.html
    ErrorDocument 502 /error/502.html
    ErrorDocument 503 /error/503.html

    <IfModule mod_ssl.c>
    </IfModule>

    <Directory /var/www/hostname.mydomain.com/web>
    # Clear PHP settings of this website
    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler None
    </FilesMatch>
    Options +FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
    <Directory /var/www/clients/client1/web1/web>
    # Clear PHP settings of this website
    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler None
    </FilesMatch>
    Options +FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>





    # suexec enabled
    <IfModule mod_suexec.c>
    SuexecUserGroup web1 client1
    </IfModule>
    <IfModule mod_fastcgi.c>
    <Directory /var/www/clients/client1/web1/cgi-bin>
    Require all granted
    </Directory>
    <Directory /var/www/hostname.mydomain.com/web>
    <FilesMatch "\.php[345]?$">
    SetHandler php-fcgi
    </FilesMatch>
    </Directory>
    <Directory /var/www/clients/client1/web1/web>
    <FilesMatch "\.php[345]?$">
    SetHandler php-fcgi
    </FilesMatch>
    </Directory>
    Action php-fcgi /php-fcgi virtual
    Alias /php-fcgi /var/www/clients/client1/web1/cgi-bin/php-fcgi-192.168.2.166-80-hostname.mydomain.com
    FastCgiExternalServer /var/www/clients/client1/web1/cgi-bin/php-fcgi-192.168.2.166-80-hostname.mydomain.com -idle-timeout 300 -socket /var/lib/php7.2-fpm/web1.sock -pass-header Authorization -pass-header Content-Type
    </IfModule>
    <IfModule mod_proxy_fcgi.c>
    #ProxyPassMatch ^/(.*\.php[345]?(/.*)?)$ unix:///var/lib/php7.2-fpm/web1.sock|fcgi://localhost//var/www/clients/client1/web1/web/$1
    <Directory /var/www/clients/client1/web1/web>
    <FilesMatch "\.php[345]?$">
    SetHandler "proxy:unix:/var/lib/php7.2-fpm/web1.sock|fcgi://localhost"
    </FilesMatch>
    </Directory>
    </IfModule>



    # add support for apache mpm_itk
    <IfModule mpm_itk_module>
    AssignUserId web1 client1
    </IfModule>

    <IfModule mod_dav_fs.c>
    # Do not execute PHP files in webdav directory
    <Directory /var/www/clients/client1/web1/webdav>
    <ifModule mod_security2.c>
    SecRuleRemoveById 960015
    SecRuleRemoveById 960032
    </ifModule>
    <FilesMatch "\.ph(p3?|tml)$">
    SetHandler None
    </FilesMatch>
    </Directory>
    DavLockDB /var/www/clients/client1/web1/tmp/DavLock
    # DO NOT REMOVE THE COMMENTS!
    # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
    # WEBDAV BEGIN
    # WEBDAV END
    </IfModule>

    ServerAlias hostname2

    </VirtualHost>

    Edit: as per https://stackoverflow.com/questions/33843786/custom-404-message-when-using-php-fpm-with-apache
    it works to add "ProxyErrorOverride on" in Options / Apache Directives
     
    Last edited: May 30, 2018
    ztk.me likes this.
  10. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    u mentioned the howto u followed, doesn't mean u have to use the fpm mode for this case ;) however yeah
    I didn't see the issue, right ... I thought an existing error.php doesn't work ( should pay more attention while reading ) but ok.
    Calling anything-nonexistent.php should call the working and existing error-document - which it doesn't.

    issue is, there's no try_files like in nginx to check file existing, dunno / will need lookup wether we can have php-fpm return status code or better apache before it wastes resources.
     
  11. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    change /usr/local/ispconfig/server/conf/vhost.conf.master
    encapsulate every <FilesMatch "\.php[345]?$"> ( think while doing it, example: mod_php wouldnt need that ) with
    Code:
     <If "-f %{REQUEST_FILENAME}">
    
        </If>
    

    could look like:

    dunno if this can be done with conf-custom folder @till ? you need to recreate the website vhost file either by changing something or resync just all pages.
     
    bch likes this.
  12. bch

    bch Member

    Thank you for providing a fix - I will test it :)
     
  13. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    this time, as a little sorry, I actually tested if it works before answering :eek:
     
    bch likes this.
  14. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    ahrasis likes this.

Share This Page