Quantcast
Channel: How To – Paul K Leasure
Viewing all articles
Browse latest Browse all 39

Configure Symfony 4 with PostgreSQL on Ubuntu or Mac

$
0
0

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.

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
Install PostgreSQL on Mac   
On Mac OS, got to your terminal and use brew as shown here.
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.
composer require doctrine/doctrine-bundle
Configure config/doctrine.yml
Change the dbal values as shown below.
...
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:

...

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!
php bin/console doctrine:database:create

Viewing all articles
Browse latest Browse all 39

Trending Articles