Running Symfony CMF With Gaudi

Emmanuel Quentin
Emmanuel QuentinFebruary 09, 2014
#cms#oss#tutorial#php

Symfony CMF is a new Content Management Framework based on Symfony 2. This project won the Symfony Open-Source Application Award 2013, and is used at marmelab for a project with more than 900K documents.

Symfony CMF requires several third-party components to be installed: Jackrabbit, MySQL, Apache, and of course PHP. Gaudi simplifies the build of linked components, so it will be hepful to setup and run a Symfony CMF project. Gaudi runs a Docker container for each required components defined in a simple configuration file.
It was instroduced in a previous post.

Symfony CMF

Creating The Configuration File

The .gaudi.yml file lists all components required to run the Symfony CMF Sandbox :

applications:
    front:
        type: apache
        links: [app]
        ports:
            8080: 80
        volumes:
            .: /var/www
        custom:
            fastCgi: app
            documentRoot: /var/www/web
            modules: [rewrite]

    app:
        type: php-fpm
        links: [jackrabbit]
        apt_get: [php5-gd, php5-intl]
        ports:
            9000: 9000
        volumes:
            .: /var/www
        custom:
            modules: []

    jackrabbit:
        type: jackrabbit
        ports:
            8082: 8082
        volumes:
            .gaudi/jackrabbit: /opt/jackrabbit/jackrabbit

Jackrabbit

You may notice that it is similar to the configuration file of the Gaudi Symfony tutorial.

Instead of starting a MySQL server, we start Jackrabbit, and make it listen on port 8082.

As Docker does not keep data when a container is removed, we need to mount a folder from the host machine into /opt/jackrabbit/jackrabbit (where Jackrabbit stores its documents).

Php-fpm

The Jackrabbit server is linked to the app application, which runs a PHP-FPM server. During the build of app, we tell Gaudi to:

  • install php5-gd & php5-intl required by Symfony CMF
  • mount the current folder to /var/www
  • listen to the port 9000

Apache

The Apache server is called app, and is configured to:

  • mount the current folder to /var/www
  • listen on the 8080 port
  • redirect all requests to the port 80 of the container
  • redirect all Fast-CGI requests to the app application
  • define the DocumentRoot to /var/www/web (required by Symfony)
  • enable mod_rewrite

Starting All Components

To start all the 3 components (Apache2, PHP-FPM & Jackrabbit), just run :

gaudi

Wich will output something like :

Cleaning front ...
Cleaning app ...
Cleaning jackrabbit ...
Building gaudi/front ...
Building gaudi/app ...
Building gaudi/jackrabbit ...
Starting jackrabbit ...
Application jackrabbit started (172.17.0.69:8082)
Starting app ...
Application app started (172.17.0.70:9000)
Starting front ...
Application front started (172.17.0.71:8080)

Installing Symfony Cmf

Attach the app container to run some commands :

docker attach app
cd /var/www

git clone https://github.com/symfony-cmf/cmf-sandbox.git && mv cmf-sandbox/ . && rm -rf cmf-sandbox
cp app/config/parameters.yml.dist app/config/parameters.yml
cp app/config/phpcr_jackrabbit.yml.dist app/config/phpcr.yml

Configuring Symfony CMF

Docker injects some environment variables for linked containers. In this example, the injected variables in the app container are:

JACKRABBIT_PORT_8082_TCP_ADDR=172.17.0.69
JACKRABBIT_PORT=tcp://172.17.0.69:8082
JACKRABBIT_PORT_8082_TCP_PROTO=tcp
JACKRABBIT_PORT_8082_TCP_PORT=8082
JACKRABBIT_NAME=/app/jackrabbit
ACKRABBIT_PORT_8082_TCP=tcp://172.17.0.69:8082

We need to inject some on them in the Symfony configuration by creating a new app/config/parameters.php file:

<?php
$container->setParameter('phpcr_backend', [
    "type" => "jackrabbit",
    "url" => getenv('JACKRABBIT_PORT_8082_TCP_ADDR').':'.getenv('JACKRABBIT_PORT_8082_TCP_PORT')."/server/"
]);

Include this file in the app/config/config.yml after - { resource: phpcr.yml } :

imports:
    # ...
    - { resource: phpcr.yml }
    - { resource: parameters.php }

Install all dependencies :

composer install

Finaly create the Jackrabbit workspace :

php app/console doctrine:phpcr:workspace:create sandbox
php app/console doctrine:phpcr:repository:init
php app/console -v doctrine:phpcr:fixtures:load

You are now go to go and check the result at http://localhost:8080/hello.

Feel free to give me some feedback or bug report in Gaudi's project.

Did you like this article? Share it!