Database access from within the environment

Published

Updated

📜

Configure code to connect automatically.

Apps on fortrabbit read the database credentials from ENV vars that the platform sets. Laravel, Symfony, Craft CMS and Statamic connect without configuration, other software takes the credentials from the dashboard.

Automatic software configuration

Configure the database by ENV vars. The software templates map the platform variables to the names the software expects, so Laravel, Symfony, Craft CMS and Statamic connect without configuration.

// Generic example for illustration purposes
$pdo = new \PDO(
  'mysql:host=' . getenv('FORTRABBIT_DB_HOST') . ';port=' . getenv('FORTRABBIT_DB_PORT') . ';dbname=' . getenv('FORTRABBIT_DB_NAME'),
  getenv('FORTRABBIT_DB_USER'),
  getenv('FORTRABBIT_DB_PASSWORD'),
);
$pdo->query("SELECT * FROM ...");
php

The platform sets these database variables:

  • FORTRABBIT_DB_HOST
  • FORTRABBIT_DB_PORT
  • FORTRABBIT_DB_NAME
  • FORTRABBIT_DB_USER
  • FORTRABBIT_DB_PASSWORD

Manual software configuration

WordPress, for example, reads the database credentials from wp-config.php. Enter them there, or read the ENV vars in that file. The dashboard shows the database name, user and password.

Connecting via SSH session

mysql and mysqldump are available over SSH. Logged in, run mysql to connect to the database.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