ServedEZ - Free, Simple easy Ad free Unlimited WebHosting - A NexusBytes Company

Hosting => Webhosting Support => Topic started by: pabws on July 10, 2019, 12:55:05 AM

Title: Using PHP Within HTML Files
Post by: pabws on July 10, 2019, 12:55:05 AM
I have an existing website that uses embedded PHP code within the HTML files and would like to know the best way to enable PHP parsing of .html files.

On other webhosts, I simple add a couple Apache directives such as 

Code: [Select]
AddType application/x-httpd-ea-php72 .html
AddHandler application/x-httpd-ea-php72 .html

to the .htaccess file to enable the parsing.

Unfortunate, I have been unable to find something that works and believe it is because the  server is using the FPM/FastCGI API for PHP.

Any suggestions would be appreciated.

Thanks in advance, Paul
Title: Re: Using PHP Within HTML Files
Post by: SE-JAY on July 10, 2019, 01:15:13 AM
I have an existing website that uses embedded PHP code within the HTML files and would like to know the best way to enable PHP parsing of .html files.

On other webhosts, I simple add a couple Apache directives such as 

Code: [Select]
AddType application/x-httpd-ea-php72 .html
AddHandler application/x-httpd-ea-php72 .html

to the .htaccess file to enable the parsing.

Unfortunate, I have been unable to find something that works and believe it is because the  server is using the FPM/FastCGI API for PHP.

Any suggestions would be appreciated.

Thanks in advance, Paul

Hey Bud,
Server is configured with php-fpm, with php 7.3 as default and 5.6 is available as an option; utilizing Nginx as reverse proxy

Please update your code to

Code: [Select]
AddType application/x-httpd-ea-php73 .html
AddHandler application/x-httpd-ea-php73 .html

And let me know if that works.
Title: Re: Using PHP Within HTML Files
Post by: pabws on July 10, 2019, 01:25:57 AM
Thanks for the quick reply.  Unfortunately, the updated code did not work.

When I used that code in the .htaccessfile, the embedded PHP did not execute and in addition, the browser now downloads the .html file instead of displaying it.
Title: Re: Using PHP Within HTML Files
Post by: SE-JAY on July 10, 2019, 03:07:59 AM
Sorry for the late reply, finally figured out!

Use this.

Code: [Select]
<FilesMatch "\.(inc|php|phtml|phps|php73|html|htm)$">
    AddHandler "proxy:unix:/usr/local/php73/sockets/xtlbzcrj.sock|fcgi://localhost" .inc .php .phtml .php73 .html .htm
</FilesMatch>
Title: Re: Using PHP Within HTML Files
Post by: SE-JAY on July 10, 2019, 11:32:32 AM
Hi, following up on this.

Please let me know if it worked for you.
Title: Re: Using PHP Within HTML Files
Post by: pabws on July 10, 2019, 12:13:03 PM
Winner winner, chicken dinner!!!

Thank you for figuring this out.  I would have never gotten this to work without your assistance.

If anyone needs to do this in the future, you can actually simplify things a bit and leave off the FilesMatch Directive. In that case, to enable the parsing of .html files for embedded PHP code, just add this AddHandler directive to the .htaccess file:

Code: [Select]
AddHandler "proxy:unix:/usr/local/php73/sockets/xtlbzcrj.sock|fcgi://localhost" .html
Thanks again for your assistance in answering my question.

Paul
Title: Re: Using PHP Within HTML Files
Post by: SE-JAY on July 10, 2019, 12:15:55 PM
Winner winner, chicken dinner!!!

Thank you for figuring this out.  I would have never gotten this to work without your assistance.

If anyone needs to do this in the future, you can actually simplify things a bit and leave off the FilesMatch Directive. In that case, to enable the parsing of .html files for embedded PHP code, just add this AddHandler directive to the .htaccess file:

Code: [Select]
AddHandler "proxy:unix:/usr/local/php73/sockets/xtlbzcrj.sock|fcgi://localhost" .html
Thanks again for your assistance in answering my question.

Paul

Sweet.

Just remember to replace xtlbzcrj with your own DA user ID and leave a note, so I can make changes to individual php-fpm configs.

All the best :)
Title: Re: Using PHP Within HTML Files
Post by: pabws on July 10, 2019, 06:20:35 PM
Thank for the reply.  I didn't notice that "xtlbzcrj" in the string was actually my user id.

So clarify things for anyone else who wants to do this, they need to

1) add the AddHander code and in that code, change the "xtlbzcrj" to their id

and
 
2) send you a note requesting that you update their individual php-fpm configuration.

Please confirm that is correct.

Thanks again. Paul
Title: Re: Using PHP Within HTML Files
Post by: SE-JAY on July 10, 2019, 07:08:10 PM
Perfect tutorial! I am actually bookmarking this for future reference.

Thank you Paul.