skip to Main Content

I recently migrated a site from Apache to Nginx and now php code in html doesn’t get parsed. .PHP pages parses without a problem as you can see in the attached image output of phpinfo.php in the bottom of this post.

This is how the code looks like in pages such as index.html:

<!-- Copyright -->
<? include("includes/copyright.php") ?>

        </body>
</html>

As you can see, there’s no <?php tag wrapping the code, but still, Apache would execute the php include, which in this case adds a footer with copyright info to the page.

Again, this is NOT a .php file but a .html instead.

If I wrap the code in a <?php ?> tag and rename the file from .html to .php, the code will parse, but THIS IS NOT an option as the site has hundreds of pages and each file has multiple php commands such as the include above.

I’ve followed instructions in many posts but still, couldn’t get it to work… Will really appreciate if someone could shed a light as I’m really not sure what else to try.

/etc/nginx/sites-available/mysite.com.conf

server {
        server_name mysite.com www.mysite.com;
        listen 111.111.11.111;
        root /home/mysite/public_html;
        index index.php index.htm index.html;
        access_log /var/log/virtualmin/mysite.com_access_log;
        error_log /var/log/virtualmin/mysite.com_error_log;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE nginx;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param SCRIPT_FILENAME /home/mysite/public_html$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param DOCUMENT_URI $document_uri;
        fastcgi_param DOCUMENT_ROOT /home/mysite/public_html;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS $https;

        location ~ .(php|html)$ {
                try_files $uri $fastcgi_script_name =404;
                fastcgi_pass unix:/var/php-nginx/1618253277225737.sock/socket;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

        fastcgi_split_path_info ^(.+.php)(/.+)$;
        listen 111.111.11.111:443 ssl;
        ssl_certificate /home/mysite/ssl.combined;
        ssl_certificate_key /home/mysite/ssl.key;

.htaccess from Apache server:

AddType application/x-httpd-ea-php56 .html .htm
ErrorDocument 404 /error-page.html 
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

# BEGIN gzip file compression
# Compress HTML, CSS, JavaScript, Text, XML and fonts
...

Output of phpinfo.php

short_open_tag is enabled

2

Answers


  1. Have you tried to add

    types {
        application/x-httpd-ea-php56 html htm;
    }
    

    In location ?

    Login or Signup to reply.
  2. <? is a Short Open Tag.

    Since PHP 5.3 (from 2009!) support is off by default. (It conflicts with other processing instructions, such as the XML declaration).

    You can turn it on using the short_open_tag directive in php.ini

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search