# Apache2 and PHP (yet again...)

## adgriffi

Hello all,

I have apache2 emerged.

I have mod_php emerged.

I ran this (but I don't think it did anything to my config files):

```
ebuild /var/db/pkg/dev-php/mod_php-4.3.4-r4/mod_php-4.3.4-r4.ebuild config
```

I have APACHE2_OPTS="-D PHP4" in /etc/conf.d/apache2

In /etc/apache2/conf/commonapache2.conf I have  *Quote:*   

> AddType application/x-httpd-php .php .phtml

 

In /etc/apache2/conf/apache2.conf I have  *Quote:*   

> LoadModule php4_module extramodules/libphp4.so

 

Everything works great (including php) when I run:

```
apache2 -k start
```

I added apache2 to default:

```
rc-update add apache2 default
```

When the computer boots, I get this warning: *Quote:*   

> [warn] module php4_module is already loaded, skipping

 And php rendering DOES NOT WORK.

In order to get it working I first have to stop the apache2 server (which was started during the boot process) and run the "apache2 -k start" command again.

PLEASE HELP.

Adam

----------

## ckdake

Take the lines out of your config file:

 *Quote:*   

> AddType application/x-httpd-php .php .phtml
> 
> LoadModule php4_module extramodules/libphp4.so

 

The D PHP4 combined with the /etc/init.d/apache2 start and the coolenss of gentoo takes care of these for you so it will get confused if you try to manually add them.  take a look at the files in the folder /etc/apache2/conf/modules.d/ for a better idea of what is going on.

----------

## adgriffi

Ok,

I took those lines out of my configs, and the warning message is gone.

HOWEVER,

PHP rendering DOES NOT WORK when I run this (which gets executed at boot time, so it's not working on boot either...):

```
/etc/init.d/apache2 start
```

It only renders if I use the command:

```
apache2 -k start
```

The first command uses "/etc/init.d/apache2" (obviously).

The second command uses "/usr/sbin/apache2".

Any more help??

----------

## ckdake

How is php not working?  does anything show up in /var/log/apache2/error_log when you try to go to a php page?

----------

## adgriffi

Well,

I don't know why, but now it IS working.

I stopped the server again and restarted it, and it's fine. I rebooted, and it works. So, problems seem to be gone now.

The only thing I can see from the logs is that it was "generating secret for digest authentication ... "

The first time this ran (after removing lines from the config files) it took almost 8 minutes. Now on boot it only took 1 second. My guess is that even though it said apache2 had started, it was still figuring stuff out in the background, and I tried it within that 8 minute period while it was working with the digest stuff.

 *Quote:*   

> [Sun Feb 15 18:55:03 2004] [notice] Apache/2.0.48 (Gentoo/Linux) PHP/4.3.4 configured -- resuming normal operations
> 
> [Sun Feb 15 19:21:06 2004] [notice] caught SIGTERM, shutting down
> 
> [Sun Feb 15 19:21:11 2004] [warn] module php4_module is already loaded, skipping
> ...

 

And then later:

 *Quote:*   

> [Sun Feb 15 20:38:09 2004] [notice] Digest: generating secret for digest authentication ...
> 
> [Sun Feb 15 20:38:09 2004] [notice] Digest: done
> 
> [Sun Feb 15 20:38:12 2004] [notice] Apache/2.0.48 (Gentoo/Linux) PHP/4.3.4 configured -- resuming normal operations

 

Thanks for your help!!

----------

## ckdake

glad its working. to fix the digest problem:  https://forums.gentoo.org/viewtopic.php?t=111133&highlight=apache+urandom

(specifically the 3rd post)

----------

## outspoken

oddly i had the [warn] message appear twice.. i removed the line you explained above and still received one message.. after looking into my conf i also had placed 'Include conf/modules.d/70_mod.php.conf' asfter commenting that out everything worked fine including php parsing.

unfortunately now for some reason when i visit something like http://www.mydomain.com/whatever/directory/name it does not load, i have to type in http://www.mydomain.com/whatever/directory/name/index.php

could someone explain this one to me and let me know how to fix it?

thanks!

----------

## ckdake

does putting  atrailing / on the name fix the problem?  If that does, your problem is with mod_rewrite.  If that doesn't fix it, your problem is that you need to allow .php files to be indexes.  Search for DirectoryIndex in commonapache2.conf and if it doesnt have a .php on the same line, add it and try again.

----------

## outspoken

ok it works now after checking for index.php in directoryindex.

i has another question since you brought up mod_rewrite. how would i have fixed it if that was the issue?

----------

## ckdake

I am fairly sure that apache users mod_rewrite to point mydomain.com/folder to mydomain.com/folder/ (it adds the slash on the end)  

If you didn't have mod_rewrite enabled, I don't think that would work properly though I really am not that familiar with it. There is probably some good documentation on apache's website.

----------

## JoeG

any idea what the hell 

```
Syntax error on line 190 of /etc/apache2/conf/apache2.conf:

Invalid command 'APACHE_OPTS="-D', perhaps mis-spelled or defined by a module not included in the server configuration

```

is trying to tell me when I run /etc/init.d/apache2?

using 

```
APACHE2_OPTS="-D PHP4 -D SSL" 
```

in /etc/apache2/conf/apache2.conf

and with my USE flags set to:

```
USE="X gtk gnome -alsa -qt -kde samba mysql imap libwww maildir sasl ssl acpi cups
```

I did:

```
emerge apache php mod_php phpmyadmin
```

JoeG

----------

## ckdake

what is line 190 in apache2.conf?

----------

## JoeG

 *Quote:*   

> what is line 190 in apache2.conf?

 

In my case, it's the last line of the file and it contains the text:

```
APACHE2_OPTS="-D PHP4 -D SSL"
```

  :Wink: 

JoeG

P.S.  I got it working.  Here's the deal.  In /etc/apache2/conf/apache2.conf, the line for APACHE2_OPTS= caused a problem when (re)starting apache with the command /etc/init.d/apache2 start.  I commented that line out, and made sure that same line existed in /etc/conf.d/apache2, then started apache with the /etc/init.d/apache2 start command.  :Cool: 

----------

## ckdake

Hmm. That line should be in /etc/conf.d/apache2 instead of in your apache config file, but what works works.

----------

