| +34 608 61 64 10



Zend 2 - Install Doctrine 2 and MongoDb

These are the steps to install y configure on Ubuntu 14.10 a Zend 2 skeleton with Doctrine and MongoDB After installing mongoDB and PHP 5, we need to install php5-mongo, using this commands

- sudo apt-get install php5-mongo
- sudo apt-get install php-pear
- sudo apt-get install php5-dev


sudo pecl install mongo

After that, we'll modify the php.ini adding the line

I modified these both files


We can find more details here.

Now we'll proceed to install/clone the Zend 2 Skeleton using GIT and GitHub, executing this command

git clone git:// zendmongoske

Note: "zendmongoske" will be my project name.

Well...we need the composer so we'll install the composer.phar

curl -sS | php

and modify the composer.json adding these lines in the require sections.

        "doctrine/mongodb-odm": "dev-master",
        "doctrine/doctrine-mongo-odm-module": "dev-master"

It's important adding the first line, cause you could show this error during the install of composer.

paolo@paolo:/var/www/zendmongo$ php composer.phar update
PHP Warning:  Module 'mongo' already loaded in Unknown on line 0
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package doctrine/doctrine-module could not be found in any version, there may be a typo in the package name.
  Problem 2
    - Installation request for doctrine/doctrine-mongo-odm-module dev-master -> satisfiable by doctrine/doctrine-mongo-odm-module[dev-master].
    - doctrine/doctrine-mongo-odm-module dev-master requires doctrine/mongodb-odm 1.0.*@dev -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see  for more details.

Read  for further common problems.

Important Note: this is my complete composer.json file.

    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
    "homepage": "",
    "require": {
        "php": ">=5.5",
        "zendframework/zend-authentication": "~2.5.0",
        "zendframework/zend-barcode": "~2.5.0",
        "zendframework/zend-cache": "~2.5.0",
        "zendframework/zend-captcha": "~2.5.0",
        "zendframework/zend-code": "~2.5.0",
        "zendframework/zend-config": "~2.5.0",
        "zendframework/zend-console": "~2.5.0",
        "zendframework/zend-crypt": "~2.5.0",
        "zendframework/zend-db": "~2.5.0",
        "zendframework/zend-debug": "~2.5.0",
        "zendframework/zend-di": "~2.5.0",
        "zendframework/zend-dom": "~2.5.0",
        "zendframework/zend-escaper": "~2.5.0",
        "zendframework/zend-eventmanager": "~2.5.0",
        "zendframework/zend-feed": "~2.5.0",
        "zendframework/zend-file": "~2.5.0",
        "zendframework/zend-filter": "~2.5.0",
        "zendframework/zend-form": "~2.5.0",
        "zendframework/zend-http": "~2.5.0",
        "zendframework/zend-i18n": "~2.5.0",
        "zendframework/zend-i18n-resources": "~2.5.0",
        "zendframework/zend-inputfilter": "~2.5.0",
        "zendframework/zend-json": "~2.5.0",
        "zendframework/zend-loader": "~2.5.0",
        "zendframework/zend-log": "~2.5.0",
        "zendframework/zend-mail": "~2.5.0",
        "zendframework/zend-math": "~2.5.0",
        "zendframework/zend-memory": "~2.5.0",
        "zendframework/zend-mime": "~2.5.0",
        "zendframework/zend-modulemanager": "~2.5.0",
        "zendframework/zend-mvc": "~2.5.0",
        "zendframework/zend-navigation": "~2.5.0",
        "zendframework/zend-paginator": "~2.5.0",
        "zendframework/zend-permissions-acl": "~2.5.0",
        "zendframework/zend-permissions-rbac": "~2.5.0",
        "zendframework/zend-progressbar": "~2.5.0",
        "zendframework/zend-serializer": "~2.5.0",
        "zendframework/zend-server": "~2.5.0",
        "zendframework/zend-servicemanager": "~2.5.0",
        "zendframework/zend-session": "~2.5.0",
        "zendframework/zend-soap": "~2.5.0",
        "zendframework/zend-stdlib": "~2.5.0",
        "zendframework/zend-tag": "~2.5.0",
        "zendframework/zend-test": "~2.5.0",
        "zendframework/zend-text": "~2.5.0",
        "zendframework/zend-uri": "~2.5.0",
        "zendframework/zend-validator": "~2.5.0",
        "zendframework/zend-version": "~2.5.0",
        "zendframework/zend-view": "~2.5.0",
        "zendframework/zend-xmlrpc": "~2.5.0",
        "zendframework/zendxml": "~1.0",
        "zendframework/zendframework": "~2.5",
        "doctrine/mongodb-odm": "dev-master",
        "doctrine/doctrine-mongo-odm-module": "dev-master"
    "suggest": {
        "zendframework/zend-ldap": "zend-ldap component ~2.5.0, if you need LDAP features"
    "bin": [
    "extra": {
        "branch-alias": {
            "dev-master": "2.5-dev",
            "dev-develop": "2.6-dev"

After that we could execute these command lines

php composer.phar self-update
php composer.phar install
php composer.phar update // In case of you have to modify some configuration.

Next step will be more familiary for you. We'll configure the virtual host in this way:

/etc/hosts  zendmongoske.localhost


<VirtualHost zendmongoske.localhost:80>
        ServerName  zendmongoske.localhost
        ServerAlias zendmongoske.localhost

        # Indexes + Directory Root.
        DocumentRoot /var/www/zendmongoske/public

        <Directory /var/www/zendmongoske/public>
                DirectoryIndex index.php
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted

        # Logfiles
        ErrorLog /var/log/apache2/zendmongoske-error.log
        CustomLog /var/log/apache2/zendmongoske-access.log common

Finally we'll execute these commands

sudo a2ensite zendmongoske.localhost.conf
sudo /etc/init.d/apache2 restart

and we'll show our Zend 2 skeleton typing