One of the strenghts of PHPDevShell is how easy it is to have several configurations available, each one being completly or partially different from the others. Typical usages are:
- hosting several sites within the same PHPDevShell installation, each site having its own database parameters
- having a different subset of parameters (deabug, database host…) between the development environement and the production environment

Technically it’s the same feature, and it’s based on the site name, i.e. the Host header of the http request.

This is how it works:
- at an early point during startup, we load all files named host.config.php in a folder named config for each folder in the plugins folder
- these files are supposed to fill the $configuration['host'] array
- later in the process, the file which name is this array corresponding to the actual host name is loaded, giving you the opportunity to set up all your parameters

Multisites

For example, let’s say I have two sites, site1 and site2 ; the main folder content is as this:

/plugins
    site1
        config
            host.config.php
            site1.config.php
    site2
        config
            host.config.php
            site2.config.php

The content of /plugins/site1/config/host.config.php is:

$configuration['host']['www.site1.com'] = '../plugins/site1/config/site1';

The content of /plugins/site2/config/host.config.php is:

$configuration['host']['www.site2.com'] = '../plugins/site1/config/site2';

Then, we a request for www.site1.com is handled, the following process occurs:

1 – all files matching /plugins/*/config/host.config.php are processed ; the content of $configuration['host'] is then:

   $configuration['host'] = ['www.site1.com' => '../plugins/site1/config/site1', 'www.site2.com' => '../plugins/site/config/site2'];

2 – only the file in $configuration['host']['www.site1.com'] is then processed, namely '../plugins/site1/config/site1'. The base for the file search is /config and the postfix .config.php is automatically appened, so the file use is /plugins/site1/config/site1.config.php

That way, you can put all the parameters of each site (database parameters for example) in their separate config file.

Developement and production

Based on the same feature, you can have a separate config file for your developement and your production environments.

For exemple, when you work on “www.site1.com”, you can set up your dev environement to answer to just “site1” ; therefore:

- http://site1/ will open your dev environement
- http://www.site1.com will open your production site

Now you just have to put these two lines in your /plugins/config/host.config.php:

$configuration['host']['site1'] = '../plugins/site1/config/site1-dev';
$configuration['host']['www.site1.com'] = '../plugins/site1/config/site1-prod';

That way you can have your dev settings in /plugins/config/site1-dev.config.php and your production settings in /plugins/config/site1-prod.config.php.

Especially usefull to have all the debug and error reported enabled in dev and disabled in production!

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment