Apache downloading php files instead of executing them - php

I am trying to install phpmyadmin in my Ubuntu Server and when I try to access via browser to it, a php file downloads instead of displaying the web page. I placed a phpinfo testfile in /var/www and it is working fine.
I have already commented lines in php5.conf file:
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<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
Order Deny,Allow
Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Order Deny,Allow
Deny from all
</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_value engine Off
# </Directory>
#</IfModule>
I am using Apache/2.4.6 and Ubuntu Server 13.10

If you installed phpmyadmin as application, then try to download source code from official website and run it manually (copy into your directory /var/www and add VirtualHost settings in apache config ) It's easier than try to decide your issue.

Related

PHPS source file - 403 Forbidden You don't have permission to access this resource

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?
Apache 2.4 has deprecated the Allow,Deny syntax. Replace
Order Deny,Allow
Deny from all
with
Require all granted
and then restart Apache.
Edited to add: Even when you're using the Allow,Deny syntax, Deny from all without an Allow statement later would, as you'd expect, deny all access to the resource in question.
References
Apache 2.4 access control docs

PHP in userdir not working

My /etc/apache2/mods-enabled/userdir.conf file looks like:
<IfModule mod_userdir.c>
UserDir /var/zpanel/hostdata/*/public_html/
UserDir disabled root
<Directory /var/zpanel/hostdata/*/public_html/*>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch
<Limit GET POST OPTIONS>
# Apache <= 2.2:
Order allow,deny
Allow from all
# Apache >= 2.4:
# Require all granted
</Limit>
<LimitExcept GET POST OPTIONS>
# Apache <= 2.2:
Order deny,allow
Deny from all
# Apache >= 2.4:
#Require all denied
</LimitExcept>
</Directory>
</IfModule>
And file /etc/apache2/mods-enabled/php5.conf
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<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
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
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 /var/zpanel/hostdata/*/public_html/*>
# php_admin_value engine On
# </Directory>
#</IfModule>
But php not working when in accessing web site via userdir.
www.example.com/~admin
When i access via domain then it works. I have zPanel installed
Server version: Apache/2.4.18 (Ubuntu)
In my /etc/apache2/mods-available/php7.0.conf I have this section
# 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 think now you know what to do.
Try the following actions:
Make sure mod_userdir is enabled (a2enmod userdir).
The $HOME and public_html dirs have the right read permissions.
sudo -Hu SOMEUSER sh -c 'chmod 755 $HOME $HOME/public_html'
Make sure php_admin_value engine is On.
sudo vim /etc/apache2/mods-enabled/php*.conf
Then find the line containing php_admin_flag and change it to:
php_admin_flag engine On
This is due that PHP is disabled by default for user dirs for Apache 2.
In your particular case, you've to uncomment the following lines:
<IfModule mod_userdir.c>
<Directory /var/zpanel/hostdata/*/public_html/*>
php_admin_value engine On
</Directory>
</IfModule>
As mention by #kenorb, this is because PHP is disabled php_admin_value engine Off by default in userdirs for Apache2.
But instead of changing the php_admin_value engine to On in /etc/apache2/mods-enabled/php*.conf, it is advised in the .conf file itself that the lines starting from <IfModule> to </IfModule> be commented out, so that .htaccess can handle the setting separately. This can be done as shown below:
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>

php file wont run properly on my server that I just set up via Cyberduck

I've set up a local server with Vagrant via Cyberduck on my Mac. There seems to be no problem with running a file in general (I guess?) except for php file for some reason. It simply shows what I typed in, which is
<?php
echo "hello from Vagrant";
instead of saying hello from Vagrant
I also did sudo vi /etc/httpd/conf.d/php.conf and see what seems to be the problem that's causing this.
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule !prefork.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# The following lines prevent .user.ini files from being viewed by Web clients.
#
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
Satisfy All
</IfModule>
</Files>
#
# Allow php to handle Multiviews
#
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
# mod_php options
<IfModule mod_php5.c>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#<FilesMatch \.php$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
Also here's some quick info about my software version that I've used so far.
PHP 5.6.15
Apache 2.2.15
CentOS 6.7
Cyberduck 4.7.3
Anyone knows any solution to this? Thank you in advance!

apache2 keeps serving old versions of php files

as in the title, this problem still persist, i've configured a virtualHost in apache2(on Ubuntu 12.04 on OVH Dedicated server), i've put a simple index.php in the base directory of my VirtualHost that contains this simple code:
<?php
echo "Hello world! ";
?>
but when i update my file by adding or removing code, i chek it by accessing the url http://test.xxxxx.ma:8082, the update is not applied, i've cleared my browser cache, used a new browser, i've cheked if mod_cache is enabled but it's not and i'm sur i'm working on the right directory, the new version of the file index.php is only served after a restart of apache2, my VirtualHost configuration is as follow :
<VirtualHost *:8082>
DocumentRoot "/var/www/vhosts/xxxxx.ovh.net/test"
ServerName test.xxxxx.ma
<Directory "/var/www/vhosts/xxxxx.ovh.net/test">
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch +Indexes
allow from all
</Directory>
</VirtualHost>
try adding
# Disable Caching for Scripts and Other Dynamic Files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
in a .htaccess file

php to html request without changing browser url

My site is working with .html extension in the URL. However i want to change it to .php. But pages are not working. Is there any way that url is using .php extension and server is treating it as .html request
Most likely you don’t have Apache setup to parse PHP files. Unless I am missing what the question is? You want too rename the .html files to .php and still have them work?
By default in Ubuntu 12.04 PHP is enabled via the php5.conf file in mods-available that should look like this.
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# 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_value engine Off
</Directory>
</IfModule>
</IfModule>

Categories