Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freeza's avatar

Different environments Setup

Hello guys, i will start my second laravel project soon. This time i want to develop with different environments (dev, prod). In my last project i developed only on prod... that sucks.

Okay... i know that Laravel has a build in environment-handler. But how do you work with that in the best way?

My idea/Workflow:

Two seperate folders for my laravel project. In each folder my laravel project exists:

  • dev-project
  • prod-project
  • if Dev-Changes are OK then copy file-changes to prod?
  • additional: if a code-part is only for the dev-environment then you say:
IF DEV environment THEN 
...
END IF

is that right? Did i understand it?

0 likes
6 replies
christopher's avatar
Level 30

You set the environment in your .env file: http://laravel.com/docs/5.1/installation#environment-configuration

So for example in your .env file you have APP_ENV=local. Laravel now know its in dev mode. On your production server you can add the env var APP_ENV=production . Now Laravel knows that the system is in production mode.

The common workflow would be to develop locally, push your changes to for example github and envoyer / forge pulls the latest version automatically as soon as you pushed something to your repo.

You dont need two folders - just use git.

If you need some logic in your app to get the current status you can use

if (App::environment('local')) {
    // The environment is local
}

as descriped in the docs.

1 like
freeza's avatar

Ah okay... so i did understand it correct :) Thank you!

Just another question to the Database Workflow:

If i change/add tables in my local environment, i have to get this changes with artisan on my prod environment manually right? Or do you know an automatic solution as like automatic pulls from git?

christopher's avatar

Do you mean the actual db records or tables?

If you add/change a table you use migrations: http://laravel.com/docs/5.1/migrations If you need fake records or "build in" records you use Database seeding: http://laravel.com/docs/5.1/seeding

If you are on your local env and need fake data you may take a look at the built in faker: http://laravel.com/docs/5.1/testing#model-factories / https://github.com/fzaninotto/Faker

Now on your server you need to run php artisan migrate to add the new tables or change columns. If you are using a service like laravel forge or envoyer, these services does it all for you.

So if you push something to your repo, forge pulls the latest git version and then runs php artisan migrate. If you are not using something like a auto deployment you have to ssh into your server and run the command manually.

2 likes
freeza's avatar

OK perfect! Thank you... i guess i can start now! :)

Best regards

Please or to participate in this conversation.