Author Topic: PHP in html file config please  (Read 2166 times)

whiterabbitz

  • Newbie
  • *
  • Posts: 6
    • View Profile
PHP in html file config please
« on: September 09, 2018, 02:28:51 am »
Hi All.

Firstly great product - loaded 2 days ago without a hitch. From zero to ssl in 20 mins!

I am trying to have apache2 interpret .html with php embedded.

Why you may well ask.

Migrating a site for a friend from content manager adobe catalyst - expensive and slow.

The site is heavily indexed by google... so want to maintain the .html extensions. And broke it up ... header. footer and content using php includes so it was maintainable.


Scenario

ubantu 16.04

Primary domain mydomain,com

Only want php in html on devel.mydomain.com

Both running ssl

Usually I would put in .htaccess this:

AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html
Options Indexes FollowSymLinks Includes
AddHandler application/x-httpd-php .html


and away it goes.. but can't get it running with ehcp forced addition -

the page loads ok but the php is just text in the rendered output.

Have also tinkered with  /var/www/new/ehcp/apachehcp_subdomains.conf
 but no go ..

Any assistance would be appreciated.

WR





earnolmartin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 302
    • View Profile
Re: PHP in html file config please
« Reply #1 on: September 09, 2018, 11:35:13 pm »
Should be doable.  However, EHCP Force Edition doesn't yet support individual custom subdomain apache or nginx templates (other than the global subdomain template which can be changed here index.php?op=manageglobalwebtemplates)

Thus, for your scenario, I recommend adding the subdomain as a new domain under your account.  You would configure both "mydomain.com" and "devel.mydomain.com" as separate domains (do NOT create "devel.mydomain.com" as a subdomain in the panel under the "mydomain.com" domain).  Using this configuration, "devel.mydomain.com" is still technically a subdomain, but it is setup in the panel as a domain.  This will allow you to edit the custom apache2 template just for "devel.mydomain.com".  Log in as the admin user for the EHCP panel.  Select the domain you want to use a custom apache2 template for (in your case "devel.mydomain.com"), and then click on the "Edit apache2 Template" link.  Find this line (might be two or more instances if you're using SSL):

Code: [Select]
ProxyPassMatch ^(.*\.php)$ fcgi://127.0.0.1:9000{homedir}/httpdocs/$1

Change it to:

Code: [Select]
ProxyPassMatch ^(.*\.(php|html))$ fcgi://127.0.0.1:9000{homedir}/httpdocs/$1

Then, we need to allow php-fpm to process .html extensions (https://www.electrictoolbox.com/nginx-php-html-access-denied/).  So in the "/etc/php/7.0/fpm/pool.d/www.conf" file (differs depending on which version of Ubuntu you're on... could be in /etc/php5/fpm/pool.d/www.conf or /etc/php/7.x/fpm/pool.d/www.conf), add this line to the bottom:

Code: [Select]
security.limit_extensions = .php .html

Restart the php-fpm service (command differs depending on Ubuntu version):

Code: [Select]
sudo service php7.0-fpm restart

That should be it.  You never want to edit the EHCP template conf files directly (found in /var/www/new/ehcp), as any changes you make will be overwritten when the panel next syncs.  You want to use the custom template functionality in the panel to make sure your changes persist.  I hope this helps.  Please let me know.   ;D
« Last Edit: September 09, 2018, 11:38:29 pm by earnolmartin »

whiterabbitz

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: PHP in html file config please
« Reply #2 on: September 10, 2018, 12:17:28 am »
Hi,

Thanks so much for that.

I will give it a try tomorrow and let you know the results.

WR

earnolmartin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 302
    • View Profile
Re: PHP in html file config please
« Reply #3 on: September 10, 2018, 12:58:53 pm »
Actually, could you please try updating your panel to the latest dev SVN version (instructions here http://ehcpforce.tk/download.php#svn-version) and use the new custom subdomain web server template functionality?

After you've updated your panel, logout and login as admin, then select the domain you want to add a subdomain to (in your case "mydomain.com"), click on "Add Subdomain".  Add the "devel" subdomain.  Go back to the main domain management screen for "mydomain.com".  Click on "List Subdomains".  Click on the "Edit Template" icon for the "devel" subdomain. 

Replace the ProxyPassMatch lines with the following:

Code: [Select]
ProxyPassMatch ^(.*\.(php|html))$ fcgi://127.0.0.1:9000{homedir}/$1

Click on the "Save Template" button.

Now, make sure you follow the instructions I posted above to get php-fpm to process .html files.  It should work this way now too, and we now have custom subdomain template functionality (assuming I coded the functionality correctly, which from my initial testing, I hopefully did).

whiterabbitz

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: PHP in html file config please
« Reply #4 on: September 10, 2018, 03:17:05 pm »
You are a star!

Works .. with a small caveat.

Being a long term cynic.. been in IT too long.

1) Remove the pseudo  subdomain  devel.mydomain.com

2) Ran update

3) Added new subdomain devel.mydomain,com

4) Tested devel.mydomain,com - Ok

5) Modified index.php in devel.mydomain.com to make sure i was looking at the right file - all good

6) Made the modes - template and /etc/php/7.0/fpm/pool.d/www.conf

7) Re-tested devel.mydomain.com - file not found

8) Re Re tested devel.mydomain,com/index.php - ok

9) added index.html in devel.mydomain.com

10) and tested devel.mydomain.com  - ok showed content of index.html

11) Added <?php phpinfo(); ?>  to index.html - Worked like a charm!!

So Only issue - which I can live with, is that the .html is the default extension and .php must be specified.

Not a problem for this site

Thanks again




earnolmartin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 302
    • View Profile
Re: PHP in html file config please
« Reply #5 on: September 10, 2018, 04:23:59 pm »
Awesome, glad it worked.  Let me know if you run into any issues as a result of updating to the latest dev version.  These features will be released to the stable build soon.

You can always change the order of which page should load by default when a specific page hasn't been requested (usually the index file).  That also appears in the subdomain or domain templates.  You can re-order which index page loads by default and has a higher priority than the others (index.html vs index.php).  Just search for index.html in the custom template, and you should see the lines I'm talking about.

Thanks for testing it out.
« Last Edit: September 10, 2018, 04:28:13 pm by earnolmartin »