Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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.
{"cc_re__cc_re__cc_by_sa_3_0": ["                       <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\n                </div>\n            </div>\n\n            <div id=\"copyright\">\n                site design / logo &#169; 2016 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\n            </div>\n            <div id=\"svnrev\">\n                rev 2016.2.5.3240\n            </div>\n            \n        </div>\n    </div>\n    <noscript>\n        <div id=\"noscript-warning\">Webmasters Stack Exchange works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\n    </nosc"], "copyright__copyright__copyright": ["e|improve this answer\n\nThat means PHP was not configured properly. I assume you installed Apache and PHP independently.\n\nSave 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.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}