Running php file asks for download instead of executing in apache 2.5?

2.9k views Asked by At

I have a windows7 64bit, I tried to run php and my IE browser was asking me for to download the file instead of executing it. Someone told me to download apache, so i downoaded wamp2.5-32bit version, installed it well, and also chose Firefox as default for wamp. But still when I double click php files in www directory of wamp, firefox asks me to download it instead of running it.

I have tried adding these lines in httpd.conf but no change;

LoadModule php5_module "c:/wamp/bin/php/php5.5.12/php5apache2_4.dll"
#PHPIniDir c:/wamp/bin/php/php5.5.12

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps
AddType text/html .php
LoadModule php5_module        modules/mod_php55.so

This wamp option also seems like a tag of war, I am going around editting notepad files and its now lots of hours gone. Is there another option?

2

There are 2 answers

3
Fl1p On

Did you check the PHP-server is running? Apache can run, but PHP is another service. Right click on the WAMP icon in you taskbar en check that. Good luck!

0
RiggsFolly On

Matt,

If you look through httpd.conf you will find all of those lines you say you have added already exist in there proper place already.

Assuming you have also done some other changes you have forgotten about or not mentioned I would suggest you Uninstall WAMPServer (using the standard windows uninstall mechanism )

Then manually delete c:\wamp as any files you have edited will not be removed by the uninstall.

Now reinstall WAMPServer.

Once you have a fresh install and WAMPServer's wampmanager icon is green enter this in your browser.

http://localhost

If you see the WAMPServer homepage then PHP is working, as this page is written in PHP.

Now you say you are double clicking a filename in the \wamp\www folder, by this I assume you mean you are using Explorer and double clicking a filename! DONT DO THAT That will just launch this file in the browser but will not run the file through Apache. That method is ok if you just have a HTML & Javascript page, but it will not compile and run a PHP script.

To get a PHP script to run you must run the page through Apache so it can spot the <?php tag. Apache then knows to pass the script through PHP so it can be interpreted and executed.

So to make this happen you enter the url into the browsers address bar like you would to launch the StackOverflow page like so :-

localhost/project1/text.php