简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM