RE: Virtual Hosts - How to Configure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There might have been a little confusion as to what I proposed.  First,
assuming that php is installed in c:\php, create the directory
c:\php\includes -- this will be where we put all of our files so that they
can be accessed by php no matter where your web root (site files) are
located.  This directory can really be anywhere, the only requirement is
that you let php know where the directory is.  You do this by setting the
"include_path" variable in your php.ini, like shown below.  Now, you are
telling php where to look for files, php will first look in the current
directory, then in the c:\php\includes directory.  This is important later.

The next setting in your php.ini is the "auto_prepend_file".  By setting
this, you are saying that file specified will always be prepended to every
php page that PHP executes--it will execute before anything else does.
Because we also set the "include_path" directive, PHP will look for the
"setup_vhost.php" file in the c:\php\includes directory; therefore, place
the setup_vhost.php there.

The "setup_vhost.php" file also opens up files also located in
c:\php\includes.  So, create the directory c:\php\includes\vhosts.  Then
create the "www.host1.com.php" and "www.host2.com.php" files inside this
newly created directory.  The contents of these files are really segments
from your php.ini that are specific to a particular domain.  PHP allows us
to dynamically set configuration values, so all we must do is read the
settings from the correct file, and then tell PHP what they are; this is
exactly what "setup_vhost.php" does.

Hope this helps.
Court

> The most straight forward that I can see would be to always 
> prepend a php file that does the appropriate ini_set's based 
> on $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'].  For example:
> 
> 
> ::::: your php.ini :::::
> include_path = ".;c:\php\includes"
> auto_prepend_file = setup_vhost.php
> 
> 
> ::::: c:\php\includes\setup_vhost.php :::::
> $settingFile = 'vhosts/'.$_SERVER['HTTP_HOST'].'php';
> if (file_exists($settingFile)) {
>   $settings = parse_ini_file('vhosts/'.$_SERVER['HTTP_HOST']);
>   foreach($settings as $setting=>$value) {
>     ini_set($setting, $value);
>   }// foreach
> }// if
> 
> 
> ::::: vhosts/www.host1.com.php :::::
> ; <?php exit; ?>  # this line is here to make sure nothing 
> happens if executed smtp = host1domain.com sendmail_from = 
> webmaster@xxxxxxxxx
> 
> 
> ::::: vhosts/www.host2.com.php :::::
> ; <?php exit; ?>  # this line is here to make sure nothing 
> happens if executed smtp = host2domain.com sendmail_from = 
> webmaster@xxxxxxxxx
> 
> 
> 
> of course, you could pull the data from a db and make the 
> logic in setup_vhost more complex; but you should get the 
> point from this simplified example.

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux