I currently use the pre-fork MPM, which has been fine for my needs. However, I upgraded to the event MPM as an experiment and ran into an issue with PHP rending by html and shtml pages.
My pre-fork configuration of apache2.conf contains the following code:
#activate PHP <FilesMatch .php$> SetHandler application/x-httpd-php </FilesMatch>
and
#enable PHP rendering by html and shtml pages <Directory /var/www/> Options Indexes FollowSymLinks Multiviews Includes AllowOverride All Order allow,deny allow from all Require all granted AddType application/x-httpd-php .html .shtml </Directory>
So when I tried the event MPM, the FilesMatch code was no longer necessary and also caused a conflict. The AddType code caused a conflict as well and had to be removed.
At this point, a page with the .php extension will render PHP code, but one with the .html extension will not.
Is there a way to once again allow an html page to render PHP code?
Thanks
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
OK, I believe that I have found the answer to my own question.
First, Digital Ocean has a good tutorial for upgrading to event MPM at https://www.digitalocean.com/community/tutorials/how-to-configure-apache-http-with-mpm-event-and-php-fpm-on-ubuntu-18-04 (Note: Just change all the references to php7.2 with the current php8.1.
Here is something to keep in mind. The upgrade requires that you turn off the http/1 version of PHP. This will expose your php code to anyone who clicks on your site. So it is best that you take down your site before going forward with the upgrade.
Remove any conflicting code from your apache2.conf file or .htaccess file such as the following: AddType application/x-httpd-php .html .shtml
Now, say that your goal is to allow html and shtml files to parse php.
Go to the following file: sudo nano /etc/php/8.1/fpm/pool.d/www.conf
Add this line of code: security.limit_extensions = .php .html .shtml
Reload php fpm: sudo service php8.1-fpm reload
Next, add the following line of code to either apache2.conf or to your .htaccess file:
<FilesMatch .html|shtml$> SetHandler “proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost” </FilesMatch>
You may need to restart apache. That should take care of it.