Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
What happens if you try your PHP file without any HTML? Nothing but: <?php phpinfo( ); ?> (on three lines) –  Dennis Williamson Sep 27 '09 at 7:05
    
Yup, just '<?php phpinfo( ); ?>'. –  phoebus Sep 27 '09 at 7:35
    
See my edited answer. –  Dennis Williamson Sep 27 '09 at 9:52
    
Have 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. –  Joe May 25 '12 at 19:36
add comment

3 Answers

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
share|improve this answer
    
All 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 Sep 27 '09 at 7:31
    
Re: engine = On, sadly, it was already set. –  phoebus Sep 27 '09 at 10:10
add comment

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

share|improve this answer
    
I'm using the full tag though. –  phoebus Sep 27 '09 at 10:07
    
Hum, I see - sry. Anything in the logs? Did you play around with fcgi or similar? Output of /server-status shows mod_php loaded? –  Marcus Spiegel Sep 27 '09 at 10:32
    
Yeah, 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:) –  phoebus Sep 27 '09 at 11:10
    
hehe, alright. Last but most useful option sometimes :) –  Marcus Spiegel Sep 27 '09 at 11:17
add comment

This command alone may have helped:

sudo apache2ctl restart

I was in a similar situation and it did for me.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.