Doctrine setup
| ORM bundle | |
| DATABASE_URL | |
| Create the database | |
| Check the connection |
ORM bundle
Doctrine is the database layer of Symfony. One meta package, the ORM pack, installs the bundle, the configuration files, and the console commands:
Install the ORM pack
composer require symfony/orm-pack
[OK] The ORM pack is installed and configured
You run this command once per project. Later lessons use the commands it installs.
DATABASE_URL
Connection details live in the .env file as a single URL. Driver, user, password, host, and database name all sit inside DATABASE_URL:
DATABASE_URL="postgresql://user:secret@127.0.0.1:5432/blog?serverVersion=16"
Swap the values to match your own database server. The course examples use a database named blog.
Create the database
Build the empty database from that URL with one console command. Run it inside the project folder:
Create the database from DATABASE_URL
php bin/console doctrine:database:create
Created database `blog` for connection named default
The command only creates the database itself. Tables arrive later through migrations.
Check the connection
That success message proves three things at once: the URL parses, the server runs, and the credentials work.
A connection error at this step almost always means a typo in the URL or a stopped database server. Compare the error message with the value in .env before changing anything else.
Next: Entities
Article author: Arthur Isaev