So in my general config file I've defined an environmental variable called basePath (as per the Environment-Specific Variables documentation). I'm using the getcwd() function to get the working directory.

return array(
    '*' => array(
        'environmentVariables' => array(
            'basePath' => getcwd(),

I'm using this for a few reasons:

  1. I work in an environment where many people can be working on the same project at the same time. So their local basePath is always different.

  2. My different siteUrls for my setup use trailing locales in the url: 'siteUrl' => array( 'en' => 'http://www.website.com/', 'fi' => 'http://www.website.com/fi/' ). So when it comes to targeting environment-specific locales, things get messy.

  3. $_SERVER['DOCUMENT_ROOT'] is ok locally, but fails on a live server.

So my problem is when using getcwd(), the locale is included in path. Is there a way to trim this out dynamically?

Or is there a way to strip out the current locale from this path on-the-fly? rtrim(getcwd(),"fi")

Maybe there is a more reliable way to get the working directory?

1 Answer 1


Check out craft-multi-environment; even if you don't use it, you might crib some of the ideas from it.

For instance, how the basePath is determined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.