Free, NO advertisement, Unlimited Web Hosting
Unlimited Disk Space + Bandwidth
Feature Packed - MySQL Databases, Email Accounts, Auto Script installer and more!
Use your own domain! Don't have your own domain? Get a free one. Click here
Amazing Support + Friendly Community
Script Installer -> Scripts ready to get installed! Build an Awesome Website with 0 coding skill! Click here to see complete lists

CLICK HERE TO ORDER SHARED HOSTING! $0/mo CLICK HERE TO ORDER RESELLER HOSTING! $0/mo

Using PHP Within HTML Files

  • 8 replies
  • 292 views
*

Offline pabws

  • *
  • 7
  • +0/-0
  • Paul
Using PHP Within HTML Files
« 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
« Last Edit: July 10, 2019, 12:58:02 AM by pabws »

*

Offline SE-JAY

  • *****
  • 472
  • +12/-1
Re: Using PHP Within HTML Files
« Reply #1 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.

*

Offline pabws

  • *
  • 7
  • +0/-0
  • Paul
Re: Using PHP Within HTML Files
« Reply #2 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.

*

Offline SE-JAY

  • *****
  • 472
  • +12/-1
Re: Using PHP Within HTML Files
« Reply #3 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>
« Last Edit: July 10, 2019, 03:16:35 AM by SE-JAY »

*

Offline SE-JAY

  • *****
  • 472
  • +12/-1
Re: Using PHP Within HTML Files
« Reply #4 on: July 10, 2019, 11:32:32 AM »
Hi, following up on this.

Please let me know if it worked for you.

*

Offline pabws

  • *
  • 7
  • +0/-0
  • Paul
Re: Using PHP Within HTML Files
« Reply #5 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

*

Offline SE-JAY

  • *****
  • 472
  • +12/-1
Re: Using PHP Within HTML Files
« Reply #6 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 :)

*

Offline pabws

  • *
  • 7
  • +0/-0
  • Paul
Re: Using PHP Within HTML Files
« Reply #7 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

*

Offline SE-JAY

  • *****
  • 472
  • +12/-1
Re: Using PHP Within HTML Files
« Reply #8 on: July 10, 2019, 07:08:10 PM »
Perfect tutorial! I am actually bookmarking this for future reference.

Thank you Paul.