【问题标题】:How to change a database to postgresql with Symfony 2.0?如何使用 Symfony 2.0 将数据库更改为 postgresql?
【发布时间】:2012-05-14 18:03:14
【问题描述】:

我在 Debian 下有一个 Symfony2 项目。将我的数据库更改为 postgresql 的步骤是什么?

注意:这个问题已经被问到here,但我相信它是 symfony 1.4 的。

【问题讨论】:

标签: postgresql symfony


【解决方案1】:

debian下安装postgresql:

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

在/etc/php5/apache2/php.ini中,添加:(这其实是可选的)

extension=pdo.so
extension=php_pdo_pgsql.so

更改 symfony apps/config/paramters.ini 文件:

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

重新启动你的项目:

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

你已经完成了!

参考资料:

Symfony documentation for configuring databases

Postgresql installation under debian

【讨论】:

  • 你不应该告诉 postgres 以 mypguser 身份运行吗?或者你为什么要添加用户?
  • @Hendrik,你是对的,不需要添加用户。
猜你喜欢
  • 1970-01-01
  • 2015-05-03
  • 2019-01-06
  • 2016-10-18
  • 2016-02-08
  • 2010-09-27
  • 2021-10-01
  • 2012-02-12
  • 2016-06-11
相关资源
最近更新 更多