Everything was going great until I added AddHandler application/x-httpd-php5s .php to the .htaccess file in my local server's document root (which I change frequently depending on the site I'm working with). Since I did that when I visit http://localhost:8888 my browser just downloads the index.php and it's not processed at all, just the raw code. Now I removed that line from the .htaccess file but I'm still having this problem.
I've found that if I add an alternative entry to my hosts file for 127.0.0.1 the new entry behaves like 'localhost' used to. But if I add the line above to my .htaccess it knocks out that new host as well. I've tried reinstalling MAMP and clearing its caches and all the temporary files I could find. I surfed through Apache's httpd.conf file all to no avail.
So, to be clear: http://localhost:8888 is experiencing the above problem. If I add a new entry to my hosts file for 127.0.0.1, say 'goomba' and the above line is not in the root .htaccess (and has never been for that host/alias/whatever) then I can access http://goomba:8888 just fine. But if I do add that line to the .htaccess then I have to add yet another entry to my hosts file to get around it even if I remove that line from the the .htaccess file.
I'm fine with using a different 127.0.0.1 alias (host? what is that called?) but it's bugging me that this is still broken.
Just to be clear, I'm on Mac OS Leopard (but I'm not using the built in Apache setup, but MAMP).
I've had a similar issue a couple times and renaming the file did not work for me. With OS X Lion I found the right configuration is this:
<IfModule php5_module>
AddType application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
</IfModule>
The magic that made it work for me is the SetHandler application/x-httpd-php part.
Of course edit the <IfModule php5_module> to your php version.
You are applying a mimetype where a handler should be (see documentation on handlers)
Try this instead:
AddType application/x-httpd-php5 .php
EDIT:
As you have indicated caching modules are loaded, you could read up on caching and htcacheclean (to clear the disk cache). You can also temporarily use the CacheDisable directive. One other thing that you could also try is to rename the file that you have requested (e.g. index.php -> index.bak), request the file again in the browser (should now 404), then revert and try again.
Just note, make sure you don't have a htaccess file from your live environment accidentally downloaded with other files. Additionally, make sure you match your PHP version when editing htaccess. Wrong version cause same issue-wrong settings.
Here is an example for running PHP7:
application/x-httpd-ea-php71 .php .php7 .phtml
I hope this info can help - it happened to me 8 years after ticket is created :)
If someone has again this kind of issue, do something most important firstly. I mean, use private navigation (without cache).
I wasted my time because of this.
GLHF
Perhaps you want application/x-httpd-php5 instead of application/x-httpd-php5s? (Note the lack of an s at the end.)
in my case deleting or comment out "AddHandler php56-cgi .php" in my root's involved htacces files solved it
Best
For the same issue, i removed the '5' AddType application/x-httpd-php .php .htm .html
its working fine! try
I had the same issue and it was because inside this folder you have .htaccess file hidden with some custom code, for me was because I copy from my running website server. Try to rename the file and you will see your project. Then customise the file in your needs.
First check if your apache server is running. Start->Run->cmd and then execute command:
netstat -abn
Lookup the result for line like this:
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING 600 [apache.exe]
If you cant find anything listening on port 8888 ( no 0.0.0.0:8888 line) then your apache is failing to start. To find out why it cant start you should find apache log directory and examine the error.log (may be you have updated your php resently?). If you find 0.0.0.0:80 listening line but some other software is listening there (do you have IIS running?) then you should remove / reconfigure that softure to free port 80. If you have apache listening on port 80 but still cant open your site and you cant figure out what is causing the problem via examining apache log files then it my be database problem. Check if your mysql is running and listening using same command but you should be looking for
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING [mysqld-nt.exe]
If you cant find such line then your mysql server is not running - check mysql log files for errors. If both servers are running and you cant get any output in your browser then check your firewall and antivirus - they may block your requests. Hope this helps ;)
I actually had a very similar issue. All of my php files were downloading when I tried to test if php and apache were working together. It turns out they weren't working together.
I had to uninstall php, I would recomend the same course of action and then reinstalling php just using the zip file download on php.net, instead of installing it with MAMP. I think my problem was that I had used the php installer. I do not recomend using that.
This website helped me a lot, I was having an issue with apache not starting and while that is not your issue, this website solved both the apache not starting and the downloading of php files issue and even though you are on a mac it may help you as well http://forums.phpfreaks.com/topic/185771-problem-starting-apache-2214-after-installing-php-5212
Hope everything works! Good Luck!
Just remove the comment
<IfDefine PHP>
LoadModule php_module modules/libphp.so
</IfDefine>
in etc/extra/httpd-xampp.conf
In my case after cloning a repo and trying to set the project up i hade to run composer update to install the all dependencies and then it open the page instead of downloading the file
Related
I am moving from a server with PHP 5 to a new server with PHP 7, and I am having issues to tell Apache to parse .html as PHP scripts.
In my .htaccess file I have this line working correctly on my current server with PHP 5:
AddType application/x-httpd-php .html
But on the new server, that directive makes any .html file being downloaded instead than executed as a PHP script.
I know that on the current server with PHP 5 installed, PHP is configured with API set as "Apache 2.0 Handler" whereas on this new server it is configured as "FPM/FastCGI" and I guess that maybe that's the problem? If so, how can I overcome it without having to change that API setting?
I look forward to hearing from you. Thank you in advance for any help!
After hours of research, I ended up reading this page:
https://www.digitalocean.com/community/questions/php-fpm-security-limit_extension-issue
And I fixed the problem by adding this code inside .htaccess:
<FilesMatch ".+\.html$">
SetHandler "proxy:unix:/run/php/php7.0-fpm-[myhostname].sock|fcgi://localhost"
</FilesMatch>
And to avoid the server to give me an 'access denied' error I had to put this line inside /etc/php/7.0/fpm/php-fpm.conf:
security.limit_extensions = .php .htm .html .inc .rss .rdf .xhtml
Then restarted PHP daemon with:
service php7.0-fpm restart
Now everything seems to work fine! Quite complex I'd say, and I think that'd due to the fact PHP is configured with the FPM/FastCGI API.
Comments and thoughts are welcome!
Thanks again to everyone.
My problem started when I was working with the .htaccess file to a directory trying to get php to run inside of html files. I tried ALOT of combinations of AddTypes and AddHandlers. I took them out and now my php files are being downloaded by the broswer instead of running. There are a few other questions on here that I have studied up and down, but they are not exactly my problem.
I'm fairly lost now, I've tried just about every combination of AddType and AddHandler. I've since decided to use mod_rewrite and just have all my files end in .php but I can't get them to run.
This is what I'm using to test:
<!DOCTYPE html>
<body>
<?php
echo("php working");
?>
</body>
</html>
Am I missing something? Luckily I made all my changes at a separate directory than the root so that the site still runs, but none of the php files in that folder can be viewed in broswer. What can I do? Any help is appreciated.
EDIT:
Just to make it clear, I was originally trying to be able to put php in my html files so I was messing around with handlers and addtypes. My server does have php. If I call a php script from a .html file, it runs. I just can't get a php file like the example I included above to open in brower ANYMORE, it used to open in browser. My fear is that I have messed something up by trying all the different handlers in .htaccess. I have since cleared my .htaccess file in hopes that would at least get me to square one, but it hasn't.
SECOND EDIT:
I went to the root directory and made a php file and it ran just fine so its definitely something I changed in the .htaccess for the particular directory. Is there anyway I can reset that directory?
have you made sure to install php correctly within apache?
if you are using php as a module, you need the following:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
or as a CGI binary
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
# For PHP 4
Action application/x-httpd-php "/php/php.exe"
# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"
other things to consider, are the permissions set correctly on the php binaries, is the php.ini present and correct, have you restarted apache since installing php into apache?
lastly, php doesnt run within html files, you would need to set the following as pretty much the last thing in the apache config
AddType application/x-httpd-php .html .htm
Do you see the line like this in your htaccess file?
php_flag engine off
If yes, delete it.
One more thing that may help you understand what happened
The following piece of htaccess would make Php from being executed but rather downloaded as a text file
<VirtualHost *>
ServerName sourcecode.testserver.me
DocumentRoot /var/www/example
AddType text/plain php
</VirtualHost>
One more thing
I'm guessing that this topic was addressed once here-> htaccess downloading file instead of loading
A friend's lamp host seems to be misconfigured. I try to execute php, but it doesn't seem to be working.
In Chrome's inspect element:
<?php echo 'test'; ?>
becomes :
<!--?php echo 'test'; ?-->
Furthermore, its been triggering a file download, rather than opening it as a webpage.
I've tried various code in an .htaccess file, but it doesn't seem to have any effect:
AddType x-mapp-php5 .php
AddType application/x-httpd-php .php
AddHandler x-mapp-php5 .php
The place to correctly configure PHP operation is the httpd.conf file, which resides in the conf subdirectory of your Apache installation directory.
In there, you'll want to look for the module loading section, which will be a bunch of lines that start with LoadModule. Somewhere in there, you should have the following (or something very similar):
LoadModule php5_module "location\of\your\php\installation"
AddType application/x-httpd-php .php
PHPIniDir "location\of\your\php\configuration\file"
I'm not all too familiar with Linux, but in Windows (WAMP) installations, those would be something along the lines of:
LoadModule php5_module "c:/program files/php/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/program files/php"
And the httpd.conf file, on my machine, is at C:\Program Files\Apache Group\Apache2\conf\httpd.conf.
It could also be that PHP is simply not installed at all on your machine, in which case, you will have to download it and install it. Brad's already posted the relevant link in one of his comments, (+1, by the way, Brad), but for the sake of having everything in one spot:
PHP: Installation and Configuration - Manual
Your Chrome is lying to you.
Your PHP source file is <?php echo 'test'; ?>. Because PHP is not executed, this file is sent to the browser. If the browser should interpret this text, it will stumble upon the <? ?> marks. They have a meaning - they are "XML processing instructions", and the text after the opening angle defines the target.
Obviously the browser does not know about a target named "PHP", so this text is ignored.
And then the element inspector tries to display the DOM and is lying about the original source code, because he is working on the PARSED source - which is great because you usually want to know on which data the browser acts, and this includes how the browser interpreted your source.
But if you make any error, the browser will try to fix it, and the fix is included in the element inspector.
Obviously the fix for an unknown XML processing instruction is to disable it by commenting it out.
This just happened to me. Turned out I had forgotten to change the filetype from .html to .php
Sounds to me that your PHP is not correctly configured or installed in your lamp configuration. What distribution are you using? It might be as simple as running a command to re-install PHP, otherwise you will likely need to compile apache with php support.
This answer doesn't apply to the OP's specific variant of this problem, but I had the basic same issue – <? var_dump($test); ?> being converted to <!--? var_dump($test); ?--> – which I could solve by enabling short_open_tag in php.ini.
I was faced with exact same problem when I accidently tried to test local php file in browser on server through file:// protocol, not through installed site.
So the answer is one: "Mr. PHP has left the building". We need to check the configuration, location of a file or access.
And browser is just trying to fix a web page and help us.
If you are placing your code outside the standard directories (development scenario, in my case) you should check in your /etc/apache2/mod-enabled or /etc/apache2/mod-available in the php5.conf (for ubuntu) and comment the lines that the comment indicates:
# 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>
Sounds like you are using an editor that is changing what you enter. Make sure that what you want in the file is what is actually in the file. Using FTP to upload a php file should ensure this.
I just solved this same problem.
You need to open your file from your WAMP, and not from your hard drive directrory.
In your browser, put: localhost/...../yourfile.php
Otherwise, your browser will replace all <?php ?>
with <!-- ?php ?-->
It seems you have to instruct apache explicitly to handle html files as php files, I was having the same problem but renaming the file to .php solved the issue for me.
On an Ubuntu system, installing the apache php5 plugin worked for me:
sudo apt-get install libapache2-mod-php5
sudo service apache2 restart
I have same problem sometimes, probably the extension of your file is "html".
Change It to "php" and it'll OK.
Everything was going great until I added AddHandler application/x-httpd-php5s .php to the .htaccess file in my local server's document root (which I change frequently depending on the site I'm working with). Since I did that when I visit http://localhost:8888 my browser just downloads the index.php and it's not processed at all, just the raw code. Now I removed that line from the .htaccess file but I'm still having this problem.
I've found that if I add an alternative entry to my hosts file for 127.0.0.1 the new entry behaves like 'localhost' used to. But if I add the line above to my .htaccess it knocks out that new host as well. I've tried reinstalling MAMP and clearing its caches and all the temporary files I could find. I surfed through Apache's httpd.conf file all to no avail.
So, to be clear: http://localhost:8888 is experiencing the above problem. If I add a new entry to my hosts file for 127.0.0.1, say 'goomba' and the above line is not in the root .htaccess (and has never been for that host/alias/whatever) then I can access http://goomba:8888 just fine. But if I do add that line to the .htaccess then I have to add yet another entry to my hosts file to get around it even if I remove that line from the the .htaccess file.
I'm fine with using a different 127.0.0.1 alias (host? what is that called?) but it's bugging me that this is still broken.
Just to be clear, I'm on Mac OS Leopard (but I'm not using the built in Apache setup, but MAMP).
I've had a similar issue a couple times and renaming the file did not work for me. With OS X Lion I found the right configuration is this:
<IfModule php5_module>
AddType application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
</IfModule>
The magic that made it work for me is the SetHandler application/x-httpd-php part.
Of course edit the <IfModule php5_module> to your php version.
You are applying a mimetype where a handler should be (see documentation on handlers)
Try this instead:
AddType application/x-httpd-php5 .php
EDIT:
As you have indicated caching modules are loaded, you could read up on caching and htcacheclean (to clear the disk cache). You can also temporarily use the CacheDisable directive. One other thing that you could also try is to rename the file that you have requested (e.g. index.php -> index.bak), request the file again in the browser (should now 404), then revert and try again.
Just note, make sure you don't have a htaccess file from your live environment accidentally downloaded with other files. Additionally, make sure you match your PHP version when editing htaccess. Wrong version cause same issue-wrong settings.
Here is an example for running PHP7:
application/x-httpd-ea-php71 .php .php7 .phtml
I hope this info can help - it happened to me 8 years after ticket is created :)
If someone has again this kind of issue, do something most important firstly. I mean, use private navigation (without cache).
I wasted my time because of this.
GLHF
Perhaps you want application/x-httpd-php5 instead of application/x-httpd-php5s? (Note the lack of an s at the end.)
in my case deleting or comment out "AddHandler php56-cgi .php" in my root's involved htacces files solved it
Best
For the same issue, i removed the '5' AddType application/x-httpd-php .php .htm .html
its working fine! try
I had the same issue and it was because inside this folder you have .htaccess file hidden with some custom code, for me was because I copy from my running website server. Try to rename the file and you will see your project. Then customise the file in your needs.
First check if your apache server is running. Start->Run->cmd and then execute command:
netstat -abn
Lookup the result for line like this:
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING 600 [apache.exe]
If you cant find anything listening on port 8888 ( no 0.0.0.0:8888 line) then your apache is failing to start. To find out why it cant start you should find apache log directory and examine the error.log (may be you have updated your php resently?). If you find 0.0.0.0:80 listening line but some other software is listening there (do you have IIS running?) then you should remove / reconfigure that softure to free port 80. If you have apache listening on port 80 but still cant open your site and you cant figure out what is causing the problem via examining apache log files then it my be database problem. Check if your mysql is running and listening using same command but you should be looking for
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING [mysqld-nt.exe]
If you cant find such line then your mysql server is not running - check mysql log files for errors. If both servers are running and you cant get any output in your browser then check your firewall and antivirus - they may block your requests. Hope this helps ;)
I actually had a very similar issue. All of my php files were downloading when I tried to test if php and apache were working together. It turns out they weren't working together.
I had to uninstall php, I would recomend the same course of action and then reinstalling php just using the zip file download on php.net, instead of installing it with MAMP. I think my problem was that I had used the php installer. I do not recomend using that.
This website helped me a lot, I was having an issue with apache not starting and while that is not your issue, this website solved both the apache not starting and the downloading of php files issue and even though you are on a mac it may help you as well http://forums.phpfreaks.com/topic/185771-problem-starting-apache-2214-after-installing-php-5212
Hope everything works! Good Luck!
Just remove the comment
<IfDefine PHP>
LoadModule php_module modules/libphp.so
</IfDefine>
in etc/extra/httpd-xampp.conf
In my case after cloning a repo and trying to set the project up i hade to run composer update to install the all dependencies and then it open the page instead of downloading the file
I'm trying to port a PHP site developed by another coder (who is no longer around) and I'm having a problem with the Apache Rewrite rules which are prompting a file download on the target server. I'm sure this is a simple problem, but I'm having some difficulty Googling an answer. I'm running on a (dedicated) Ubuntu Server with a standard installation of Apache and PHP5 and porting from shared a shared server where everything runs fine. No site files have been altered during the port.
The .htaccess file contains this code (only)
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
Options -Indexes FollowSymlinks
RewriteEngine on
RewriteRule ^html/(.*) /index.php?init=site\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9
RewriteRule ^mykart$ /index.php?admin=true
RewriteRule ^mykart/$ /index.php?admin=true
RewriteRule ^mykart/(.*)$ /index.php?init=admin\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9&admin=true
When I try to open the file http://www.mysite.com/html/#home the browser attempts to download the (index.php) file instead of displaying it, with the message
"You have chosen to Open
[dialog shows blank space here]
which is a: application/x-httpd-php
from....
"
I guess I must have missed something in either the PHP or Apache configuration, but what?
EDIT: To clarify, the server is running Apache2 and has several, functioning, PHP sites on it. Furthermore if I delete the .htaccess file and run a simple phpinfo display page everything runs fine, so it's not the execution of PHP per see.
I suppose that the MIME type application/x-httpd-php5 is not valid. I’ve tried it on my local machine and it caused the same behavior.
Have you tried application/x-httpd-php instead?
Looks like an Apache config issue, of course I could be wrong. Have you checked httpd.conf for the following lines:
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html php
I had a similar issue. Browser attempted to download links from php website, instead of loading them.
It wasn't Php interpreter issue for me, it turned out to be misplaced .htaccess file. However, I didn't realized that disabling the htaccess file solved the issue for hours, due to browser cache.
So, don't forget to clear your browser caches! And restart Apache.