Preparing an .env. file

Preparing an .env.<environment> file is a crucial step in deploying your application. This file contains environment variables that are used by your application, specific to the environment you are deploying to.

What is an .env. file?

An .env.<environment> file is a file that contains environment variables for a specific environment. For example, if you are deploying to your production environment, you would create an .env.production file.

Variables to set in your .env. file

The easiest way to create an .env.<environment> file is to copy your .env file and rename it to .env.<environment>. You don't want reuse secrets across files, you should change credentials across environments.

You will want to make the changes below (the ones that are applicable to your application):

VariableDescriptionExample Format
APP_ENVSet your environment name.production
APP_DEBUGSet this to false (for any world-exposed application).false
APP_KEYYou can use php artisan key:generate to generate a new key or use this online tool.base64:...
DB_DATABASESet this to the name of your database. Use simple names and avoid weird characters.my-database
DB_USERNAMESet this to the username that will have access to your database.myusername (⚠️ Do NOT use root or admin)
DB_PASSWORDSet this to the password for the username that will have access to your database.mysupers3curepassword (⚠️ Avoid special characters. Use long alphanumeric strings instead)
REDIS_PASSWORDSet the password for your Redis database.mys3cureredispassword (⚠️ Avoid special characters. Use long alphanumeric strings instead)
REVERB_HOSTThe DNS hostname to use for Reverb. (⚠️ must be different than your SPIN_APP_DOMAIN)socket.example.com

Special Notes on database credentials

The default behavior of Postgres, MySQL, Redis, and MariaDB are to use the credentials on first initialization. This means if you change the credentials in your .env file after you've already started the database, the database automatically update the username or password of the users in your .env file.

To make a change, you'll need to use the methods described in their official documentation on how to manage users and passwords. You'll need your existing credentials to make the changes and then you'll need to update the credentials in your .env file to match the new credentials.

If you're just getting started with Spin and you deployed to a new server and just learned this the hard way (been there many times 😃), then you may consider just "Starting Over" by deleting your entire Docker data, changing your .env file, and then redeploying.