apache2 not processing php files

Hi,
I’m running apache2 and I installed php5 with yast. httpd2 -M states that php5 is loaded. /etc/apache2/conf.d/php5.conf is being included in httpd.conf and it contains:


<IfModule mod_php5.c>
        AddHandler application/x-php .php
        AddHandler application/x-httpd-php .php4
        AddHandler application/x-httpd-php .php5
        AddHandler application/x-httpd-php .php
        AddHandler application/x-httpd-php-source .php4s
        AddHandler application/x-httpd-php-source .php5s
        AddHandler application/x-httpd-php-source .phps
        DirectoryIndex index.php4
        DirectoryIndex index.php5
        DirectoryIndex index.php
</IfModule> 

The first line was added by me since that’s what mime.types actually contains.

php.ini is in /etc/php5/apache2 and since I was not sure apache/php was finding it I added a PHPIniDir “directive” into httpd.conf. I have not changed it.

Test file is the typical /srv/www/htdocs/info.php with <?php infophp(); ?>

Normal index.htm is working fine. php -a is working fine.

I spent a long afternoon around this configuration and I looked in plenty of pages for solutions. I only do occasional system administration so I might have easily overlooked something trivial, but I run out of ideas.

There is a thread in this web site with a similar problem but no solution:

Php5 not recognized in SUSE 10.2 Apache2

What could be missing/wrong if php5 is loaded and the addhandler is defined? How can I further test?

TIA
Fernando

What’s the output of your info.php page?

I’ve never seen a function called infophp(), is it supposed to be phpinfo();?

Hiatt

On Sat, 07 May 2011 02:36:02 +0530, jthiatt08
<jthiatt08@no-mx.forums.opensuse.org> wrote:

>
> What’s the output of your info.php page?
>
> I’ve never seen a function called infophp(), is it supposed to be
> phpinfo();?

if his server doesn’t process php files, he won’t see output from an
info.php page.

apart from php5.conf being included in httpd.conf, php has to be set in
/etc/sysconfig/apache2. not sure if it’s supposed to happen automatically,
but i remember setting it manually a few times.

there’s a lot of stuff in that file, mostly comments. there’s one
uncommented parameter for APACHE_MODULES, which has to include php5.


phani.

Yeah, what’s the output of that page? A blank page, a 500 error, or what? It should be a 500 error, since the function is called phpinfo().

Also if you look in /var/log/apache2/error_log you will see more clues.

If httpd -M says the module is loaded, then he has included php5 in APACHE_MODULES.

On Sat, 07 May 2011 05:06:05 +0530, ken yap
<ken_yap@no-mx.forums.opensuse.org> wrote:

> If httpd -M says the module is loaded, then he has included php5 in
> APACHE_MODULES.

that only says that it’s included for the CLI configuration. i don’t know
exactly how this enabling via /etc/sysconfig/apache2 works, if that
influences CLI & apache interfaces equally. i’d definitely look if it’s
enabled or not in that file; i’ve had apache not working because of that
several times. never tried phpinfo() via CLI at those times though.


phani.

Then perhaps you should explore how the configuration works before you comment. I’ll give you an outline: the SysV init script uses the values in /etc/sysconfig/apache2 to write a config file in /etc/apache2 which directs apache2 to load the required modules.

httpd2 -M reports on that the config that exists in /etc/apache2. So it will see the same thing, provided /etc/init.d/apache2 has been run once.

On Sat, 07 May 2011 06:06:05 +0530, ken yap
<ken_yap@no-mx.forums.opensuse.org> wrote:

>
> Then perhaps you should explore how the configuration works before you
> comment. I’ll give you an outline: the SysV init script uses the values
> in /etc/sysconfig/apache2 to write a config file in /etc/apache2 which
> directs apache2 to load the required modules.
>
> httpd2 -M reports on that the config that exists in /etc/apache2. So it
> will see the same thing, provided /etc/init.d/apache2 has been run once.
>

thank you; but i don’t see any harm in my comment. i wrote i didn’t know
exactly, and am glad to get it explained. what i suggested wouldn’t have
led to other mistakes, perhaps to a wasted 1.5 min. didn’t know you could
only comment when you were completely sure how something works.


phani.

It saves 1.5 minutes of your time.

Hi

Thanks for the replies.

I have indeed added php5 to /etc/sysconfig/apache2. The function is phpinfo(). I was typing from the top of my head. The issue is that the browser just asks to save/open the file (which then comes with the source).

