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>
Related
I just installed phpdocumentor, but received strange errors. I finally tracked down the problem.
Phpdocumentor creates various files such as someFile.php.txt which contains PHP code, but aren't meant to be parsed. Turns out, my server is parsing them. I've also tested a file name called someFile.txt, and it isn't being parsed.
How do I prevent my PHP server from parsing files such as someFile.php.txt?
My server is PHP Version 5.4.20, Apache 2.2.15, and CentOS 6.4. My /etc/httpd/conf.d/php.conf file is as follows:
#
# 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 worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
It turns out that the default settings of CentOS Apache actually allow this and it is a known vulnerability. In order to fix it, you will need to edit your Apache config settings. Your PHP settings are typically in /etc/httpd/conf.d/php.conf. The default looks like this
AddHandler php5-script .php
AddType text/html .php
We need to change it to
#AddHandler php5-script .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
Restart Apache and that should be the end of parsing any file with an extension after .php
Now, that $ is very important because this is using regex and within regex a $ means "end of string". So that means the file has to END with .php (i.e. no .php.txt) to be parsed by PHP.
I'm having the same problem on CentOS 6.5, and I needed to fix this in a virtual environment where I don't have access to php.conf.
I used the following in a .htaccess file.
# Match anything that ends with .php.txt
<FilesMatch \.php\.txt$>
RemoveHandler .php
ForceType text/plain
</FilesMatch>
I don't allow uploads by users, so I'm not worried about any security implications. I just wanted to get the .php.txt extension working. This did the trick.
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!
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.
I just installed phpdocumentor, but received strange errors. I finally tracked down the problem.
Phpdocumentor creates various files such as someFile.php.txt which contains PHP code, but aren't meant to be parsed. Turns out, my server is parsing them. I've also tested a file name called someFile.txt, and it isn't being parsed.
How do I prevent my PHP server from parsing files such as someFile.php.txt?
My server is PHP Version 5.4.20, Apache 2.2.15, and CentOS 6.4. My /etc/httpd/conf.d/php.conf file is as follows:
#
# 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 worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
It turns out that the default settings of CentOS Apache actually allow this and it is a known vulnerability. In order to fix it, you will need to edit your Apache config settings. Your PHP settings are typically in /etc/httpd/conf.d/php.conf. The default looks like this
AddHandler php5-script .php
AddType text/html .php
We need to change it to
#AddHandler php5-script .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
Restart Apache and that should be the end of parsing any file with an extension after .php
Now, that $ is very important because this is using regex and within regex a $ means "end of string". So that means the file has to END with .php (i.e. no .php.txt) to be parsed by PHP.
I'm having the same problem on CentOS 6.5, and I needed to fix this in a virtual environment where I don't have access to php.conf.
I used the following in a .htaccess file.
# Match anything that ends with .php.txt
<FilesMatch \.php\.txt$>
RemoveHandler .php
ForceType text/plain
</FilesMatch>
I don't allow uploads by users, so I'm not worried about any security implications. I just wanted to get the .php.txt extension working. This did the trick.
I have the following php file:
<html>
<body>
<?php
echo "test";
?>
</body>
</html>
My httpd.conf file has the following entry:
grep php /var/apache/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
Why would the file always be downloaded and not loaded in the browser?
You also need to set the correct content handler / MIME-type for .php files. The default Ubuntu php configuration contains:-
<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>