Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

[SOLVED] set_dev_servers not working as expected?


7 Posts   1784 Views


26 November 2009 at 12:38pm (Last edited: 26 November 2009 1:00pm), Community Member, 604 Posts

Hi all,

I'm creating a custom install for SS where my team enters both dev and live database settings during installation.

Works fine, and I planned to use the set_dev_servers method to handle the logic between the credentials.

Here is my code:

   '', // Both of these IP's are our Dev server

// Database credentials. Logic here for switching between servers.
// As Dev mode is automatically set by IP address only, we can just check if we are in Dev Mode and switch.
global $databaseConfig;

if(Director::isLive()) {
// Site is in LIVE MODE
$databaseConfig = array(
"type" => "MySQLDatabase",
"server" => "liveserver",
"username" => "liveuser",
"password" => "livepassword",
"database" => "livedatabase",
} else {
// Site is in DEV MODE
$databaseConfig = array(
"type" => "MySQLDatabase",
"server" => "localhost",
"username" => "devuser",
"password" => "devpassword",
"database" => "devdatabase",

However, when I view a new installation on the dev server with the above in _config.php, Director::isLive() validates to true and it uses the wrong credentials.

Anyone see what I'm doing wrong there, or what may be going on?



26 November 2009 at 12:53pm Community Member, 604 Posts

I have also added this to check just after set_dev_servers

echo Director::get_environment_type();

IP is one of the ones in the above list

get_environment_type() returns "live".

SS 2.3.3. Has anyone ever had something like this working? I swear I saw this exact method in the docs but now devmode docs is empty.



26 November 2009 at 1:00pm Community Member, 604 Posts

Ah I see,

set_dev_servers requires the domain, not the IP. When I add the domain for the current site to that array, it goes into DEV mode.

Would rather it work by IP, but hey, it works now.



27 November 2009 at 5:16am Community Member, 21 Posts

I just post to this thread because I think it could be confusing someone who has a similar problem.

As far as I see for the dev_servers array there are both, IP-Addresses and Hostnames allowed. Your check with


is not correct, because if you look up the code in static function Director::is_dev(); you will see that they are using


to check if a host is included in array dev_server instead.

If you do an echo of this variable, you will get the Hostname (which could contain the domain name of course), not the domain, of the Server which you will have to include in your dev_serves array.


27 November 2009 at 8:40am Community Member, 604 Posts

Hi Slamby,

No I don't it think should confuse anyone. Your post confuses me actually and I think you have misunderstood.

From my tests, and certainly by what you state in your own code investigation, the method only checks based on HTTP_HOST. Therefore the dev_servers array does not seem to do any checking of the server IP address, only the host name used to run the site.

I am testing on a domain called, which runs on IP

If I put in the dev_server array, the site is NOT put into dev mode.

If I put in the dev_server array, the site IS put into dev mode.

Adding IP's to the dev_server array seem to only server a purpose if you are actually using those IP's to browse to your silverstripe installation. E.G.

The purpose of my post was that it does not seem possible to set an entire IP address as DEV mode, regardless of the domain the site is running on. And this appears to be accurate.



27 November 2009 at 10:51am Community Member, 21 Posts

Hi Aaron,

I do not want to insult you. Sorry if I did.

What I like to say it that SS is checking for the HTTP_HOST, and checking against the dev_servers array.

You are not testing at a domain which is called as far as I can see. It looks to me that the domain, you are testing on is and the host on that domain which is running SS is called silverstripe. The fully qualified domain/host name for this constellation is This server has the IP The IP itsself resolves to, which is taken from your dns entries. If you do not have this dns entry - in your zone files or your hosts file - then it would not resolve and would be the HTTP_HOST. If then the IP address would be in your dev_servers array, SS would run in dev mode.

Please take a look at the original dev_servers array (from a fresh checkout) - is an IP address and also included in your dev_servers array. As long as your local hosts file has an entry which maps to localhost, is not triggered. If you delete the entry you wont be able to browse to http://localhost anymore, since your box relies on IP addresses and there is no matching entry anymore. Instead calling you will be able to browse to your target again. Meanwhile your echo of HTTP_HOST will change from localhost to This is why IP addresses will work also.


27 November 2009 at 11:06am Community Member, 604 Posts

Hi Slamby,

I'm not insulted at all!

However I think you have completely misunderstood my post. is not the real domain I am testing on, but I am testing on a subdomain that looks pretty much exactly the same. Trust me, I am not testing on TLD portion. This is proven by the fact that adding "" works as expected, "" does not.

The entire point of my post is that the dev_servers array is checked against the hostname, NOT the IP that silverstripe is currently running on. Your posts are pretty much confirming that, so I don't see what the confusion is sorry.