2

Wanting to use DDEV for local development, and I have a site with legacy content needing to run php on pages with .html extension. With other testing environments I have used different lines in .htaccess to enable this. With my ddev test environment I can't yet figure what works.

UPDATED Here are the lines I've tried (uncommenting singly or in combo) in .htaccess:

#AddType application/x-httpd-php .html .htm
#AddHandler application/x-httpd-php .htm .html

#AddType application/x-httpd-php7 .html .htm
#AddHandler application/x-httpd-php7 .htm .html
    
#AddHandler x-httpd-php .htm .html
#AddType x-httpd-php .html .htm
    
#AddType x-httpd-php7 .html .htm
#AddHandler x-httpd-php7 .htm .html

#AddType x-httpd-php73 .htm .html
#AddHandler x-httpd-php73.htm .html
#AddHandler x-httpd-php7-3 .htm .html
      
#AddType application/x-httpd-php73 .html .htm
#AddType application/x-httpd-php7-3 .html .htm
#AddHandler application/x-httpd-php7-3 .htm .html

I also tried updating the .ddev/apache/apache-site.conf with something like:

<FilesMatch ".html$"> 
SetHandler "proxy:fcgi://php:9000" 
</FilesMatch> 

or

<FilesMatch ".+\.html$"> 
SetHandler applicaiton/x-httpd-php 
</FilesMatch> 

but admittedly this is not something I'm familiar with so probably not getting those quite right.

macOS Big Sur, ddev1.16.5 with php7.3, ddev webserver_type: apache-fpm.

Any suggestions? Thanks!

amos
  • 23
  • 4
  • 2
    You don't mention whether you're using `webserver_type: apache-fpm` in ddev. The default is nginx-fpm, which won't respect your .htaccess... – rfay Jan 11 '21 at 14:56
  • Thank you @rfay - I set webserver_type: apache-fpm, great catch. However, problem remains the same... I've tried: ` #AddType application/x-httpd-php .html .htm #AddHandler application/x-httpd-php .htm .html #AddType application/x-httpd-php7 .html .htm #AddHandler application/x-httpd-php7 .htm .html AddHandler x-httpd-php .htm .html AddType x-httpd-php .html .htm #AddType x-httpd-php7 .html .htm #AddHandler x-httpd-php7 .htm .html #AddType x-httpd-php73 .htm .html #AddHandler x-httpd-php73.htm .html ` – amos Jan 12 '21 at 14:07
  • I also tried updating the .ddev/apache/apache-site.conf with something like: SetHandler "proxy:fcgi://php:${APACHE_FCGI_HOST_PORT}" or SetHandler applicaiton/x-httpd-php but admittedly this is not something I'm familiar with so probably not getting those quite right? Also, the apache-site.conf is over written with ddev stop/start, so testing with "ddev exec apachectl -k graceful" after editing .conf, but should be able to have those changes stay? Thanks again! – amos Jan 12 '21 at 16:39
  • haha I saw the line to allow customizations of site.conf to stay! Clearly I'm still getting oriented... – amos Jan 12 '21 at 17:27

1 Answers1

2

The problem is that php-fpm is not configured to allow use of the .html file extension. This is configured in /etc/php/<version>/fpm/pool.d/www.conf.

So you have two things to do to enable the behavior you're after, allowing PHP interpretation of HTML files.

  1. Allow processing html files in the php-fpm configuration, in pool.d/www.conf. You can do this using the answer in https://stackoverflow.com/a/65693405/215713
  2. Allow processing html files in the apache configuration. I'm sure there is more than one way to do it, and you may be able to do it in .htaccess, but I did it by adding this stanza the port 80 virtualhost in .ddev/apache/apache-site.conf (and of course removing the #ddev-generated at the top of the file):
 <FilesMatch ".+\.(html|ph(ar|p|tml))$">
      SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost"
  </FilesMatch>
rfay
  • 9,963
  • 1
  • 47
  • 89
  • 1
    Thank you @rfay that works! Took a while to get back to this but now excited to switch over to ddev! – amos Mar 30 '21 at 20:14