Jump to:

23473 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] set_dev_servers not working as expected?

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

Page: 1
Go to End
Author Topic: 1773 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    [SOLVED] set_dev_servers not working as expected? Link to this post

    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:

    Director::set_dev_servers(array(
       'localhost',
       '127.0.0.1',
       '114.111.111.111',
       '114.111.111.112', // 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?

    Aaron

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] set_dev_servers not working as expected? Link to this post

    I have also added this to check just after set_dev_servers

    echo $_SERVER['SERVER_ADDR'];
    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.

    Aaron

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] set_dev_servers not working as expected? Link to this post

    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.

    Aaron

  • slamby
    Avatar
    Community Member
    21 Posts

    Re: [SOLVED] set_dev_servers not working as expected? Link to this post

    Aaron,
    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

    echo $_SERVER['SERVER_ADDR'];


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

    echo $_SERVER['HTTP_HOST'];


    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.

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] set_dev_servers not working as expected? Link to this post

    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.

    Example:
    I am testing on a domain called http://silverstripe.devserver.com, which runs on IP 114.111.111.111.

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

    If I put silverstripe.devserver.com 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. http://114.111.111.111/silverstripe/

    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.

    Aaron

  • slamby
    Avatar
    Community Member
    21 Posts

    Re: [SOLVED] set_dev_servers not working as expected? Link to this post

    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 http://silverstripe.devserver.com as far as I can see. It looks to me that the domain, you are testing on is devserver.com and the host on that domain which is running SS is called silverstripe. The fully qualified domain/host name for this constellation is silverstripe.devserver.com. This server has the IP 114.111.111.111. The IP itsself resolves to silverstripe.devserver.com, 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 114.111.111.111 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) - 127.0.0.1 is an IP address and also included in your dev_servers array. As long as your local hosts file has an entry which maps 127.0.0.1 to localhost, 127.0.0.1 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 http://127.0.0.1 you will be able to browse to your target again. Meanwhile your echo of HTTP_HOST will change from localhost to 127.0.0.1. This is why IP addresses will work also.

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: [SOLVED] set_dev_servers not working as expected? Link to this post

    Hi Slamby,

    I'm not insulted at all!

    However I think you have completely misunderstood my post.

    http://silverstripe.devserver.com 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 "silverstripe.devserver.com" works as expected, "devserver.com" 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.

    Ta
    Aaron

    1773 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.