# Apache2/mod_php/mod_ssl

## ClippyHater

I see the install instructions for apache/php/mod_php/mod_ssl in the desktop config guide, but are there comparable instructions somewhere for apache2?

----------

## pilla

Moving to Network & Security.

----------

## rizzo

Well I got apache2 and mod_php to install just fine.  You have to have "apache2" in your USE flag.

However apache2 still isn't handling php files.  It wants to download them.  You know that old gag.  Yes, I've added "-D PHP4" to /etc/conf.d/apache2.  No dice.  Then I noticed inside that file they say to use "-D PHP", which I tried and still no dice.

So if anyone has this working please let us know!

----------

## Rihkama

PHP doesn't support Apache 2 yet. Or actually it supports but it is fairly buggy. I suppose PHP's own manual has quite accurate warning about it: "Do not use Apache 2.0 and PHP in a production environment neither on Unix nor on Windows".

You might check http://www.php.net/manual/en/install.apache2.php in case it has some extra instrucutions which you haven't done.

----------

## Dalrain

I've had apache2 + mysql + php running quite well on my Gentoo box for a while. The main thing on the PHP is that you'll definitely want to get the latest development PHP though.  4.3.x any release also seems to work fine with 2.0.43 as well.

----------

## rizzo

Dalrain did you have to do any special configs other than edit the /etc/conf.d/apache2?  I have apache 2.0.43-r1 and mod_php 4.3.0-r1.

This is the only uncommented line in /etc/conf.d/apache2:

```
APACHE2_OPTS="-D SSL -D PHP"
```

I've tried also "PHP4" instead of just "PHP" in that line, but no change.

----------

## rizzo

OK I guess it had been working this whole time ... sort of.  I made a "phpinfo.php" page with just this code:

```
<? phpinfo(); ?>
```

That worked great.  However my index.php file was still not being handled.  So out of curiosity I moved my phpinfo.php to index.php and now that wasn't working.  Sure enough other php files worked, just not that index.php in my doc root.

So for some reason apache (both 1 and 2 behave this way) doesn't like files named index.php in the doc root.  I'll keep digging.

----------

## opello

maybe try adding "index.php" do your list of default pages in the DirectoryIndex of the commonapache.conf, mine is like:

```
<IfModule mod_dir.c>

    DirectoryIndex index.php index.html index.php3 index.shtml index.cgi index.$

</IfModule>
```

but then, I believe that I just added index.php at the front.

Anyway, it works for me (apache 1.3.26-r4) but I'm going to 2.0.43-r1 as I type  :Smile: 

Going to get the newest php and ssl with the use flag set, and I'll post back here if it works flawlessly ... right ... heh.

----------

## opello

Just got Apache 2.0.43-r1 and mod_php 4.3.0-r2 emerged, and with just configuring apache to my liking, and mod_php emerged with the apache2 use flag, everything worked great.

Hope this helps someone.

----------

## lordjoe

I've been trying to setup apache 2.0.43-r1 and mod_php 4.3.0-r2 today without much luck. I have specified "-D PHP" in the /etc/conf.d/apache2 (despite what the ebuild says, 70_mod_php.conf in /etc/apache2/conf/modules.d/ looks for PHP to be defined, not PHP4). I see "Apache/2.0.43 (Gentoo/Linux) mod_ssl/2.0.43 OpenSSL/0.9.6h PHP/4.3.0" in the logs so i'm assuming mod_php is getting loaded just fine. I'm trying to use webvcrplus. When I try to run the config.php (or just let it load the index.php) i'm prompted to save/view the file. It does report the correct mime-type (application/x-httpd-php) as the mod_php modules.d conf is supposed to set... would be nice to figure this one out :p

----------

## opello

Well, I kept my version of apache1 just in case, but all I did was:

emerge apache-2.0.43-r1.ebuild

edit the /etc/make.conf to include apache2 as a use flag

emerge mod_php

I didn't do ssl, but can if you want me to test it.

As for the php stuff, all I did was leave the ini and other settings as default.  I did add index.php (as I said above) to the DirectoryIndex directive in commonapache2.conf

----------

## lordjoe

alright... all is well now somehow. I'm not sure what did it; i cleaned out all the config files and remerged (is that a word?) and it works... weird

----------

## opello

good deal ... I don't know what it could have been unless it was hung up on something from apache1 ... But mine emerged into another folder /etc/apache2 iirc ...

I guess i'd say remerged (re-merged) but re-emerged sounds just as strange  :Smile: 

Glad you got it working.

----------

## crossfire

rizzo  - did you ever get this fixed?   I just installed apache2 and php4 and have the same problem - everything works excpet for index.php

 *rizzo wrote:*   

> OK I guess it had been working this whole time ... sort of.  I made a "phpinfo.php" page with just this code:
> 
> ```
> <? phpinfo(); ?>
> ```
> ...

 

----------

## Sven Vermeulen

No problem here. Does your commonapache2.conf contain the following?

```

<IfModule mod_dir.c>

    DirectoryIndex index.html index.html.var index.php index.php3 index.shtml index.cgi index.pl index.htm Default.htm default.htm

</IfModule>

```

and does your apache2.conf load commonapache2.conf?

----------

## crossfire

Yes, I have both,

in my apache2.conf file:

# For Apache2 we load all conf files in conf/modules.d

Include conf/modules.d/*.conf

Include conf/commonapache2.conf

and in commonapache2.conf

### DirectoryIndex: Name of the file or files to use as a pre-written HTML

### directory index.  Separate multiple entries with spaces.

###

<IfModule mod_dir.c>

    DirectoryIndex index.php index.html index.html.var index.php3 index.shtml index.cgi index.pl index.htm Default.htm default.htm

</IfModule>

 *Sven Vermeulen wrote:*   

> No problem here. Does your commonapache2.conf contain the following?
> 
> ```
> 
> <IfModule mod_dir.c>
> ...

 

----------

## slott_hansen

I have had similar problems and I still have them...   :Crying or Very sad: 

I emerged apache2 and mod_php and when ever I access a PHP file it prompts for download. I use lynx on localhost but that shouldn't be the problem.

To further depress me my apache2 won't startup automatically when I reboot. I have to do a start/stop (restart won't make it work) in order for it to accept connections.

And the spooky thing is that when I do a apache2 status it tells me it's started. Netstat shows NO apache and thus I'm lead to belive there must be something wrong!!!!

So if anyone could PLEASE shed some light on this I would be greatly apriciated...

----------

## slott_hansen

Phew-  got the PHP stuff working.

I manually had to add the following stuff to my apache2.conf...

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

Well thats one problem solved. But still my apache refuses to be "connectable" after a reboot!!!!

----------

## slott_hansen

I have been looking at my problem for quite some time now and I'm still not getting closer to finding a solution. I installed postgreSQL and when I try to connect after a reboot I have no trouble at all - so what could be wrong with my apache2 ???

----------

## bertrand

I added the following to my /etc/apache2/conf/apache2.conf and it start working for .php files

```

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

AddType application/x-httpd-php         php

<Files *.php>

        SetOutputFilter PHP

        SetInputFilter PHP

</Files>

# PHP Syntax Coloring (recommended):

AddType application/x-httpd-php-source  phps

<Files *.phps>

        SetOutputFilter PHP

        SetInputFilter PHP

</Files>

```

I hope this can help someone else!

----------

## DarkJedi9

Okay, I have apache2 in my USE flag, and I have emerged apache and mod_php.  I also added the lines bertrand suggested into apache2.conf.  Then I did /etc/init.d/apache start.  Apache is working, but when I try to go to http://localhost/hello.php, it wants to save or open then file, like others have had trouble with.  As far as I can tell, I've done everything that has worked for the others, and it isn't helping me.  Any suggestions?

----------

## DarkJedi9

Alright, this is really strange.  I have two files in my /home/httpd/htdocs directory, phpinfo.php and hello.php.  When I try to go to http://localhost/hello.php, I get that accursed save or open dialog box, but when I go to http://localhost/phpinfo.php, I get this page full of stuff.  (BTW, both files contain only one line: <? phpinfo(); ?>)  That lines sure looks like it would generate the page I see, so I guess that's good, but I can't for the life of me see why one file would be interpreted correctly and one not.

----------

## slott_hansen

Did you change your /etc/conf.d/apache2 to the following ?

APACHE2_OPTS="-D SSL -D PHP"

----------

## DarkJedi9

Actually, I just got it working.  I'm not sure exactly why though. My /etc/conf.d/apache2 has APACHE2_OPTS="-D PHP4", and my /etc/apache2/conf/apache2.conf has LoadModule php4_module                   /usr/lib/apache2-extramodules/libphp4.so in it, which I would swear I had before, but now it's working.  I did notice what was noted above (I believe; I'm having a hard time finding it now) about rebooting.  I had to reboot the whole comp, not just restart apache2.  But hey, it works.  Thanks all for the help.

----------

## Trumpcard

I have a similiar problem to this...  Any php in my root directory works fine,  but anything in a subdirectory is not recognized....

If I move my php to  /  ,  they work fine,  if I try to access them from subdirectories, they wont work at all.  I've even set up my sub <DIRECTORY ...> to look exactly like the root directory, so Im not sure what the issue is.

----------

## WarMachine

This worked fine for me:

https://forums.gentoo.org/viewtopic.php?t=39805

although I didn't try the mod_ssl part

----------

## sandcrawler

Heres something that I hope helps everyone here.

I was having the same troubles as most here.  First mod_php didn't seem to be loading as all I got was raw source.  I unloaded apache1.27 and mod_php.  verified my make.conf (which was missing "apache2 -java -qt") and reloaded mod_php from scratch with apache2.  

My new symptoms was this AWFUL "save this file" message.  I tried all of the suggestions here and then I devided to take a whack at the <? phpinfo(); ?> line.  Sure enough when I created this file and named it index.php it worked.

Basic troubleshooting led me to look at file permissions. Everything was setup as apache permissions, including my index.php from squirrelmail.  I immediately noticed my index.php that I had created was root.root.  I changed the squirrelmail index.php to root.root  and BINGO, the page tries to work. (i got forwarded to the src/login.php)  Chaning the permissions on all folders in squirrelmail to got me to a login.  Logging in got me to a permission error on the data folder.  changing it back to apache solved that problem.

So I hope that helps someone.  Now...  I'm worried about having these folders running with root permissions.  Anybody got a clue on getting them back to apache?  I should know the answer to this but I'm too swamped to play with that right now.  The cannibals are fed and happy and I got other servers to worry about in the meantime.

-=Mos19K=-

----------

## art

I had same problem using mozilla 1.3  used konqueror and it works fine

????

----------

## sven

You are right! It does work with Konqueror, but not with Mozilla 1.3! This is really strange! 

I'm using Apache 2.0.45 and PHP 4.3.1 and have just added "-D PHP" to /etc/conf.d/apache2 and uncommented the line.

EDIT: I cleared Mozillas Cache (Preferences/Advanced/Cache) and now it works!!

----------

