PHPCR (PHP Content Repository) is a Content Repository library written in PHP, based on the Java Content Repository (JCR) standard. You can read more about it here. Furthermore, PHPCR is being used in the Symfony2 CMF (Symfony2 Content Management Framework) project which aims to build a foundation for future development of CMS applications using Symfony2.

PHPCR needs to connect to a content repository to store and persist the data. There are several options for content repositories, the most mature right now is Jackrabbit, a Java implementation. By default, Jackrabbit stores the data in the filesystem, which is fine for testing and development, but for production, you may want to store the data in a database. Here is how to configure Jackrabbit so it can use MySQL.

When you start Jackrabbit for the first time, it will create a default directory structure and configuration files. They are created in the current working directory, or you can specify the location with –repo


java -jar /path/to/jackrabbit-standalone-2.4.2.jar --repo /path/to/repo

If you are using the Doctrine PHPCR ODM bundle in Symfony2, there is a command to start/stop the server


./app/console  doctrine:phpcr:jackrabbit start

This will create your repository in app/Resources/java/jackrabbit/jackrabbit

Once you have the default configuration files, stop the server, and open the repository.xml configuration file. You will need to modify the PersistenceManager section under the Workspace configuration. The resulting configuration should look like this:

<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
  <param name="url" value="jdbc:mysql://host/db"/>
  <param name="user" value="user"/>
  <param name="password" value="pass"/>
  <param name="databaseType" value="mysql"/>
  <param name="schemaObjectPrefix" value="${wsp.name}_"/>
</PersistenceManager>

Replace host, db, user and pass with your MySQL connection information. Make sure the database exists in MySQL, and that the user has access to it. When Jackrabbit starts, it will create all the tables needed.

Before you start the server, you need to make sure the MySQL driver can be loaded by Jackrabbit. If you don’t have the jar, download it and install it. Modify your CLASSPATH so it can be found. If you are on Mac OSX, copy the mysql-connector-java-5.0.8-bin.jar file to /Library/Java/Extensions.

If you created your workspace before making this change, you may need to delete the workspace directory and recreate your workspace, so Jackrabbit starts using MySQL with it.