Ubuntu Server – Apache: PHP Files Are Downloaded Instead of Opening in Browser


After installing a basic LAMP (Linux, Apache, MySQL & PHP) stack in Ubuntu you will find that Apache will prompt you to download .php files (rather than opening them in your browser).

The solution is to edit the /etc/apache2/mods-available/php5.conf file:

sudo nano /etc/apache2/mods-available/php5.conf

The lower half of php5.conf reads as follows:

# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>

Simply comment out the lines from <IfModule …> to </IfModule> as directed:

# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#    <IfModule mod_userdir.c>
#        <Directory /home/*/public_html>
#            php_admin_value engine Off
#        </Directory>
#    </IfModule>
#</IfModule>

Save php5.conf as then restart Apache:

sudo /etc/init.d/apache2 restart

You will now be able to open .php files in your browser.

11 thoughts on “Ubuntu Server – Apache: PHP Files Are Downloaded Instead of Opening in Browser

  1. After installing a basic LAMP (Linux, Apache, MySQL & PHP) stack in Ubuntu you will find that Apache will prompt you to download .php files (rather than opening them in your browser).

    Hrm. That’s weird. You must have some sort of weird configuration with Apache2, because php should resolve by default just fine. The first thing I do is make a php_info.php file with nothing but after installing Apache to test if it works and I have never once experienced your issue. So I just wanted you to know that this issue is your issue and is not at all common on Apache2 in the LAMP stack on Ubuntu 10.04 SE.

  2. Well, maybe we don’t need to comment the last line, but still.. it didn’t worked for me.. I’m thinking of uninstalling the lamp-server^ and then manually install 😦

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s