I'm trying to set up multi-environment configs.

I have specific db settings I want to change depending on environment. I am using localhost and my Digital Ocean server IP address in my db.php file.


return array(

'*' => array(
    'tablePrefix' => 'craft',
'localhost' => array(
        'server' => 'localhost',
        'user' => 'root',
        'password' => 'root',
        'database' => 'something',
'xxx.xxx.xxx.xxx' => array(
            'server' => 'localhost',
            'user' => 'some_user',
            'password' => 'some_password',
            'database' => 'somethingelse',

I've tried switching the order, that did not work.

Do I need to use a domain name rather than a IP address here?

1 Answer 1


The short answer is yes — you need to use a domain names.

You might also want to have a look at this multi-environment configuration method defined on the craft cookbook website that creates a global php variable called CRAFT_ENVIRONMENT in your main index.php.

I generally use that in combination with Ben Parizek technique as described in this answer.

  • Why bummer? Do you not have a domain name? I should clarify that if you are accessing the server via the IP address in the browser, then the ip address should also work as the domain name. And if you really want to use the IP address regardless, then I'm sure you could also set the CRAFT_ENVIRONMENT variable based on the ip address using SERVER('SERVER_ADDR'). For localhost, you would just also need to use Commented Apr 14, 2015 at 15:12
  • I'm working on a site for a client, they have a domain name, but I don't want to switch this site live yet, so I have set up server space elsewhere and have them access the site via the IP address. Once finshed, I will switch the DNS records to this server. Will have to look more into CRAFT_ENVIRONMENT variable, I am not that familiar with using it.
    – Nick
    Commented Apr 15, 2015 at 16:29
  • I see your problem. To clarify the 'CRAFT_ENVIRONMENT' variable is a made-up variable used in the craft cookbook configuration method that I linked. But you'll notice with that they are using server variables to determine the environment — don't see why you couldn't use the IP instead of domain name to do the same thing. Another option that might work is to create a subdomain (stage.domain.com) and only point the subdomain to that server. Commented Apr 15, 2015 at 16:51

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.