<p>Should be able to. Use a switch statement to check on the host and then server up the correct environment configuration like so:</p>

<p>public/index.php:</p>

<pre><code>switch (strtolower($_SERVER['SERVER_NAME']))
{
    // Staging
    case 'stage.mydomain.com' :
        define('CRAFT_ENVIRONMENT', 'stage');
        $craftPath = '../../craft';
        break;

    // Local
    default :
        define('CRAFT_ENVIRONMENT', 'local');
        $craftPath = '../craft';
        break;
}
</code></pre>

CC BY-SA 3.0
2016-11-01T12:36:18.543Z
2016-11-01T17:40:31.697Z
2016-11-01T17:40:31.697Z
Ian Young
<p>On my local dev sever, as well as the production server, the <code>craft</code> folder is one level above web root, so <code>$craftPath</code> in <code>index.php</code> is set like so:</p>

<p><code>$craftPath = '../craft';</code></p>

<p>On the staging server, the <code>craft</code> folder is two levels above web root, so <code>$craftPath</code> needs to be:</p>

<p><code>$craftPath = '../../craft';</code></p>

<p>Can this be accomplished in a single index.php file? Something similar to the multi-environment array in <code>config/general.php</code> and <code>config/db.php</code> perhaps?</p>

<multi-environment>
Can multi-environment configuration be used in 'index.php'?
# Can multi-environment configuration be used in 'index.php'?

(Asked by: username_0 on 2016-11-01)

On my local dev sever, as well as the production server, the `craft` folder is one level above web root, so `$craftPath` in `index.php` is set like so:

`$craftPath = '../craft';`

On the staging server, the `craft` folder is two levels above web root, so `$craftPath` needs to be:

`$craftPath = '../../craft';`

Can this be accomplished in a single index.php file? Something similar to the multi-environment array in `config/general.php` and `config/db.php` perhaps?

**Tags:** multi-environment

---

## 1 answers

### Answer by username_1 on 2016-11-01. Score: 3 | Accepted answer

Should be able to. Use a switch statement to check on the host and then server up the correct environment configuration like so:
public/index.php:
switch (strtolower($_SERVER['SERVER_NAME']))
{
    // Staging
    case 'stage.mydomain.com' :
        define('CRAFT_ENVIRONMENT', 'stage');
        $craftPath = '../../craft';
        break;

    // Local
    default :
        define('CRAFT_ENVIRONMENT', 'local');
        $craftPath = '../craft';
        break;
}


---

