# Apache2 and PHP4 - About to lose my mind!

## rsg

Hello,

I've got Apache2 running, and I'm trying to get it to work with mod_php.  As far as I can tell, I've done all I'm supposed to do, and then some!  After many wrong turns, I finally understand why APACHE2_OPTS="-D PHP4" is all I need to do.  It seems as though all is fine; from the error log, I get messages like this:

```
[Thu Mar 11 19:54:32 2005] [notice] Apache/2.0.52 (Gentoo/Linux) PHP/4.3.10 configured -- resuming normal operations
```

which I infer to mean Apache is "configured" to serve up .php pages.  However, when I attempt to open a page from a client machine, entering something like "http://mydomain.com/info.php", the browser opens its 'Opening info.php' (Mozilla) or 'File Download' (MSIE) dialog box!  What am I missing?  I do have the '70_mod_php.conf' file, and it looks correct.

Help, and Thanks!

----------

## hds

/etc/conf.d/apache2:

```

[...]

APACHE2_OPTS="-D PHP4"

[...]

```

```

env-update; source /etc/profile

```

```

/etc/init.d/apache2 restart

```

works?

----------

## rsg

Nope!   :Confused:    Same symptoms.

I had not done the "env-update;..." step, but it didn't seem to help

Any other ideas?

----------

## hds

well, i have PHP5 installed (so i use -D PHP5), but it does work fine here..

----------

## ihad

Hi,

Just guessing here, but: could it be that your apache doesn't load mod_mime? Because then the handlers for

php-scripts won't be set. From my 70_mod_php.conf:

```

<IfModule mod_mime.c>

AddType application/x-httpd-php .php

AddType application/x-httpd-php .phtml

AddType application/x-httpd-php .php3

AddType application/x-httpd-php .php4

AddType application/x-httpd-php-source .phps

</IfModule>

```

You could try to put the AddType-Directives somewhere in the apache2.conf w/o the <Ifmodule...>

conditions and see if it works then...

Regards

----------

## rsg

Aha!  I did what you suggested, ihad, and copied the AddType lines to my apache2.conf file, and it works!

But, figuring it belonged in the 70_mod_php.conf file instead, I tried removing them for apache2.conf, and commenting out the <IfModule....> tags in 70_.conf file, figuring that would work.  Of course, it didn't!  So it seems as though Apache isn't even reading the 70_.conf file!

Anyway, I don't really care if it will continue to work, but it seems weird!

----------

## hds

this might have to do with:

 *Quote:*   

> 
> 
> After many wrong turns, I finally understand why..
> 
> 

 

could it be that you screwed something up elsewhere, perhaps?

if in doubts, and this is going to be a real server accessible to the outside realworld, i simly would install apache, php and mod_php again. just in case. now you know what you have to change..

btw.. make sure you have "session" in your USEflags. if its not already in there, you might have to reinstall php anyway. otherwise it will not have session support.

----------

## eerok

Gah, I've been going nuts trying to duplicate my system elsewhere (same versions of everything).  I thought something was messed with php, and I even copied /etc/apache2 over to the new system.

Now I discover that php was working all along.  For example, even though I still fail on phpinfo(), which is the standard test, I can execute phpmyadmin.

So I'm evidently not handling "index.php" files properly.  I think I used to know how to fix that, but can someone refresh my memory?

edit: bah, that's not it, either -- phpmyadmin uses an index.php file as well ... perhaps it's some kind of permissions problem?  htdocs was copied over, but the owner is the same.

----------

## gentoo_0x00

how does phpinfo() fail?

what happens if you put it in a file called test.php instead of index.php, does it work then?

perhaps your apache configuration is looking for index.html before index.php.

----------

## eerok

It appears that even though the 2 installs are pretty much identical, one will accept

```
<?

phpinfo(); ?>
```

and the new one insists on

```
<?php

phpinfo(); ?>
```

Also the new install will sometimes deal properly with a tacit index.php and sometimes not.

There's a slight difference in USE flags between the 2 installs; I guess that's the difference?

Anyway, it was mostly just darkly amusing to have been killing myself trying to make php work when it was already pretty much working.  I guess I can adapt to the slightly different reality on the new system, lol.

----------

## hds

hmm.. so all between yours "bah" and "killing" and what not..

dare to explain where your problem is exactly?

----------

## eerok

Well, there's no longer a problem per se, since I made everything work.

It's more of a mystery why 2 installs compiled with the same source versions, the configs from one copied to the other, using the same .php files, should behave differently enough to appear broken.  The only difference between the installs is that I explicitly set some USE flags in /etc/make.conf for the 2nd ... like apache2, php, mysql ... instead of doing USE="php mysql" on the command line.

No big deal, but worth a bah or two  :Laughing: 

