Recently I had a project where I was writing some Behat tests involving custom steps that I didn’t want to run on production. The steps created and destroyed data, and I don’t like touching the production database if I don’t have to, so they were really only for running locally and in CI. I was writing in a switch that would detect whether or not the tests were running on a production environment and exit gracefully if they were. I started by changing the APP_ENV variable in my .env file to ‘production’ so I could test the switch. No luck. I dumped the variable, and saw that it was ‘local’. Weird, right?
Gets weirder. I ran
php artisan env from the terminal, and got
Current application environment: production, as expected. However, when I ssh’d in to my homestead box and ran the same command, I got
Current application environment: local. Very, very strange.
Turns out that homestead sets the APP_ENV variable to local by default - it’s set in the homestead.yml file (at least, it was for the version of homestead that I’m using). It looks like this:
variables: - key: APP_ENV value: local
Removing that is the first step. Inside your homestead box you also have to edit ~/.profile and remove all the lines where APP_ENV is set to local. Then reprovision homestead with
homestead provision, make sure you have a fresh session, clear the cache, and your development environment will start respecting your .env settings for APP_ENV - which can come in all kinds of handy.