Tag Archive: sf2

Composer update creates a lack of memory

While using Symfony 2 it’s common that you have to run the command composer update. Sometimes we’re graced with the error:

1
2
3
4
5
6
7
8
9
10
The following exception is caused by a lack of memory and not having swap configured

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:954
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 954, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(954): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(754): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(715): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(648): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(130): Symfony\Component\Console\Application->renderException(Object(ErrorException),  in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 954

The easiest way to fix it it’s by creating a virtual swap partition using the following commands:

1
2
3
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

Install and configure Symfony 2 and Sonata bundle

I found some bugs and inconsistencies while trying to install those 3 bundles by the book, so I decide to create that small tutorial.

What we gonna install:

  • Symfony Framework
  • SonataAdminBundle
  • SonataDoctrineORMAdminBundle
  • SonataEasyExtendsBundle

First we start by installing the Symfony Framework

1
composer create-project symfony/framework-standard-edition

Now we jump to the sonata bundle

1
composer require sonata-project/admin-bundle

Choose one connection, I use mysql so I need to install the SonataDoctrineORMAdminBundle

1
composer require sonata-project/doctrine-orm-admin-bundle

Activate the bundles

SonataAdminBundle

AppKernel.php

1
2
3
4
5
6
7
/* Sonata */
new SymfonyBundleSecurityBundleSecurityBundle(),
new SonataCoreBundleSonataCoreBundle(),
new SonataBlockBundleSonataBlockBundle(),
new KnpBundleMenuBundleKnpMenuBundle(),
new SonataDoctrineORMAdminBundleSonataDoctrineORMAdminBundle(),
new SonataAdminBundleSonataAdminBundle(),

config.yml

1
2
3
4
5
6
sonata_block:
  default_contexts
: [cms]
  blocks
:
   # Enable the SonataAdminBundle block
    sonata.admin.block.admin_list
:
      contexts
:  [admin]

routing.yml

1
2
3
4
5
6
7
8
admin:
    resource
: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix
: /admin

_sonata_admin
:
    resource
: .
    type
: sonata_admin
    prefix
: /admin

With this done, you should see a layout like this one in your site.

Sonata admin dashboard

At this moment we have the Sonata Admin Bundle configured in our site. We gonna process now with the Easy Extend Bundle then we end with the User Bundle.

EasyExtendBundle

Pretty simple to configure this bundle, start to download the bundle and activate the bundle in the AppKernel file.

1
php require sonata-project/easy-extends-bundle

AppKernel.yml

1
new SonataEasyExtendsBundleSonataEasyExtendsBundle(),