Friday, December 31, 2010

Using PostgreSQL with Symfony 1.4

Recently my company decided to upgrade from Symfony 1.0 to Symfony 1.4.  This upgrade was long overdue.  With this upgrade came a problem; the PDO driver for MySQL did not support an SSL connection, which is something that one of our clients required.  As a result we decided to go with PostgreSQL as our database, as the PDO driver did support an SSL connection.

After doing several Google searches and asking for help on some IRC forums, it became clear that very few people knew much about getting Symfony to work with PostgreSQL.  Not surprising since almost all PHP developers use MySQL.  Turns out, it is not as bad as it sounds to get Symfony up and running with PostgreSQL quickly.

Step 1: Install PostgreSQL.  Quick instructions for this can be found on PostgreSQL's own website: The only thing I would change about this is adding the --with-openssl option when you run the configure script before compiling.

Step 2: Start your Symfony project.  This is also pretty straight forward, the instructions for this are here:

Step 3: Download the Symfony plugin for PostgreSQL.
php ./symfony plugin:install sfPostgresDoctrinePlugin

Step 4: Publish the plugin.
php ./symfony plugin:publish-config

Step 5: Alter the config/ProjectConfiguration.class.php file to get the enablePlugins function to accept an array.

class ProjectConfiguration extends sfProjectConfiguration
public function setup()

Step 6: Create the plpgsql language.  As the postgresql user run the command:
createlang plpgsql [databasename]

And there you have it!  You should now be able to operate Symfony with PostgreSQL just like you did with MySQL.  Enjoy!


  1. This is a nice article..
    Its very easy to understand ..
    And this article is using to learn something about it..
    c#,, php tutorial
    Thanks a lot..!

  2. What postgre and php version do you use? I have problems installing postgre with Symfony :(

  3. When this article was written, it was using the latest versions of Symfony and Postgres. What kind of problems are you having?

  4. Hi Matthew,

    When I try to insert the generated sql scripts of sfPostgresDoctrinePlugin is results to an error.

  5. Can you give me some more details Mark? What operating system? What version of Symfony? What version of PHP? What version of PostgreSQL?

  6. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    Symfony Development