# installing PHP support in Apache

## skippy

So, I have apache 1.3.27 up and running fine and now I want to add basic PHP support so I can start learning it. I see I have the choice of:

```
emerge php
```

or

```
emerge mod_php
```

 or some other choice I should ues? I just want the basic PHP for learning, I can get advanced later.

Also, I've read in other posts, that I may have to edit the /etc/init.d/apache startup command? Is that true?

Thanks in advance!

----------

## reves

For the PHP Apache module you'd need just mod_php.

For information on configuring it you could check here.

You could also  search the forum for more info.

----------

## xenon

 *reves wrote:*   

> For the PHP Apache you'd need just mod_php.

 

I don't think so.

----------

## reves

 *xenon wrote:*   

>  *reves wrote:*   For the PHP Apache you'd need just mod_php. 
> 
> I don't think so.

 

I suppose I didn't type that right; you'd need Apache and mod_php but not php.

----------

## xenon

No, your post was clear, I just don't agree (but could definitely be wrong). But if you're right, what is the use of php (like in emerge php) itself? You can't just use it as a standalone scripting language, can you? I think mod_php is just a way to link the php and apache engines.

----------

## Sven Vermeulen

I can only answer for apache2 since that's what I use here...

First of all, no, you don't need php, yes you need mod_php. If you plan on using apache2, don't forget to add "apache2" to the USE-variable, otherwise mod_php won't configure itself properly (it's just a matter of location, but still).

Ofcourse, when emerging apache(2), you need to add "php" to the USE-variable too. I don't know if it is absolutely necessary (apache is modular) but better to be safe than sorry.

After that, you need to edit /etc/conf.d/apache so that apache starts with the "-D PHP" option. Otherwise it won't load the PHP-module.

You do not need to edit apache.conf/commonapache.conf (or at least not with apache2): mod_php automatischally installs an addendum configuration file.

So, in short:

```

~# nano /etc/make.conf

// Add "apache2" if you plan to use apache2

// Add "php" to have apache support php

// (Analogum for "mysql", "ldap", "ssl"...)

~# emerge apache

~# emerge mod_php

~# nano /etc/conf.d/apache

// In case of apache2: APACHE2_OPTS="-D PHP"

```

----------

## kashani

 *xenon wrote:*   

> No, your post was clear, I just don't agree (but could definitely be wrong). But if you're right, what is the use of php (like in emerge php) itself? You can't just use it as a standalone scripting language, can you? I think mod_php is just a way to link the php and apache engines.

 

mod_php does not require php and vice versa. You can in fact run seperate versions of both with seperate ini files on the same system... though that does get confusing at points.

kashani

----------

## rac

I agree with kashani.  The "php" ebuild is the command-line interpreter.  mod_php is what you want for integration with webservers, and it does not require php.

----------

## xenon

Ok, I was wrong.   :Smile: 

----------

## reves

Yeah the php is the command line interface. You could use it for shell scripts or you could use it with gtkphp.

----------

## xenon

Uh. Glad to know. I never thought php could live outside of a browser.  :Smile: 

----------

## skippy

Well, I finally had a chance to give it a try and here is what I found out. You do not need php, just the mod_php. I just installed apache with: 

```
emerge apache
```

 Then I installed mod_php using: 

```
emerge mod_php
```

 I then followed anther sugestion I found in the forum. Which is to do this from the command line: 

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

 Then I edited this file: 

```
 /etc/conf.d/apache
```

 And added this line to the bottom: 

```
APACHE_OPTS="-D PHP4"
```

 And then I had to reboot and PHP worked!

I also tried to just to this from the command line: 

```
/etc/init.d/apache restart
```

 Although it did reload apache fine, it did not enable the PHP portion. After rebooting (and nothing else) PHP worked fine for a sample hello.php file I had.

Thanks for all your help, everyone.

----------

