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
shane
  • 373
  • 1
  • 3
  • 4
  • 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.) – andrewdski Jun 05 '11 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! – shane Jun 05 '11 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). ` php_admin_value engine Off ...` – Grzegorz Oledzki Jul 31 '14 at 11:55

6 Answers6

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
Null
  • 1,950
  • 9
  • 30
  • 33
Paris Liakos
  • 2,131
  • 3
  • 22
  • 23
  • 1
    Ha! Thankyou! ( Worked ) Does this mean I need to install mysql separately too? any chance of helping me with the command? Many thanks – shane Jun 05 '11 at 21:21
  • @shane `sudo apt-get install mysql-server` – damianb Jun 05 '11 at 21:22
  • Your a gent, thanks. I'm currently on the migration from developing on windows. Will the mysql install give me phpmyadmin too? – shane Jun 05 '11 at 21:24
  • 1
    Obsidian_ was faster:) if you also want to install phpmyadmin use this: `sudo apt-get install phpmyadmin` and then you will find it here: http://localhost/phpmyadmin – Paris Liakos Jun 05 '11 at 21:25
  • 1
    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. http://www.phpmyadmin.net/home_page/index.php – damianb Jun 05 '11 at 21:28
  • @rootatwc: Not with web apps. Frequently they're missing security updates just because nobody that is involved with the project knows how to build the necessary packages or cares to. – damianb Jun 05 '11 at 21:30
  • @Obsidian_ don't worry this doesn't apply to phpmyadmin,apache,php (and every popular package)..everything gets patched asap (when it comes to security).don't get tricked by the versions;) – Paris Liakos Jun 05 '11 at 21:34
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
Dale E. Moore
  • 431
  • 7
  • 19
  • 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? – valid Jul 26 '14 at 18:10
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.

Anonymous User
  • 908
  • 1
  • 9
  • 5
3

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

Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109
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.

damianb
  • 1,224
  • 7
  • 16
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

alok
  • 2,718
  • 21
  • 17