# [SOLVED]Configure Apache to work with PHP4 and PHP5

## shadowShad

So hello every body.

I'm a newby in php, and I've tried to install 2 version of php on my server but I've some problems to configure Apache to work with PHP4 and PHP5.

I choose to put PHP4 working in CGI mode and PHP5 working as an Apache module. I've followed the Guid : 

http://svn.gnqs.org/projects/gentoo-php-overlay/file/docs/php4-php5-configuration.html?format=raw

But I still have a problem, PHP5 work fine but PHP4 CGI doesn't work 

When I try to view a file with .php4 extension I get this error : 

```
You don't have permission to access /php4-cgi/info.php4 on this server.[/
```

code]

my file : /etc/apache2/modules.d/php4-cgi.conf

```
<IfDefine PHP4CGI>

    ScriptAlias /php4-cgi /usr/lib/php4/bin/php-cgi   

    Action php4-cgi /php4-cgi

    AddHandler php4-cgi .php4 .php3 .phtml

</IfDefine>
```

my file : etc/apache2/modules.d/70_mod_php5.conf

```
<IfDefine PHP5>

   # Load the module first

   <IfModule !sapi_apache2.c>

      LoadModule php5_module    modules/libphp5.so

   </IfModule>

   # Set it to handle the files

   <IfModule mod_mime.c>

      AddType application/x-httpd-php .php

      AddType application/x-httpd-php .phtml

      AddType application/x-httpd-php .php5

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

   </IfModule>

   AddDirectoryIndex index.php index.phtml

</IfDefine>
```

And I put in my /etc/conf.d/apache2  : 

```
APACHE2_OPTS="-D PHP4CGI -D PHP5"
```

And for my virtual host I have : 

```
<VirtualHost *:80>

    ServerAdmin toto@webserv.com

    DocumentRoot /home/toto/boulot/www

    ServerName localhost

   <Directory "/home/toto/boulot/www">

        Options Indexes FollowSymLinks

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>    

    <IfModule peruser.c>

        ServerEnvironment apache apache

        MinSpareProcessors 4

        MaxProcessors 20

    </IfModule>

</VirtualHost>

```

I don't understand, can anyone help meLast edited by shadowShad on Fri Dec 16, 2005 6:55 am; edited 1 time in total

----------

## danapsimer

Have you checked the file permissions on the file and directory?

----------

## shadowShad

The permission file of the cgi script is : 

for the command :

```
 ls -l  /usr/lib/php4/bin 
```

```
-rwxr-xr-x  1 root root 1719748 Dec 14 13:58 php

-rwxr-xr-x  1 root root 1748820 Dec 14 13:58 php-cgi

-rwxr-xr-x  1 root root     738 Dec 14 13:58 php-config

-rwxr-xr-x  1 root root    4016 Dec 14 13:58 phpize

```

Is that you want to known? It's seems to me that the permissions are good no?

----------

## pjp

Moved from Other Things Gentoo

----------

## c4

 *shadowShad wrote:*   

> When I try to view a file with .php4 extension I get this error : 
> 
> ```
> You don't have permission to access /php4-cgi/info.php4 on this server.
> ```
> ...

 

I had an idea that perhaps it was the directory setting for Apache that was causing the error rather than being a PHP4 issue.

You say that php5 works fine, does this include files from withing the above directory? 

I was thinking that perhaps you are using a common Apache setup with a default folder setting like

```
<Directory />

  Options -All -Multiviews

  AllowOverride None

  <IfModule mod_access.c>

    Order deny,allow

    Deny from all

  </IfModule>

</Directory>
```

thus denying access for everyone to any directory without an indexfile like index.html or index.php inside. I assumed you were opening http://localhost/php4-cgi/info.php4 and recieving the error?

I don't have any working setup with Apache at the moment so I can't check, but my guess was that because the directory was not specified in your vhost-setting, the directory was defaulted to " Order deny,allow Deny from all" and so you recieved the access forbidden error.

Also, have you checked the apache error-log for further information?

----------

## shadowShad

You are right!!

Thank you the problem come from the apache configuartion file : /etc/apache2/httpd.conf

I let this directive by default : 

```
<Directory />

      Options none

      Order Deny,Allow

      Deny from All

</Directory>
```

and indeed this directive denying access for everyone to any directory, and I haven't defining a vhost for php4-cgi,

if I coment this directive php4 cgi works fine, but I think that it's preferable to defining a vhost.

Thank you very much.

----------

## shadowShad

by adding 

```
<Directory "/usr/lib/php4/bin/">

    Options none

    AllowOverride None

    Order allow,deny

    Allow from all

</Directory>
```

in httpd.conf the problem is solved and I cant let uncomented the default directive :[/code]

```
<Directory />

       Options none

       Order Deny,Allow

       Deny from All

</Directory>
```

----------

## Rebuke

I followed the guide here http://www.gentoo.org/proj/en/php/php4-php5-configuration.xml and ran into the same problem, is it worth adding this note to the guide as I'm assuming that myself and the OP are not unique  :Wink: 

----------

## NautilusIII

YES, please add this to the guide!!!

----------

