Overview
I’m trying to host a few legacy PHP apps on Heroku with Apache. They all relied on the following deprecated syntax to parse any unknown file types (without the .php
extension) as PHP.
DefaultType application/x-httpd-php
This has been replaced by AddType
in Apache 2.4 (Heroku currently uses v2.4.37). Heroku also uses mod_proxy_fcgi
to process PHP files via fcgi://heroku-fcgi
.
Issue
I have a file foo.test
and I want to have it handled by PHP FPM. Taking cues from the docs and the default Apache config provided by Heroku, here’s what I’ve tried:
# .htaccess
<FilesMatch .test$>
<If "-f %{REQUEST_FILENAME}">
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
# apache_app.conf (properly loaded via Procfile)
ProxyPassMatch "^/(.*.test(/.*)?)$" "fcgi://heroku-fcgi/app/$1"
With both of these I get a plain-text 403 Access denied.
response from PHP FPM. I’m sure both configs are properly loading and pointing to the FCGI handler because changing the endpoint results in other errors.
My Apache skills are long since rusty and I can’t seem to find any good pointers online. The Apache error log is also clean. Any ideas (without the obvious “change all extensions to PHP, you dumbass”) would be appreciated!
2
Answers
Fairly obvious solution. PHP FPM has its own configuration with a
security.limit_extensions
flag. It defaults to.php
.The solution was to unset that value:
security.limit_extensions =
. This naturally can pose some security threats, but these apps are only going up for static demo.I was using
heroku/heroku-buildpack-php
but forked that to update this file. Thehtaccess
FilesMatch
should work now but I just ended up placing it into the Apache config file to avoid repetition across the sites I'll be serving.security.limit_extensions can be customized with a configuration file passed as a Procfile argument.
https://devcenter.heroku.com/articles/custom-php-settings#php-fpm-settings
So you can set up it like the following
Procfile
apache.conf
fpm_custom.conf