Hi I am trying to view a .PHPS source file on Ubuntu 20.04.3 Apache 2.4.41 PHP 7 server but when I view the .phps file in the browser I get this message -
403 Forbidden You don't have permission to access this resource.
If I rename the file type to .txt I can view the file fine in the browser.
I’ve added the following to .htaccess -
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
And I tried adding that to /etc/apache2/sites-enabled/demo.testsite.com-le-ssl.conf but it didn’t work.
I then updated this file /etc/apache2/mods-available/php7.3.conf and commented out Require all denied and also added Order Deny,Allow and Deny from all -
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
#Require all denied
Order Deny,Allow
Deny from all
</FilesMatch>
I then restarted apache sudo service apache2 restart and I still get this message in the browser when viewing the PHPS file -
403 Forbidden You don't have permission to access this resource.
Has anyone got any idea how to fix?
update 2022/05/15
For some reason I am getting 403 Forbidden again. My only guess why is because I did some updates (sudo apt update and sudo apt upgrade). When I checked this file again /etc/apache2/mods-available/php7.3.conf the setting showed Require all denied so I changed it back to Require all granted.
I restarted both servives sudo service apache2 restart and sudo service php7.3-fpm restart and still 403 Forbidden.
When I search for .phps in the apache2 folder the same result appears in these files -
- /etc/apache2/conf-enabled/php7.3-fpm.conf
- /etc/apache2/conf-available/php7.3-fpm.conf
- /etc/apache2/mods-available/php7.3.conf
All have this inside -
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
Require all granted
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(ar|p|ps|tml)$">
Require all denied
</FilesMatch>
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
I've tried removing this from all those files but still not working -
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(ar|p|ps|tml)$">
Require all denied
</FilesMatch>
Any idea how to fix this?