Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a database to postgresql with Symfony 2.0?

I have a Symfony2 project under Debian. What are the steps to change my database to postgresql ?

Note: The question has been asked here, but it is with symfony 1.4, I believe.

like image 809
Benjamin Crouzier Avatar asked May 14 '12 18:05

Benjamin Crouzier


1 Answers

Install postgresql under debian:

apt-get install postgresql postgresql-client
apt-get install php5-pgsql
adduser mypguser
su - postgres
psql
CREATE USER mypguser WITH PASSWORD 'mypguserpass';
CREATE DATABASE mypgdatabase;
GRANT ALL PRIVILEGES ON DATABASE mypgdatabase to mypguser;
\q

In /etc/php5/apache2/php.ini, add: (this is in fact optional)

extension=pdo.so
extension=php_pdo_pgsql.so

Change the symfony apps/config/paramters.ini file:

[parameters]
    database_driver:    pdo_pgsql
    database_host:      localhost
    database_port:      null
    database_name:      mypgdatabase
    database_user:      mypguser
    database_password:  mypguserpass

Relaod your project:

php bin/vendors update
php app/console assets:install web
php app/console doctrine:schema:create
php app/console doctrine:fixtures:load
chmod 777 -R app/cache app/logs

You're done!

References:

Symfony documentation for configuring databases

Postgresql installation under debian

like image 147
Benjamin Crouzier Avatar answered Oct 11 '22 14:10

Benjamin Crouzier