Use a postgres database with symfony3 Use a postgres database with symfony3 postgresql postgresql

Use a postgres database with symfony3



Finally, I fixed it by removing all the files that manage php and reinstalling php with homebrew.


---- Removing php ----
First, I used the following command from root (cd /) to find all the files starting by "php"

find . -name "php*"


Depending on the results (you might have a lot), remove all the files that need to be removed (at this point it's your judgement that matter). For example, I removed files in /usr/local and /usr/bin but not in /Applications or /Homebrew.
Examples :

rm -Rf /usr/bin/php*rm -Rf /usr/local/php*


Sometimes, you can have a "permission denied" error even with sudo but it didn't make problem at the end.


---- Reinstalling php ----


Once everything concerning php is removed, you can reinstall it using the following command line :

brew install php56 --with-postgresql

If you have a "libz not found" error, you will need to launch the following command :

xcode-select --install

and relaunch the installation with :

brew reinstall php56 --with-postgresql

If everything went well, you will only have to define the field date.timezone in php.ini and you will have new php system. You can check that you have the pdo_pgsql module installed using this commande line : php -m.


---- Connect your database to your symfony project ----


First, you need to modify the file app/config/parameters.yml in your project by adding the following code :

# Postgresl    psql_database_driver: pdo_pgsql    psql_database_host: 127.0.0.1    psql_database_port: 5432    psql_database_name: your_database_name    psql_database_user: your_user_name    psql_database_password: your_password

The fields host and port can be different but this two are the default values for symfony and a postgres database.


Then, you will have to modify the file app/config/config.yml at the Doctrine Configuration level this way :

# Doctrine Configurationdoctrine:    dbal:        default_connection: pgsql        connections:           #Mysql           default:                driver:   pdo_mysql                host:     "%database_host%"                port:     "%database_port%"                dbname:   "%database_name%"                user:     "%database_user%"                password: "%database_password%"                charset:  UTF8           #Postgresql           pgsql:                driver:   pdo_pgsql                host:     "%psql_database_host%"                port:     "%psql_database_port%"                dbname:   "%psql_database_name%"                user:     "%psql_database_user%"                password: "%psql_database_password%"                charset:  UTF8        #mapping_types:            #geometry: string    orm:        auto_generate_proxy_classes: "%kernel.debug%"        naming_strategy: doctrine.orm.naming_strategy.underscore        auto_mapping: true

This is an example you can adapt as you wish.

Now, you can connect your database to your project with this command line :

php bin/console doctrine:database:create --connection=pgsql

If you already have entities in your src/AppBundle/Entity you can create your tables with :

php bin/console doctrine:schema:update --force


Everything must be alright now. I hope, it will help someone else who faces this kind of problems.