Ubuntu – What causes PHP pages to consistently download instead of running normally

apache-2.2PHPphp5Ubuntu

I'm running a Ubuntu Server on a VM, to test out different web forum solutions. I have set up a ~/public_html/ to be accessible with the apache2 web server, and that works fine.

However when I go to a .php file on a browser (using my VM's ip-address/~username/phpfile.php) it does not display it as it should. Instead it offers to save to file/asks what program to open it with. Interestingly though that dialog box does recognise that it is a php file.

I have the following version of php installed on the system:

PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

And the following server:

Server version: Apache/2.2.14 (Ubuntu)
Server built:   Nov 18 2010 21:19:09

If anyone knows what might be causing this/potential solutions it would make me very happy 🙂

EDIT:
Turns out files this behaviour was only apparent on files in the ~/public_html/ directory. All php files in /var/www/ work fine.

Prizes go to whoever can explain why? 😀 (And by prizes I just mean a well done, no actual prizes I'm afraid.)

Best Answer

You might have only have the cli version of PHP installed currently try

sudo apt-get install php5

and restart apache

sudo apache2ctl restart.

You can also check the PHP module is loaded into apache by doing

sudo apache2ctl -M

Which if the module is loaded then it should show something like

Loaded Modules:
 ...
 php5_module (shared)
 ...
Syntax OK
Related Topic