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):
Variable | Description | Example Format |
---|---|---|
APP_ENV | Set your environment name. | production |
APP_DEBUG | Set this to false (for any world-exposed application). | false |
APP_KEY | You can use php artisan key:generate to generate a new key or use this online tool. | base64:... |
DB_DATABASE | Set this to the name of your database. Use simple names and avoid weird characters. | my-database |
DB_USERNAME | Set this to the username that will have access to your database. | myusername (⚠️ Do NOT use root or admin ) |
DB_PASSWORD | Set this to the password for the username that will have access to your database. | mysupers3curepassword (⚠️ Avoid special characters. Use long alphanumeric strings instead) |
REDIS_PASSWORD | Set the password for your Redis database. | mys3cureredispassword (⚠️ Avoid special characters. Use long alphanumeric strings instead) |
REVERB_HOST | The DNS hostname to use for Reverb. (⚠️ must be different than your SPIN_APP_DOMAIN ) | socket.example.com |
Special Notes on database credentials
⚠️ NOTE: If you change the credentials in your .env
file after you've already started the database, the database will not automatically update to your new credentials. You'll have to manually update the credentials in the database itself. Refer to the official Docker image documentation for the database you're using for more details.
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.