# Problem with PHP and Apache

## tony_yum

Hi. I've recently done 

```
emerge --newuse apache mod_php
```

 with php in the USE flag. I have 

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

 in /etc/conf.d/apache2 and

```
AddType application/x-httpd-php .php

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

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

in /etc/apache2/conf/apache2.conf

I restarted apache2, and try accessing info.php from the web browser which has the following

```
<html>

<body><?php phpinfo(); ?></body>

</html>
```

And the web browser display exactly that code. Apache doesn't seemed to have parsed the PHP code.

Is there some steps that I have missed?

Thanx in advance.

----------

## TheRAt

You are certain you have emerged PHP4, not 5... your config file enables 4..

----------

## markp2000

I don't know if the addtype goes in the /etc/conf.d/apahce2 file.  I have mine in the /etc/apache2/conf/commonapache2.conf file.

Mark

----------

## nobspangle

The addtype and loadmodule simply go in the apache config file it doesn't matter where. However gentoo have provided us with a nice simple way of doing things.

In /etc/apache2/conf/modules.d are several files depending on what extra modules you have installed and what options you compiled apache with, the apache config automatically includes all of these files into the config. If you look in the file 70_mod_php.conf you will see the line <IfDefine PHP4> this means if you start apache with the option -D PHP4 it will include this file in the config. This means you do not have to edit your config files to get php to work you only need to add the -D PHP4 to APACHE2_OPTS in /etc/conf.d/apache2

So in short you have not missed any steps, you have performed too many.

----------

## DarkStorm_Inc

noob, even w/o the extra steps of adding to the conf it still doesnt work. I have php4 apache2 installed and it doesnt work as you have described... gentoo was nice to do that.. but it doesnt work well imo. Installing a std apache install w/o all the gentoo extras would be better. At least that cant be blamed on gentoo not working right during emerge...

----------

## lookinin

tony_yum: Have you gotten anywhere with this?

DarkStorm_Inc: Your problem is identical to tony_yum's?

 *Quote:*   

> Hi. I've recently done
> 
> Code:
> 
> emerge --newuse apache mod_php
> ...

 

Just a note: apache doesn't care if php is in your use flags

```
# emerge -pv apache mod_php

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] net-www/apache-2.0.52-r1  +berkdb -debug -doc +gdbm +ipv6 -ldap +ssl -static -threads 0 kB 

[ebuild   R   ] dev-php/mod_php-4.3.10  -X +apache2 +berkdb +crypt -curl -debug -doc -fdftk -firebird -flash -freetds -gd -gd-external +gdbm -gmp -hardenedphp -imap -informix +ipv6 -java -jpeg -kerberos -ldap -mcal -memlimit -mssql +mysql +nls -oci8 -odbc +pam -pdflib -png -postgres -qt -snmp +spell +ssl +tiff +truetype +xml2 -yaz 0 kB 
```

 *Quote:*   

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

 

As nobspangle mentioned, these settings should all ready exist in /etc/apache2/conf/modules.d/70_mod_php.conf, so there is no need to add them otherwise.  Check that this file exists.  

And to be thorough, I would remove the lines you said you added to /etc/apache2/conf/apache2.conf.

There is only one config file that needs a change - and that is in /etc/conf.d/apache2 (again, as all ready mentioned):

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

I apologize if I sound rude, but I want to make sure that point is clear.  Moving along - have you guys both checked your versions, remerged, etc?  What is the output of:

```
# qpkg -v -I apache

# qpkg -v -I mod_php
```

Have you looked at your logs in /var/log/apache2/error_log?  Mine has output like the following:

```
[Mon Feb 21 19:54:32 2005] [notice] Apache/2.0.52 (Gentoo/Linux) PHP/4.3.10 configured -- resuming normal operations
```

----------

## mmschnei

This might be a stupid suggestion but after adding "-D PHP4" to /etc/conf.d/apache2 have you restarted your apache server?

----------

## j-m

 *tony_yum wrote:*   

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

 

Uhm, why are you doing this, all of this and more is in /etc/apache2/modules.d/70_mod_php.conf  :Question: 

----------

## truth_bk

I have a feeling some of these guys might actually be opening the files straight up on the web broswer.... I dont mean to insult anyone's intelligence, and this might just be me supposing things I shouldn't.... but hey, I saw no one mentioned it above. You have to make sure these php files are "served" by the apache server. You have to make sure you put these in the document root: /var/www/localhost/htdocs (by default) before you open them in your browser!! Make sure you do this, it's the webserver that runs the php code, NOT your broswer.

Anyway, if you do know this, as you might, don't feel insulted by this suggestion!  :Smile: 

----------

## RikBlankestijn

I had to add apache2 to the USE-flags, and then after re-emerging mod_php. I did:  *Quote:*   

>  * To have Apache run php programs, please do the following:
> 
>  * Edit /etc/conf.d/apache2 and add "-D PHP4" to APACHE2_OPTS
> 
>  * This is a CHANGE from previous behavior, which was "-D PHP"
> ...

 

Thanks lookinin.

----------

