37

On my new Ubuntu system, I've managed to get Apache2 up and running for developing my ZendFramework Web Applications...

I've got my available-sites config working correctly because I am able to request localhost and it servers up the correct index.html from my specified directory.

Problem : if I request index.php, firefox attempts to download the file instead of running the script.

Any Ideas why this would happen?

I've added the following to httpd.conf but it hasn't helped.

AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml

AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
3
  • Have you restarted apache after changing httpd.conf? Other than that, I don't see a problem. (My server has only AddType, but I'm not sure it matters.) Commented Jun 5, 2011 at 21:19
  • Thanks for your reply. Turns out I had only installed the Apache server, and not PHP. I had assumed it was bundled and would install together... You know what they say about assumption... Ha! Commented Jun 5, 2011 at 21:23
  • If anyone has the problem, and the libapache2-mod-php5 already installed. Then, if you are experiencing the problem in one of the home public-html folders, checkout /etc/apache2/mods-available/php5.conf - it has a section turning off PHP for home folders (for some reasons). <Directory /home/*/public_html> php_admin_value engine Off ... Commented Jul 31, 2014 at 11:55

6 Answers 6

68

If Firefox downloads your PHP files it means that your server doesn't have PHP or the Apache PHP module installed.

Have you installed the Apache PHP module? If not then install it by typing this into a terminal:

sudo apt-get install libapache2-mod-php5

And if yes, do you have your index.php located in /var/www/?

Make sure to enable PHP with the command

sudo a2enmod php5
Sign up to request clarification or add additional context in comments.

7 Comments

Ha! Thankyou! ( Worked ) Does this mean I need to install mysql separately too? any chance of helping me with the command? Many thanks
@shane sudo apt-get install mysql-server
Your a gent, thanks. I'm currently on the migration from developing on windows. Will the mysql install give me phpmyadmin too?
Obsidian_ was faster:) if you also want to install phpmyadmin use this: sudo apt-get install phpmyadmin and then you will find it here: localhost/phpmyadmin
it's far easier to download phpmyadmin and set it up yourself tbh, and you'll get a newer version too typically. web apps in the ubuntu repositories are very often out of date by months, if not years. phpmyadmin.net/home_page/index.php
|
12

If you are using userdir (http://localhost/~user/phpinfo.php) you will want to:

vi /etc/apache2/mods-enabled/php5.conf

Change

<IfModule mod_userdir.c>
   <Directory /home/*/public_html>
       php_admin_value engine Off
   </Directory>
</IfModule>

to comment the php_admin_value

<IfModule mod_userdir.c>
   <Directory /home/*/public_html>
       #php_admin_value engine Off
   </Directory>
</IfModule>

then

service apache2 restart

1 Comment

I'm perplexed that this is a solution. Specifically it seems problematic to mention php_admin_value engine no matter if set to On or Off. Why would that be the case? Is an empty directive ignored?
4

For me, the solution was to create the following 2 symbolic links:

ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf
ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/php5.load

and to restart Apache:

/etc/init.d/apache2 restart

Hitting the http://my_server/test.php file, which has contents:

<?php
   phpinfo();
?>

came right up, and the browser didn't try to download the php file. Didn't have to restart the browser, either.

1 Comment

you can create the simlinks with a2enmod php5
3

You need to enable the PHP extension. Do this with the command sudo a2enmod php.

Comments

2

I'll assume you installed PHP already and installed the PHP module for Apache here...

Did you restart apache? If not: sudo service apache2 restart

Make sure that your httpd.conf file is also being executed. If necessary, restart it after making an edit that would cause an error on load. If it doesn't fail to restart, it's not running the .conf file.

If the problem still continues, close your browser, reopen it, and clear your cache. It might be the browser just caching the page response.

Comments

0

I have installed php 7.0 and getting the dailog box. I have installed apache php module for 7.0 version and it fix my problem.

sudo apt-get install libapache2-mod-php7.0

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.