Craft configuration on fortrabbit¶
Craft 3 uses modern
.env style configuration, learn more about the concepts here. In result, you can run your Craft locally and on remote without code or configuration file changes. Locally, your
.env file will be modified and read.
The mandatory Craft CMS security key has to be shared among all environments. We recommend to use your local security key as the master key. When you used Composer to install, that key was shown at the end of the installation. If not, open your local (hidden)
.env file from the root folder of your project and find a line that looks like this:
It will contain a value when you have installed Craft 3 correctly on your local machine. Copy that line. Go to the App's ENV vars settings in the Dashboard and paste that line. Here is the direct link:
That ENV var is already set. Just replace it with your local one. Also see the official Craft guide on that topic to learn about the different ways to create the key.
TLDR: No need to configure the MySQL database connection for fortrabbit, it should already be set. On fortrabbit the environment variables are getting seeded from the ones set in the Dashboard (not from the .env file). When you have chosen Craft in the Software Preset while have creating the App, all ENV vars at fortrabbit are already pre-populated. If not, see here.
Please include the following settings in the settings file located in
<?php return [ // Global settings '*' => [ 'useProjectConfigFile' => true, 'securityKey' => getenv('SECURITY_KEY'), 'siteUrl' => getenv('SITE_URL') ?: '@web' ], // fortrabbit 'production' => [ 'devMode' => false, 'allowAdminChanges' => false, 'allowUpdates' => false ], // local 'dev' => [ 'devMode' => true ] ];
The file contains other settings as well, keep those. For more details and options, check out our Craft CMS tuning guide.
Now, your local Craft installation should already have created a MySQL database with a few tables in it. The fortrabbit database, on the other side, is still empty. Now, export your local database and import it to the fortrabbit remote. Head over to our MySQL export & import guide to learn how to access the database on fortrabbit and export/import tables.
PRO TIP: You will probably often synchronize development and production databases. We have developed a handy command line tool: Craft Copy to speed that up. It works like this:
# Sync database up (local ⟶ fortrabbit) $ php craft copy/db/up # Sync database down (local ⟵ fortrabbit) $ php craft copy/db/down