2

So I've installed LAMP on an Ubuntu machine for some php development and everything is working fine except instead of parsing and displaying php pages, the browser is asking me if I want to download them. I know this is a well documented issue, and I've already been to the Ubuntu page concerning it, and gone through all the potential causes. I've installed libapache2-mod-php5 and upon running sudo a2enmod php5 I get module php5 already enabled. So I think I've pretty much narrowed the problem down to a php file authorizations issue.

Now I should point out that this only happened after I modified the config file to allow a UserDir in my /home/public_html. With the default configuration in folder /var/www php files parsed just fine, and still do, so long as I gave myself root access or modify their permisssions. And I didn't change anything else in the config file.

So, my question is, how do I check/modify the php authorization files? Where are they? What exactly do I check? I can't seem to find any good info on this.

8
  • What exactly happens when you try to navigate to the PHP pages? Commented Apr 7, 2013 at 2:05
  • It asks you to download them, and if you download, the PHP code inside the file is parsed or is it being downloaded with the PHP code inside? Commented Apr 7, 2013 at 2:08
  • Probably an installation error, or needs a restart of the service.. Try my answer and let me know how it goes Commented Apr 7, 2013 at 2:09
  • @Havenard It's downloading the file and opening it as text in Gedit - like I said, I already know that php5 is installed and working, as it still parses in the /var/www directory, just not in my new user directory. I'm thinking it's something within the apache config or in a php config file ? Commented Apr 7, 2013 at 2:13
  • 1
    Edit your httpd.conf and add the line AddType application/x-httpd-php .php it should fix the problem. Commented Apr 7, 2013 at 2:18

4 Answers 4

3

Try an installation of:

sudo apt-get install php5 libapache2-mod-php5

Then restart the service..

/etc/init.d/apache2 restart 

or if using httpd:

/etc/init.d/httpd restart 

Then let me know how that goes.

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

2 Comments

The system didn't recognize /etc/init.d/httpd, so I guess I'm not running that haha. The other 2 ran fine but the issue remains
Thanks. This should be the solution for most cases, particularly brand new server.
2

So I figured this out with some really tedious searching, I'm surprised the solution is not more widely available, it's really very simple. The /etc/apache2/mods-available/php5.conf file comes with these lines.....

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

...which obviously disable php in user directories. These need to be commented out.

1 Comment

Roger, we upgraded from php7.1 to 7.2 for laravel and ran into this odd problem. Our home directories were not parsing the php files, yet our main /var/www/.. were working fine.
1

This solved my problem, but I just couldn't figure out why:

AddType application/x-httpd-php .php

I added the above in the /etc/httpd/conf/httpd.conf

My problem arose right when I edited the httpd.conf to configure

Comments

0

I'm on Centos 7 running PHP 7.0. I had to load the PHP 7 module in my /etc/httpd/conf/httpd.conf file.

LoadModule php7_module        /usr/lib64/httpd/modules/libphp7.so
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

As always, remember to sudo service httpd restart after making changes to apache

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.