How to configure Symfony 4 with PostgreSQL on Ubuntu or Mac OS
Install PostgreSQL on Ubuntu
Easily install PostgreSQL from the command line with apt-get.
1 2 3 4 5 6 |
sudo apt-get update sudo apt-get install postgresql postgresql-contrib |
Install PostgreSQL on Mac
On Mac OS, go to your terminal and use brew as shown here.
1 2 3 4 5 6 |
brew install postgresql postgres -V to see the version |
Use composer to install Doctrine
If Doctrine is not already installed, then from the command line in your Symfony 4 project directory, use composer to require doctrine.
1 2 3 4 5 |
composer require doctrine/doctrine-bundle |
Configure config/doctrine.yml
Change the dbal values as shown below.
1 2 3 4 5 6 7 8 9 10 |
... doctrine: dbal: driver: 'pdo_pgsql' charset: utf8 ... |
Edit the .env file.
PostgreSQL may create a user matching the user you logged in as. You will need to change the db_user and password to whatever is appropriate. Replace the mysql settings with the PostgreSQL settings as shown below:
1 2 3 4 5 6 7 8 9 |
... DATABASE_URL=pgsql://db_user:db_password@127.0.0.1:5432/db_name ... |
Now you can use the command line to create the database!
1 2 3 4 5 |
php bin/console doctrine:database:create |