Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I recently installed Apache and later installed PHP too.

When I browse to http://localhost/index.html it displays the default Apache page "it works".

But when i try to run http://localhost/phpinfo.php it starts to get downloaded instead of running the PHP code

  • My Apache version 2.2
  • PHP Version 5.2.1
share|improve this question
1  
We can't see your localhost :) –  Marco Demaio Feb 7 '12 at 19:25

3 Answers 3

up vote 4 down vote accepted

Probably the server doesn't recognize the script as executable, and that's why it offers it as a downloadable file.

These lines should be present in your Apache config. Note that the path may need to be changed for the .so modules, depending on your configuration:

*nix:

# -- if you're using PHP 5, uncomment this line to activate it
LoadModule php5_module libexec/libphp5.so

# -- if you're using PHP 4, uncomment this line to activate it
#LoadModule php4_module libexec/libphp4.so

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps


Windows:

# -- assuming PHP 4
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Restart the Apache service and PHP should load into Apache to run just fine.

You might also want to make sure your php.ini file is located where you want it to be, which should generally be where you have PHP installed, e.g. c:\php. In order to do so, you'd add the following directive in Apache's configuration file:

# configure the path to php.ini
PHPIniDir "C:\php"
share|improve this answer
    
added those lines and restarted the server too... but still no change... –  KoolKabin Feb 6 '12 at 19:25
2  
If you are on a Windows machine, the LoadModule lines from Sinan won't work, as you will need to point to DLL files. Also, per Sinan, you must uncomment one of the lines. Good luck! –  rickumali Feb 7 '12 at 21:32

Personally I use wampserver (wampserver.com/en). Like Brad stated, go with a bundled package like this instead of independently installed components.
I had tried for a few weeks to install the "A.M.P" section of my WAMP stack independently without success. With the prepackaged WAMP bundle (or Brad's XAMPP) it should take you no time at all.

share|improve this answer

That means PHP was not configured properly. I assume you installed Apache and PHP independently.

Save yourself some trouble and just install something like XAMPP. It's easier to just stick with a prepackaged bundle, unless you have very particular needs.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.