My apache runs php files with or without .php extension, How can I disable this and force apache to run php files only with .php extension. I don't want to use .htaccess, this might be an apache config. does anyone know how to disable this option?
Thanks for the answer but using Addtype as you mentioned did not ever work for me, all by itself, even in PHP 5..
Here's what I've tried that DOESN'T work with this version of PHP:
Options +ExecCGI
AddType application/x-httpd-php .php .nusuffix
AddHandler x-httpd-php5 .php .nusuffix
This worked for PHP 5. Now, does not.
This is for a hosted account, so I must do this via .haccess.
You can check your httpd.conf what extensions are configured, it need need to be following. if there is change in your file you can change it to following and restart the apache
AddType application/x-httpd-php .php
more details : https://wiki.archlinux.org/index.php/Apache_HTTP_Server
please add if anything is missing
Related
Recently I configured Apache 2.2 server to run PHP and have configured to load PHP 5 as a module. I am able to start Apache with no problems but when I try to run PHP files it pops up would you like to open or save file?
Running on Windows XP SP3
Internet Explorer browser but not related
Simply trying to open it as a file not as my index.php and haven't set Apache to look for that as my index. If it helps I think my issue might be here:
;AddType application/x-httpd-php .php
;AddType application/x-httpd-php .php5
;AddType application/x-httpd-php .phtml
I tried to modify in my Apache conf file addtype and addhandler but no change and apache still starts both ways.
I tried putting these inside the mime configuration part and outside of it same both ways but not sure where in doc that should go my loadmodule part is also entered.
Im not sure but the only other place i could see being an issue would be in my php.ini file to which i have made no modifications.
Can someone point me in the right direction? What I am missing here?
Edit httpd.conf and add (or remove the ; at the begin of line):
# PHP 5.x module
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html .php
# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):
AddType application/x-httpd-php-source phps
I don't know, but I think you need to restart the Apache.
From http://dan.drydog.com/apache2php.html (step 11)
I wanted to change the .php extension to .foo, to hide it for visitors.
My webserver has cPanel installed, so I logged in and clicked on "MIME Types", and entered the following:
MIME Type: application/x-httpd-php
Extension: foo
The problem is that it's not being parsed as PHP, but instead is downloaded (when you click the link, a file containing all the code of that file is being downloaded)
How would I solve this?
Add in httpd.conf or vhost.conf
<IfModule mime_module>
AddType application/x-httpd-php .foo
</IfModule>
But best way to solve you problem is in using mod_rewrite
If you have the necessary AllowOverride permissions to use .htaccess, try
AddHandler application/x-httpd-php5 .php .foo
For some reason our CentOS server needs x-httpd-php5, where as our WAMP internal server just uses x-httpd-php like you have (and -php5 will not work)
I have a CPanel based website and we used the above rule to set .html to be parsed as php, didn't even bother with the CPanel Mime settings... but there are other ways to determine if a server is running PHP so you're not really hiding that you use PHP from anyone who knows what they are doing
can't for the life of me work out why this isn't working - on a dreamhost server, I've created an htaccess file and added AddHandler php5-cgi .html .htm to allow php in html files, as per the dreamhost docs. On an identical dreamhost package, I've done the same thing for another site and it worked perfectly, but in this case it just won't parse the php! Is there anything I could have missed here which could be causing the problem? The htaccess is in the web root and isn't being overridden by anything else.
Try this
AddType application/x-httpd-php .html .htm
The above setting will work if the apache is picking php as a module.
AddHandler application/x-httpd-php .html .htm
or
AddHandler application/x-httpd-php5 .html .htm
above will work if apache is executing php as CGI?
there is no harm i would say to put both of the above conditions together but try one over other and see if it work for you.
read more here in this article I wrote.
Is your server using suPHP rather than mod_php or plain php-cgi?
Try using
AddHandler x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
instead.
Postscript
Shared Hosting services use UID based separation on individual accounts from each others. Most use suPHP, but some use suEXEC. They will use one of these. Both act as a su wrapper around php-cgi so you can't tell from the phpinfo()as its PHP scripting engine as this will report Server API CGI/FastCGI in both cases. For CGI initiated scripts, phpinfo doesn't report on the Apache config. You need either to look at your hosting provider's FAQ or possibly try:
<?php
header( "Content-Type: text/plain");
echo system('grep -iR LoadModule /etc/httpd /etc/apache2');
The hosting provider's support forums / FAQ might give specific configuration advice here. Have you tried them?
I've got the same problem as you but I just put this AddType php .html .htm to my .htaccess, it's working.
For me it is working for only like this:
AddHandler php-cgi .php .htm
I'm running XAMPP.
Is there a line I can add to .htaccess or http.conf to make ASP be parsed and handled as PHP pages?
I had it setup before but can't remember how to do it. What I've tried so far hasn't worked.
Edit: None of these solutions are working, I've tried everything.
If none of the solution above is ok with you, check your Server API with phpinfo(); method.
If Server API is CGI or FAST CGI change it to Apache 2.0 Handler.You can do it using Plesk Panel or CPanel.
Another option is not to change Server API but .htaccess or httpd.conf : http://avinashsing.sunkur.com/2012/04/19/how-to-map-another-file-extension-to-the-php-parser-through-htaccess/.
But I have solved my problem with the first one.
Maybe try this:
AddHandler php5-script .php .asp .aspx .ascx .ashx .asmx
AddType text/html .php .asp .aspx .ascx .ashx .asmx
Add this to your httpd.conf
AddType application/x-httpd-php .asp .aspx .ascx .ashx
Try adding this line to .htaccess;
AddHandler application/x-httpd-php .asp
Apparently it is not as efficient as adding the equivalent to http.conf but it works even when you don't have access to http.conf.
Adding this line in .htaccess enabled me to execute PHP code written in .asp pages:
AddHandler php5-script .php .asp
Apache does not have a module for ASP processing. You have to use IIS for that. Modern IIS can run PHP so you may do it the other way around, use IIS and plug PHP into it.
I enabled PHP5 on my website and my webhost needs me to add the following to .htaccess files for PHP5 to work:
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
Locally, I am running XAMPP to develop code, but XAMPP does not want to work with the .htaccess file above.
I think it is an issue with XAMPP not recognizing php5 (but it does recognize php if I use "application/x-httpd-php" instead of "application/x-httpd-php5")
How do I resolve this?! I need the .htaccess files to look like above so they work with my webhost, but I need XAMPP to work locally with the same files without making changes!
Apache has <IfDefine> directive. You can use it to hide AddType from your own server:
<IfDefine !MyServer>
AddType application/x-httpd-php5 .php5 …
…
</IfDefine>
And start apache with
apachectl -D MyServer
So, you're in kind of a tough place; ideally speaking your webhost should not need you to put extra gunk in your htaccess files. Not knowing XAMPP too well, I can't offer a specific solution, but I can give you some pointers:
Your webhost is running a custom compiled version of PHP that uses application/x-httpd-php5; while it is totally possible to build PHP yourself or find a custom build that has the SAPI layer configured appropriately, you probably don't want to do this.
Depending on how much leeway your host is giving htaccess files, it may be possible to use <IfDefine> or <IfModule> to only conditionally execute the PHP fudge code. I haven't tested, and your webhost may have disabled this functionality. Also, you will have to find an appropriate conditional to test against.
My favorite answer would be to suck it up, and maintain separate htaccess files. I do this on my website; I have a .htaccess.in file which contains "global" declarations, and an htaccess.php file which generates the real .htaccess file based on configuration, etc.
Hope that helps.
Another simple solution: change the config file name at home. E.g. in httpd.conf:
<Directory />
#existing stuff here...
AccessFileName .htaccess.home
</Directory>
Now your home server will ignore your ".htaccess" files. You'll configure it with ".htaccess.home" files.