12

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.

Community
  • 1
  • 1
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
  • If you hope use two connections,just take a look here : http://stackoverflow.com/questions/8440403/how-to-create-2-connections-mysql-and-postgresql-with-doctrine2-in-symfony2 – Nll May 14 '12 at 18:50

1 Answers1

35

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

Robin
  • 3,512
  • 10
  • 39
  • 73
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236