Part II - Creating a virtual host
| Appendix J. Setting up PHP5 in parallel with PHP4 in SuSE 10.1 |

## Part II - Creating a virtual host

### Step 1; Adding an alias IP-address to Your server

In this example we will assume that the server is called "gamma" and have the primary address "192.168.0.50". The virtual host will be called "gamma2" and will be located at address "192.168.0.51". The easiest way to add another address alias is to use yast2 and the network configuration module and simple add a new alias.

### Step 2; Creating different document and cgi roots

In preparation of the new virtual host we want it to have a separate document and cgi (where we will store the PHP5 binary) roots compared with the standard server. For this purpose we add two new directories "/srv/www/gamm2-htdocs/" and "/srv/www/gamma2-cgi-bin/" on the server.

### Step 3; Configure Apache with a virtual host

For his we add a new small config file named "gamma2_vhost.conf" (the exact name is not important as long as it ends in *.conf) in the "/etc/apache2/vhosts.d/" directory. The script we add is

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    # Setup gamma2 on secondary IP-address
    <VirtualHost 192.168.0.51>

     DocumentRoot /srv/www/gamma2-htdocs/
     ServerName gamma2
     ServerAdmin root@localhost

     # We use a separate CGI directory
     ScriptAlias /cgi-bin/ /srv/www/gamma2-cgi-bin/

     # For good measure we also add recognition of PHP5 index
     DirectoryIndex index.php5

     # This is the two critical statement for this virtual
     # host we activate PHP5 as a CGI module
     Action php5-cgi /cgi-bin/php
     AddHandler php5-cgi .php5 .php

     <Directory /srv/www/gamma2-cgi-bin/>
      AllowOverride None
      Options +ExecCGI -Includes
      Order allow,deny
      Allow from all
     </Directory>

     <Directory "/srv/www/gamma2-htdocs/">
      Options None
      AllowOverride None
      Order allow,deny
      Allow from all
      DirectoryIndex index.html index.php
     </Directory>

     UserDir public_html

    </VirtualHost>

We do not go into any more detail of this configuration since it should be fairly easy to understand. For details we refer to the Apache documentation.

What we have accomplished with this file is that when we call the server on the second address any php file will be recognized by apache as a file to be handled by the "php5-cgi" action. This in turn means that whenever Apache encounters a *.php5 (or *.php) file it will run the program "/cgi-bin/php". This path in turn will be expanded to " /srv/www/gamma2-cgi-bin/php".

In the next section we will show how to compile PHP5 and put the executable CGI version in this directory.

| Up |
| Home |