But here's the different behavior: the index.php file sometimes works and sometimes doesn't when it's not specified (ie, http://localhost/yadda instead of http://localhost/yadda/index.php).

I now have to use <?php ... ?> instead of just <? ... ?> within a php file.

Like I said, no big deal but a bit strange.

----------

## justanothergentoofanatic

 *eerok wrote:*   

> It's more of a mystery why 2 installs compiled with the same source versions, the configs from one copied to the other, using the same .php files, should behave differently enough to appear broken.

 

They probably weren't exactly the same version. Ebuild authors are not supposed to increase the version number when they change things that only affect new installs of the ebuild.

-Mike

----------

## eerok

Thx, that makes sense and it's worth keeping in mind when I need to duplicate a system again.

----------

## justanothergentoofanatic

 *Quote:*   

> Thx, that makes sense

 That's good because it never quite made sense to me... *Quote:*   

>  and it's worth keeping in mind when I need to duplicate a system again.

 for exactly this reason. Oh, well.  :Cool: 

-Mike

----------

## erikb

I don't follow the last few posts either, but I did solve my similar problem with clues in this thread.  Above, there's a mention that httpd.conf wasn't reading the 70_mod_php.conf file.  This was the key.

I was reading somewhere before I emerged apache2 that the gentoo devs had tried to better organize the /etc/apache2 directory, but because it was just confusing more people, they decided to switch back to a more "normal" structure.  (Notably, httpd.conf is now not split up.)  Because I was having trouble myself trying to switch my DocumentRoot, I opted to emerge (the then ~x86) versions of:net-www/apache-2.0.53 *

dev-php/mod_php-4.3.10 *

dev-php/php-4.3.10 *

dev-libs/apr-0.9.6-r1 *

dev-libs/apr-util-0.9.6 * and whatever else they needed.

So mod_php installed it's config file to /etc/apache2/conf/modules.d/70_mod_php.conf, but all the other modules and such are now in /etc/apache2/modules/.  This actually looked fine, because in httpd.conf, there is a line:

```
# We Include extra .conf files from /etc/apache2/modules.d

# This is used to load things like PHP and mod_ssl.

#

Include conf/modules.d/*.conf
```

The thing to realize here is that that relative path is not from the location of httpd.conf, but from ServerRoot, which is /usr/lib/apache2/, and conf/ is a symlink to /etc/apache2/  So that line is really including files in /etc/apache2/modules.d/.  OK, so I moved the 70_mod_php.conf to there, moved the php.ini in /etc/apache2/conf/ to just /etc/apache/ and on restarting apache I can see it try to load the php module.  I say try to load, because libphp4.so is in /usr/lib/apache2-extramodules/, not /usr/lib/apache2/extramodules/.  I moved the former to the latter, and now all works fine for *.php files.  I still have to add an AddType if I want it to parse php in *.html files, but I think that's more understandable.

I chalk this up to using ~x86 packages, does it still merit filing a bug report?  I've never done such a thing.

----------

## diskmuncher

I have apache-2.0.52-r1 (not ~x86), and mod_php-4.3.10.  The /etc/apache2/conf file is quite broken in the ways you describe below...I fixed by changing everything to absolute paths throughout (I prefer it that way anways...no mistaken interpretation).  Plus, of course, I had to add -D PHP4 to /etc/init.d/apache2 (or the alternative which is to remove the <IFModule> statements in /etc/apache2/conf/modules.d/...)

 *erikb wrote:*   

> I don't follow the last few posts either, but I did solve my similar problem with clues in this thread.  Above, there's a mention that httpd.conf wasn't reading the 70_mod_php.conf file.  This was the key.
> 
> I was reading somewhere before I emerged apache2 that the gentoo devs had tried to better organize the /etc/apache2 directory, but because it was just confusing more people, they decided to switch back to a more "normal" structure.  (Notably, httpd.conf is now not split up.)  Because I was having trouble myself trying to switch my DocumentRoot, I opted to emerge (the then ~x86) versions of:net-www/apache-2.0.53 *
> 
> dev-php/mod_php-4.3.10 *
> ...

 

----------

## bpopp

There does appear to be a bug with the way php5 is packaged. I recently did a fresh Stage 2 install of Gentoo and emerged mod_php5 (after unmasking) and apache2.  I ended up getting mod_php version 5.0.3-r1 and apache 2.0.52-r1. 

After making the normal entry in /etc/conf.d/apache2, php pages still weren't being parsed. When I looked in /etc/apache2/conf/modules.d there were several modules, but none were php specific. Using erikb's suggestion below, I cd'd up a few directories and found the necessary file in /etc/apache2/modules.d (all by it's lonesome). I copied that file to the other directory with the other modules (ssl, etc.) and restarted apache and everything is working as expected. 