I don’t see errors in /var/log/apache2/error_log and loglevel is info. I tried debug, no change. Something else, I tried telnet with HEAD / HTTP/1.0 and I got:


HTTP/1.1 403 Forbidden
Date: Fri, 06 May 2011 16:04:04 GMT
Server: Apache/2.2.10 (Linux/SUSE)
Vary: accept-language,accept-charset
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=iso-8859-1
Content-Language: en
Expires: Fri, 06 May 2011 16:04:04 GMT

I notice that Server: does not report PHP5. Maybe this depends on how apache was originally compiled??

Also, it is missing the header X-Powered-By:, which I believe should point to PHP5 (based on Apache 2 and PHP 5 (mod_php) on Linux)

Apache will not report PHP because it’s a dynamically loaded module that may or may not be loaded at runtime.

What exactly do you mean when you say you installed php5. For PHP to work in Apache, you must have both of these packages:

php5
apache2-mod_php5

Just one is not sufficient.

Also do you have any existing .htaccess in that directory that may interfere? Any other .conf files from other webapps in /etc/apache2 that may interfere? And take out that PHPIniDir directive you put in. It’s not needed and may in fact cause a problem.

You could have installed all the prerequisites by installing the pattern lamp_server, although you get mysql thrown in which you may or may not need later.

One other thing, did you by any chance edit info.php on a different machine, e.g. Windows or OS/X? Because the PHP interpreter is sensitive to line endings and if after <?php it is expecting Unix NL, but gets Windows CR NL, or OS/X CR, it would not recognise the file as a PHP script.

And info.php is lowercase right, not INFO.PHP?

Just trying to cover all possibilities.

Yes I installed both packages and a few other php libraries. I already had apache2 and mysql from a long time before. This is a development machine for a zope web server. Apache was running as a front-end to zope using ntlm and rewrite.

However, to test php, I actually renamed the httpd.conf and I am using the one installed by the rpm. So it should be clean. I tried with and without .htaccess. No difference whatsover.

PHPIniDir or not, no difference although I can’t figure out how mod_php5 knows the place of php.ini. I guess it came at compile time. Maybe I should put some bogus command in php.ini to force an error. I assume an apache restart would show it or I could setup up the error log.

Actually there are a few other .conf files. I don’t have access to the system right now, but I’ll have another look at them later and try to disable them. I’m not sure how they could interfere though. If there are AddHandle directives in php5.conf, they can’t be cancelled, right?

BTW, what exactly is a “pattern”? Is this some sort of meta package I can install with yast? I guess I could try removing appache/mysql/php5 and try a fresh install but I really would prefer to leave this as a last resort.

A pattern is basically a group of packages.

If you had packages that came outside of openSUSE or even from another release, all bets are off.

However I am inclined to think rewrite might have something do with it. Are the rewrite rules restricted to a virtual host or are they global? Because if they are global, they could interfere with the processing of PHP files as PHP.

Yes, it’s info.php and it is recognized. The file was created in linux with vim and the browser is in Windows. I see the 3 lines of info.php are actually all put together, when opened with notepad, which I guess is consistent with a missing CR.

I installed all with yast using the default packages. I started using the default httpd.conf which does not Load mod_rewrite and it’s not either in sysconfig (I had already checked, also with httpd2 -M).

I do remember though, that at a certain stage (before the clean httpd.conf), IfModule mod_php5.c was actually not detecting the module! (I tested with a bogus directive inside the <if>). However httpd2 -M was reporting the module as loaded! So, I’m not sure this -M thing is that reliable…

Forget this. Probably this happened when I was loading the module directly in httpd.conf (not syconfig) and the php5.conf was parsed before the LoadModule.

Here’s where it gets tricky. Here’s my guess: httpd2 -M probably reports what modules are specified in the config files. It could be that when it actually runs for real, the module may be corrupt and it is not functional.

You could do a lsof and look at the output to see if http2 actually has mod_php5.so loaded.

You could do rpm -V apache2-mod_php5 and see if the installed files from the package are intact.

Actually the reason is that it was treated as HTML and whitespace is all collapsed in HTML.

Ahh, so indeed -M is not that reliable.

This reminds me that when I checked the .so, it was only available in /usr/lib64/apache2/apache2 and not in apache2-prefork (names from the top of my head). I made a link, IIRC. Also, its file premissions were different from the other modules.

Anyway, I have a few more pointers to look at when I return later on to the server’s place. Many thanks for your help!

And PHP really only works with httpd-prefork, not with httpd-worker.