Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:34:26+00:00 2026-06-15T22:34:26+00:00

I am moving over the the Laravel framework, but I am having trouble with

  • 0

I am moving over the the Laravel framework, but I am having trouble with the database settings,

Specifically, I have my environments setup, and they are working fine for the application.php config file, however the database.php config file seems to have no effect.

Even if I have a database.php config file in my environments folder it is never loaded, I put a bunch of invalid characters (keyboard mash) into the file to get php to throw an error, but it is never hit.

Does Laravel not support environment based database settings? or am I doing this wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:34:27+00:00Added an answer on June 15, 2026 at 10:34 pm

    You can definitely set database settings (and any other config setting) by environment.

    For Laravel 3 (for Laravel 4 and Laravel 5 see below):

    Firstly – you need to define $environments in your paths.php and set it to something like this:

    $environments = array(
      'development' => array('*.dev'),
      'production' => array('*.com'),
    );
    

    Laravel will automatically look for this variable, and if set, will use the associated configuration.

    Normally you have a config folder, with settings such as database.php and auth.php

    Now just create a new folder for each Laravel_Env you plan to use (such as Development). You’ll end up with a folder structure like this;

    /application
      /config
        /development
          database.php
        /production
          database.php
        application.php
        config.php
        database.php
        ...
        user_agents.php
    

    You’ll note I’ve only included database.php in each subfolder. Laravel will always load the default config settings first, then override them with any custom configs from the environments setting.

    Finally, in your development/database file, you would have something like this;

    <?php
     return array(
    'default' => 'mysql'
     );
    

    p.s. I just tested this on the current 3.2.12 build of Laravel – and it definitely works.

    Bonus Tip: You can also automatically set an environment for Artisan, so you do not have to include the environment manually on each command line! To do this:

    1. You need to know your ‘hostname’ that you are running Artisan on. To find out – temporarily edit the artisan.php in your root folder, and add var_dump(gethostname()); to line 2 (i.e. above everything).

    2. Run php artisan from the command line. You will get a string dump with your hostname. In my case its “TSE-Win7”;

    3. Remove the changes to the artisan.php file

    4. Add your hostname (i.e. “TSE-Win7”) to the environments.

    You should end up with something like this:

    $environments = array(
      'development' => array('*.dev', 'TSE-Win7'),
      'production' => array('*.com'),
    );
    

    Artisan will now run using your development environment. If you deploy to a live server – re-run these steps to get the hostname() for the server, and you can configure a specific artisan config just for the server!

    For Laravel 4:

    The default environment is always production. But in your start.php file you can define additional environments.

     $env = $app->detectEnvironment(array(
       'local' => array('your-machine-name'),
    ));
    

    On Linux and Mac, you may determine your hostname by type hostname in your terminal – it will output the name of your computer. On Windows put dd(gethostname()); at the beginning of your routes.php file – and run the website once – it will show you the current hostname of your computer.

    To get the current environment as a variable in your application – read this SO answer here. Laravel 4: how can I get the environment value?

    For Laravel 5:

    There is single configuration file, called .env in your root directory.
    Watch this laracast, config explained fully.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on moving over to OOP in PHP. I have reading
Moving over from django / python, I am having a little trouble getting the
I am trying to overlay a moving average over an OHLC chart but it
So if I have a WPF window, would moving another window over the WPF
I have an application that is moving over from WCF Http to named pipes
I have been moving over to JavaScript (esp. canvas) from Flash / Flex /
Sort of new to Git, but I'm thinking of moving over from SVN. I
I have a J2SE program that I'm moving over to use JPA. The existing
I have a legacy PHP form that I'm moving over to Drupal 6. I'm
VC++ 2010, OpenGL, GLSL, SDL I am moving over to shaders, and have run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.