It sounds like the apache config expects it to be one place and the php guys decided to put it somewhere else. I feel a little uncomfortable with this solution, though, because if newer versions of php make changes to this file, they won't be incorporated. A better solution (assuming this isn't fixed anytime soon) would probably be to setup the apache config to include this second /etc/apache2/modules.d in addition to the /etc/apache2/conf/modules.d/ directory.

----------

## Strowi

hi,

i just upgraded (ok, after lots of trouble with php reinstalled) apache-2.0.52-r1 and mod_php-4.3.10.

After knocking my head again different walls in my flat, i found out that "modules.d/70_mod_php.conf" and "php.ini" were to be found in "/etc/apache2/conf/" instead of "/etc/apache2", but the "libphp4.so" was also in the wrong place (sth. "apache2-extramodules/.. don't remember, knocked that part of my brain once too much  :Wink: ).

This is due to the config change in apache2 to make it more 'gentooish'. You can findmore info about that somewhere on the gentoo.org-page (or google). So i guess it will be fixed sometime in the future (i think mod_php-5 already had that addressed, but because i want to setup horde on our flat-router i can't use/test it)

So the easiest soulution is to do:

```

mv /etc/apache2/conf/php.ini /etc/apache2

mv /etc/apache2/conf/modules.d/70_mod_php.conf /etc/apache2/modules.d/

mv /usr/lib/apache2/apache2-extramodules/libphp4.so /usr/lib/apache2/modules/

```

Now add "index.php index.php3 index.shtml index.cgi index.pl index.htm Default.htm default.htm" to your DirectoryIndex in /etc/apache2/httpd.conf to server the index.php & co. autmatically when opening a directory.

And if you don't have anything other modules installed (or doing a clean install), do also:

```

rm -fr /etc/apache2/conf /usr/lib/apache2/apache2-extramodules

```

Hope that helps saving some heads. :Wink: 

----------

## sca

 *eerok wrote:*   

> 
> 
> But here's the different behavior: the index.php file sometimes works and sometimes doesn't when it's not specified (ie, http://localhost/yadda instead of http://localhost/yadda/index.php).
> 
> 

 

Try adding 'index.php' to your httpd.conf file so it looks like this:

```
DirectoryIndex index.html index.html.var index.php
```

 *eerok wrote:*   

> 
> 
> I now have to use <?php ... ?> instead of just <? ... ?> within a php file.
> 
> 

 

This is a feature, not a bug  :Smile: 

Change "short_open_tag = Off" to "short_open_tag = On". This should solve your problems.

----------

## eerok

Hmm, there's no httpd.conf for apache-2.0.52-r1, which is what I'm using on both gentoo machines.  (I have httpd.conf for a more recent apache I'm running on archlinux.)

Config files were copied over (at least /etc/apache2 was -- maybe I missed something?).  Oh, well, this isn't so much of an issue anymore.

However, now I need to upgrade to mysql-4.1 and thought I'd best get php5 as well, since I'm using it everywhere else -- will I need to upgrade apache for the php5?  Any howto's on that (I'm currently searching for info).

----------

## sca

Yes, you'l need apache-2.0.53 AFAIK. This one uses a new packaging system, moving apache configuration to /etc/apache2/httpf.conf.

Lower versions of apache2 use /etc/apache2/conf/apache2.conf (at least I think so).

----------

## Strowi

jep, sca is right, the moved it all to /etc/apache2 and merged the 2 config-files common-/apache.conf and cleared out some stuff.

I think it is much more structured than before, at least it makes much more sense to me. :Wink: 

----------

## eerok

As it turned out, I was unable to get mysql-4.1 from gentoo since there's no ebuild for the current source -- 4.1.10 is all that's mirrored now; the highest ebuild I found was for 4.1.8 ...

Since I really need db compatibility, and I have a lot of dev work to do immediately, I ended up installing lampp  :Shocked: 

Oh, well, that's life, lol.

----------

## jbain

Okay, so i've tried everything I found in this thread and I"m still having trouble... I emerge the 2.0.52 ebuild of apache, is it just completely messed up or what is going on with it? I'd like to try teh 2.0.53 one but i'm a n00b at unmasking XD never really figured out how to do that.

after upgrading to the latest apache ebuild with the consolidated config files and re-emerging php and mod_php, this *should* theoretically work? If anyone has any other advice i'd appreciate it.

EDIT::

okay, so i unmerged apache, php, and mod_php. then i deleted all the config files i could find manually. then i unmasked apache-2.0.53 and all its deps, re-emerged everything. re-added -D PHP4 to the  config file, moved php.ini into /etc/apache2 and the module into /etc/apache2/modules.d... still no dice.

I even tried giving absolute pathes to the modules directory, 

any thoughs? pointers? slaps across the face for over looking something? Anything would be greatly appreciated

should I try upgrading to php5?

----------

## UgolinoII

I have just had a very peculiar experience with a fresh install of apache-2.0.53 and mod_php-5.0.3-r2 which matched the symptoms outlined above.

The istall went fine, changed APACHE_OPTS="-D PHP5" set up the usual apache.conf (servername etc) nothing special.

Restarted apache, and php docs were not being served up properly. ie being offered for download instead of being parsed and rendered.

Some time later after much tinkering, I issued the following sequence of commands

```

reki apache2 # /etc/init.d/apache2 restart

 * Restarting apache2...                                                  [ ok ]

reki apache2 # /etc/init.d/apache2 stop

 * ERROR:  "apache2" has not yet been started.

reki apache2 # /etc/init.d/apache2 zap

reki apache2 # /etc/init.d/apache2 start

 * Starting apache2...

httpd (pid 25744) already running                                         [ ok ]

reki apache2 # /etc/init.d/apache2 stop

 * Stopping apache2...                                                    [ ok ]

reki apache2 # /etc/init.d/apache2 start

 * Starting apache2...                                                    [ ok ]

```

seems when I was restarting apache that i was being led a merry dance. And that somewhere along the line apache had got confused about whther it was started or stopped. Following the finsl sucessfull STOP / START things seemed to iron themseleves out.

On a side note, the mod_php I installed created a symbolic link 'conf' in /usr/local/apache/ which points to /etc/apache2 , which correlates to the 

```
Include conf/modules.d/*.conf
```

line in /etc/apache2/httpd.conf.

----------

## Martz

This is a complete nightmare - god knows why everything has moved around so much in minor versions.. but I'll save my rants for somewhere else...

I also have APACHE2_OPS="-D PHP4" set in my /etc/conf.d/apache file

Doing ps aux | grep apache does that apache has been started with the -D PHP4. All the config files are in place, but none of the PHP gets parsed.

I have mod_php 4.3.10-r4 installed, the move recent version refuses to compile. 

I don't expect to fix it - I've given up after spending 24 hours working on this. I wouldn't mind, but I've installed apache 1.3x more times than I care to remember, and apache2 enough times. This is crazy!

----------

## mallchin

I've been using 2.0.52 for a while knowing the conf layout changes would cause some agro, but decided to try it last night. Now I have issues parsing php files.

I'm going move the old configs and 'emerge -C apache mod_php php' then remerge them again. Hopefully a plain layout will be easier to decipher, too many old irrelevant files laying around.

Edit: All seems to be working now.

----------

## yc

I can't post data from a html form to php file -- no data displayed after the php file is called. Any ideas? Something to do with PHP and Apache setting?

----------

## mallchin

 *yc wrote:*   

> I can't post data from a html form to php file -- no data displayed after the php file is called. Any ideas? Something to do with PHP and Apache setting?

 

Are you capturing the data correctly using $_POST?

----------

## thomasvk

Is there like some kind of unofficial official fix for all this? My PHP is screwed around too, and I don't know what to do because I only do Gentoo and a more complicated Linux than Mandrake for a couple of weeks now.  :Very Happy:  This is so funny.

----------

## yc

Where should I place $_POST? in the FORM tag or somewhere else? see sample codes below:

###########html file

<form action=./dataenter.php method=post>

  <table border=0>

    <tr><td>Name: </td>

        <td><input type=text size=20 name=name></td>

    </tr>

    <tr><td>Hobby: </td>

        <td><input type=text size=20 name=hobby></td>

    </tr>

    <tr><td><input type=submit value=Submit></td>

        <td><input type=reset value=Reset></td>

    </tr>

   </table>

</form>

#########dataenter.php

<html>

<head>

<title>Data Enter</title>

</head>

<?

  $A = $name;

  $B = $hobby;

  echo $A." is a good boy! and like ".$B;

?>

</html>

After "submit" , the php file only displays "is a good boy! and like ", no parameters displayed.

----------

## mallchin

Posted form values are passed via an array, $_POST.

You can access it like so:

###########html file

<form action='dataenter.php' method='post'>

<table border='0'>

<tr><td>Name: </td>

<td><input type='text' size='20' name='name'></td>

</tr>

<tr><td>Hobby: </td>

<td><input type='text' size='20' name='hobby'></td>

</tr>

<tr><td><input type='submit' value='Submit'></td>

<td><input type='reset' value='Reset'></td>

</tr>

</table>

</form>

#########dataenter.php

<html>

<head>

<title>Data Enter</title>

</head>

<?php

$A = $_POST[name];

$B = $_POST[hobby];

echo $A." is a good boy! and like ".$B;

?>

</html>

----------

## yc

Thanks mallchin!

_POST is working now!  :Razz: 

----------

## mallchin

Your welcome  :Cool: 

----------

