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? :D (And by prizes I just mean a well done, no actual prizes I'm afraid.)
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
add this to your apache config
You need to configure apache so that it will start the php interpreter when a .php file is requested instead of just returning the file's contents.
This needs to be done in httpd.conf for the directory in question. It would look something like this:
I had the same problem actually in the user's public_html directory and I found that in the /etc/apache2/mods-available/php5.conf file there are some comment lines included and here they are:
I did what it says and restarted apache and the problem had gone.
Check
.htaccess
for AddType row. I had a custom AddType which caused bad content-type. Firefox helped me debug the issue, but you can also usewget
.Easy to forget, but a common way this happens is forgetting the opening and closing
<?php ?>
tags.I've recently got this problem and after eliminating all other causes in this thread, I found that
mod_php5
extension (in my system at/usr/lib64/apache2/mod_php5.so
) was without executing pemitions.After chmoding it it worked.