ISPConfig & nginx - PHP Inside HTML Files Not Executing

Discussion in 'Installation/Configuration' started by MainStreetJames, Feb 13, 2012.

  1. MainStreetJames

    MainStreetJames New Member

    Hi,
    Today's my first day with ISPConfig. I'm running ISPConfig 3.0.4.2 & nginx 1.0.12 on CentOS 6.2.

    I am able to display HTML pages, and PHP pages, but any PHP inside of an HTML page does not execute. I realize that mixing PHP inside the HTML isn't optimal use of nginx, but I need the code to work until I get a chance to separate everything.

    I've tried adding the following (copied from the '\.php$' directive) to the vhost file for the site, but when I do I get a 403 error when trying to display HTML files (with or without PHP inside):

    Code:
            location ~ \.html$ {
                try_files $uri =404;
        	    include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9011;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    I've also tried adding the following to the site's php-fpm.d conf file, but it doesn't seem to make a difference:
    security.limit_extensions = .php .html

    I've checked the error logs in /var/log/nginx, /var/log/php-fpm & the site's log did, but there are no errors related to this issue.

    I've tried changing the user from nginx to apache in the site's 'Web' tab in ISPConfig, but I still get the 403 error when the '~ \.html$' directive is in the vghost file. When I remove that directive the HTML files display properly, but the PHP inside is not executed.

    Any help would be greatly appreciated.


    Thanks,
    MSJ
     
  2. falko

    falko Super Moderator Howtoforge Staff

    Why don't you use the extension .php for these files instead of .html?
     
  3. MainStreetJames

    MainStreetJames New Member

    I suppose we could (which would be a lot of work changing all references to them in the site, project lists, external references, etc), but that doesn't address the server configuration issue. Most of the pages just have a few PHP variables that get expanded in place, and they'll get the PHP separated out in the future.

    Since nginx is supposed to be able to handle this - and its not really a stretch to expect a web server to do this - we'd like to be able to mix PHP with HTML when necessary.

    Clearly there's a setting in the current version of nginx/php-fpm that I've missed or screwed up. I doubt it's a permissions issue because the files used for testing are identical except for extension (including location, owner & group). Also, a plain HTML file (same location, owner & group) that will display properly with the default settings will generate the 403 error when the '\.html$' directive is in place.


    MSJ
     
  4. falko

    falko Super Moderator Howtoforge Staff

    Not sure, but maybe you have to modify the mime.types file in the /etc/nginx directory.
     
  5. kervin

    kervin New Member

    Did you ever find the solution to this problem? I'm dealing with the same issue.

    The application is a CMS that was built that way, so I have to support it.

    Whenever I add support for HTML I get a 500 error from my PHP scripts.
     
  6. falko

    falko Super Moderator Howtoforge Staff

    Do you use PHP open and close tags in your files (<?php and ?>)?
     
  7. kervin

    kervin New Member

    Thanks. My error turned out to be related to the application itself not ISPConfig. Once that was fixed I was good to go.
     
  8. glasprilla

    glasprilla New Member

    Hi.
    I have the same trouble (ISPConfig 3.1.6 & nginx - PHP Inside HTML Files Not Executing on CentOS 7), would you like help me with a solution because in this post is not published the solution?
    Thanks,
    German Lasprilla
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    Do the files have .php as file ending? Files with ending .html are not parsed from PHP. And check that the PHP tags in the file have the long form <?php .... ?> and not just <? .... ?> or <% .... %>. If you want to use the short php form then you will have to enable that in php.ini.
     
  10. glasprilla

    glasprilla New Member

    How to enable the files with ending .html are parsed from PHP, I have a CMS aplication ?
    Thanks for your help.
     

Share This Page