PHP not being parsed in apache2, php module is installed and enabled
Solution 1
what is the short_open_tag
option set to in your php.ini file? I often missed to turn that on - so I know how you might feel. Some package maintainers set this option to "0" false. Refer to http://www.php.net/manual/en/ini.core.php
Solution 2
When I do the same grep of my config files, I get one line you didn't:
/etc/apache2/mods-enabled/dir.conf:3: DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
Make sure this line in /etc/php5/apache2/php.ini
is set this way:
; Enable the PHP scripting language engine under Apache.
engine = On
If you change it, restart Apache:
sudo apache2ctl restart
Related videos on Youtube
phoebus
Updated on September 17, 2022Comments
-
phoebus over 1 year
EDIT: I decided to just wipe out my apache and php installs and start from scratch. Things are working now, no idea why they weren't before. I've probably set up 30 different LAMP-type servers and never run into this before, I guess I'll just chalk this one up to insanity.
Original question is as follows:
Greetings,
PHP files are not being properly executed on my webserver. I have a test file as follows:
<html> <head> <title>Testing PHP</title> </head> <body> <?php phpinfo( ); ?> </body> </html>
Here are my installed PHP and apache packages:
$ dpkg -l | grep php ii libapache2-mod-php5 5.2.6.dfsg.1-3ubuntu4.2 ii php-config 1.10.11-1 ii php-pear 5.2.6.dfsg.1-3ubuntu4.2 ii php5 5.2.6.dfsg.1-3ubuntu4.2 ii php5-cgi 5.2.6.dfsg.1-3ubuntu4.2 ii php5-cli 5.2.6.dfsg.1-3ubuntu4.2 ii php5-common 5.2.6.dfsg.1-3ubuntu4.2 ii php5-mysql 5.2.6.dfsg.1-3ubuntu4.2 $ dpkg -l | grep apache ii apache2-mpm-prefork 2.2.11-2ubuntu2.3 ii apache2-utils 2.2.11-2ubuntu2.3 ii apache2.2-common 2.2.11-2ubuntu2.3 ii libapache2-mod-auth-mysql 4.3.9-11 ii libapache2-mod-php5 5.2.6.dfsg.1-3ubuntu4.2
Here are my php-related config lines:
$ grep -n php /etc/apache2/apache2.conf /etc/apache2/mods-enabled/php5.* /etc/apache2/httpd.conf /etc/apache2/mods-enabled/php5.conf:1: <IfModule mod_php5.c> /etc/apache2/mods-enabled/php5.conf:2: AddType application/x-httpd-php .php .phtml .php3 /etc/apache2/mods-enabled/php5.conf:3: AddType application/x-httpd-php-source .phps /etc/apache2/mods-enabled/php5.load:1: LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
As you can see, the php5 module is loaded. I can confirm this as a2enmod indicates it is already loaded.
Currently, attempting to load a PHP file in a browser simply displays it as raw text.
Curiously, while trying to fix it, I found that if I add a line like "AddType application/x-httpd-php .php .phtml .php3" to the bottom of httpd.conf, then it suddenly starts asking me to download those php files instead. That's weird, considering that such a line is the same as in the php5.conf module file.
Obviously, neither is desired behavior.
Also, yes, apache2 and now even the server itself have been restarted numerous times. Apache has no trouble serving regular HTML pages.
Any ideas?
-
Dennis Williamson over 14 yearsWhat happens if you try your PHP file without any HTML? Nothing but:
<?php phpinfo( ); ?>
(on three lines) -
phoebus over 14 yearsYup, just '<?php phpinfo( ); ?>'.
-
Joe almost 12 yearsHave you checked the apache error logs and see if it is reporting any errors there? Restart apache and then do a
tail
of the log.
-
-
phoebus over 14 yearsAll that does is make it so that apache looks for an index.php file when you go to a flat directory, i.e. website.com => website.com/index.php =P
-
phoebus over 14 yearsI'm using the full tag though.
-
phoebus over 14 yearsRe: engine = On, sadly, it was already set.
-
Marcus Spiegel over 14 yearsHum, I see - sry. Anything in the logs? Did you play around with fcgi or similar? Output of /server-status shows mod_php loaded?
-
phoebus over 14 yearsYeah, server-status showed mod_php as loaded. However, because I needed to get this up and running, I decided to just wipe my installs and restart from scratch, so now it's working. Thanks for trying though:)
-
Marcus Spiegel over 14 yearshehe, alright. Last but most useful option sometimes :)