Why isn't my PHP file running and instead Apache is offering it for download?

5,740

Solution 1

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"

Solution 2

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:
5,740

Related videos on Youtube

KoolKabin
Author by

KoolKabin

A freelance web developer Websites: 1.) http://biotechx.com 2.) http://highcountrytrekking.com 3.) http://firante.com 4.) http://himalayanencounters.com 5.) http://ajisai.edu.np 6.) http://environmentnepal.info/test 7.) http://treknepal.au 8.) http://sunshinetrekking.com 9.) http://taverntrove.com 10.) http://trekkingandtoursnepal.com 11.) http://outsourcingnepal.com

Updated on September 18, 2022

Comments

  • KoolKabin
    KoolKabin over 1 year

    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
    • Kristian Damian
      Kristian Damian about 12 years
      We can't see your localhost :)
  • KoolKabin
    KoolKabin about 12 years
    added those lines and restarted the server too... but still no change...
  • DownDown
    DownDown about 12 years
    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!