Created
November 28, 2019 02:43
-
-
Save u1735067/8e93cf79d9d879a8402ca16fcb3fec23 to your computer and use it in GitHub Desktop.
Apache 2.4 conf to display .phps (or any file type marked with handler `application/x-httpd-php-source`) as highlighted, like with mod_php. Thanks VBart for the original nginx idea (Apache is a bit more tricky ..). There's 2 files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### PHP-FPM Source (.phps) type handler ; conditions are taken from CentOS8 php.conf | |
# https://stackoverflow.com/questions/11085086/php-fpm-is-parsing-phps-instead-of-showing-code-hilighted | |
<IfModule !mod_php5.c> | |
<IfModule !mod_php7.c> | |
<Directory "/real/path/to/"> | |
Require all granted | |
# https://httpd.apache.org/docs/2.4/en/expr.html | |
<If "%{REQUEST_URI} == '/php-fpm/highlight.php'"> | |
Redirect 404 | |
</If> | |
</Directory> | |
ScriptAlias "/php-fpm/highlight.php" "/real/path/to/highlight.php" | |
Action "application/x-httpd-php-source" "/php-fpm/highlight.php" | |
</IfModule> | |
</IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
if ($_SERVER['REQUEST_URI'] === $_SERVER['SCRIPT_NAME'] | |
|| $_SERVER['REDIRECT_HANDLER'] !== 'application/x-httpd-php-source' | |
|| !array_key_exists('PATH_TRANSLATED', $_SERVER)) { | |
throw new Exception(); | |
} | |
highlight_file($_SERVER['PATH_TRANSLATED']); | |
} catch (Exception $e) { | |
http_response_code(403); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment