# Apache2 + PHP4 Help

## wild_pointer

Ok, I've tried this about three times and each time I have the problem where my server doesn't parse php files, it tries to serve them for download.

This is the order in which I've been doing things.

in /etc/make.conf I have:

ACCEPT_KEYWORDS="~x86"

USE="apache2" 

emerge apache

emerge mod_php

Then in /etc/conf.d/apache2 I set

APACHE2_OPTS="-D PHP4" 

and in apache.conf

LoadModule php4_module /usr/lib/apache2-extramodules/libphp4.so

Actually this is in a directory like /addon/php.conf which is linked in apache.conf [I've since unmerged everything to start over, so sorry if the patthnames are a bit off]

Can someone explain exactly how I should be doing this?  I'd like to get my website back up sometime this month  :Smile: Last edited by wild_pointer on Fri May 02, 2003 10:20 pm; edited 1 time in total

----------

## rizzo

Did you run the ebuild ... config command as you were directed at the end of the mod_php ebuild?  The libphp4.so is installed in /etc/apache2/extramodules, not /usr/lib/.

----------

## danielrm26

I understand there may be a typo in the /etc/conf.d/apache directions. Try PHP instead of PHP4 and let me know if that works.

----------

## wild_pointer

I just finished merging mod_php again, and I see no instruction for an ebuild.  I tried /var/db/pkg/dev-php/mod_php-4.3.1-r2/mod_php-4.3.1-r2.ebuild config but got the following error:

/usr/sbin/ebuild.sh: line 292: //usr/sbin/apacheaddmod: No such file or directory.

I tried -D PHP as well, browser still tries to download php files.

----------

## giant

hmm I just installed apache2 with mod_php and it runs just fine.

From my memory - but I'll look this up at work the php module is not loaded in the main apache.conf.

There is a dir in the conf dir about modules and there should be a file 70php_module something. In this all necessary modules will be loaded.

I post the conf files I use when I am at work.

Word of warning if you pass on php_admin_values in your vhost.conf you will get an error when you check them with apache2 -S but it works just fine.

----------

## wild_pointer

/etc/apache2/modules.d/70_mod_php.conf has the LoadModule and AddType commands all set for me after installation.

```

<IfDefine PHP>

  <IfModules !mod_php4.c>

    LoadModule php4_module    extramodules/libphp4.so

  </IfModule>

</IfDefine>

<IfModule mod_mime.c>

  AddType application/x-httpd-php     .php

  ...

</IfModule>

```

In apache2.conf there is an Include conf/modules.d/*.conf line.

[EDIT] It would appear danielrm26 was right about the -D PHP from <IfDefine PHP> part, but it's still not working.

----------

## wild_pointer

Well it started working... by itself.  I copied my /test.php file to it's own directory and renamed it index.php and it loaded as expected. When I tried /test.php again it worked as well.

Thanks all.

----------

## danielrm26

Yeah, very odd.  Mine still wasn't working when loading a known php page, but then I created the test.php page and tried it...

It worked.

So I guess it's working now...  I know I don't like the 'flaky' feeling that I am getting - it works one minute and not the next.

----------

## dondajp

I just fixed on mine. 

 after installing apache2 and mod_php do the changes that are mention after the emerge. But the bug is in the file the   /etc/apache2/conf/modules.d/70_mod_php.conf  

 change the first line  

 <IfDefine PHP> 

 with the 

 <IfDefine PHP4> 

 That should work. if not let me know

----------

## Bruce

After reading the posts on this thread and other similiar threads, I thought I'd put in my 2 cents.  I spent 3 days screwing around with apache2 and PHP.  I'm knew the modules were loaded because telneting to port 80 and requesting a page would yield the folllowing address:

```

<address>Apache/2.0.45 (Gentoo/Linux) mod_perl/1.99_08 Perl/v5.8.0 mod_ssl/2.0.45 OpenSSL/0.9.6i PHP/4.3.1 Server at www.foobar.com Port 80</address>

```

For some reason PHP would not parse the page so apache would simply serve up the PHP as if it was a normal document.   

I read this thread several times but to be blunt I figured that some of the other posters had a screw loose because software just doesn't start working by itself.  

Last night at 3 AM, I finally gave up.  This morning when I got up, lo and behold, PHP started working.   I even spent the last hour trying to make it fail (I can't).

Please add me to the list of people with a screw loose.

----------

## SeraphWhisper

following this thread and screwing around with apache, i think i figured out the secret...

for some reason, php only works after rebooting the whole system...although i have no idea why...

tried the following steps:

1) emerge apache

2) emerge php mod_php

3) added "APACHE_OPTS="-D PHP" to /etc/conf.d/apache2 (to account for the typo in 70_mod_php.conf )

4) rc-update add apache2 default

fired up apache2 and php still refused to work.....reboot once, there you go, magic....

unemerged it all and tried it again.....still doesn't work till i reboot....

*shrug* im completely stumped, but it works....

----------

## jaloha

Apahe has a lot of threads in action.  I'm sure that something just needs to be restarted or updates itself after a period of time.  That would explain the flaky behavior.

----------

## momech

Err, i'm a newbie linux admin, BUT:

Could the aswer be that when you start apache with "apache(2)ctl start" it DOES NOT define the "PHP(4)" flag, whereas the init DOES define the "PHP(4)" flag? 

That would explain why it suddenly starts working: 

After messing around with apache(2)ctl for a lot of time you do a reboot/shutdown and - tada.wav - at boot init starts apache WITH the PHP(4)-flag...?

----------

