Tag Archives: Composer

“Uncaught exception ‘ErrorException’ with message ‘proc_open(): fork failed” with composer

I got this error while updating with composer:

PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:943

logo-composer-transparent

I though it was just the same error I had before that I fixed giving unlimit memory to the PHP process, but it wasn’t the same and didn’t work. The only way I could fix it was updating from PHP 5.3.10 to PHP 5.5.16 (PHP 5.4 should work too).

First of all make a backup of the Apache and PHP configuration files:

/etc/apache2/apache2.conf
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

Add the repository you need:

  • PHP 5.4: sudo add-apt-repository ppa:ondrej/php5-oldstable
  • PHP 5.5: sudo add-apt-repository ppa:ondrej/php5

And update/upgrade:

sudo apt-get update
sudo apt-get upgrade

You’ll probably get a message like this:

The following packages have been kept back:
  apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common
  libapache2-mod-php5 libapr1 libapr1-dev libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-dev libaprutil1-ldap libjson0 libjson0:i386 php-pear php5
  php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-intl
  php5-mcrypt php5-mysqlnd php5-pgsql php5-xdebug php5-xmlrpc php5-xsl
0 upgraded, 0 newly installed, 0 to remove and 29 not upgraded.

You can update those packages by hand:

sudo apt-get -y install php-pear php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-intl php5-mcrypt php5-mysqlnd php5-pgsql php5-xdebug php5-xmlrpc php5-xsl

Then remove the unnecesary ones:

sudo apt-get autoremove

And update the rest:

sudo apt-get -y install apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5

During the update process you’ll be asked what to do with your original Apache and PHP configuration files. I like letting the update process to update them so I can compare with my backups later and fix anything that’s missing. For example the xdebug.so library in PHP 5.3 was in /usr/lib/php5/20090626/xdebug.so and in PHP 5.5 it’s in /usr/lib/php5/20121212/xdebug.so.

UPDATE: Apache 2.4 uses IncludeOptional instead of Include and it made my virtual host stop working. I changed back to Include and the everything was fine.

Include sites-enabled/*.conf

Ref: https://github.com/composer/composer/issues/945
http://www.pixelite.co.nz/article/upgrading-php-54-ubuntu-1204-lts-support-drupal-8

Fix “Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes)” with composer update

I got this error today when running composer update for one of my Symfony2 projects:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 3781182 bytes) in phar:///usr/local/bin/composer/src/Composer/Util/RemoteFilesystem.php on line 202

logo-composer-transparent

Composers troubleshooting tells that you can increase the memory PHP can allocate editing memory_limit parameter in php.ini. I changed it from 128M to 512M but still didn’t work.

Finally the solution was to run composer update with no memory limit like this:

php -d memory_limit=-1 /usr/local/bin/composer update

Update composer and all packages installed with it

php composer.phar self-update
php composer.phar update

Install a Symfony2 application using Composer

Before installing any Symfony2 project you have to meet the minimum requirements for it in your server. I had some problems because I was using XAMPP at it doesn’t have the necesary PHP 5.3 version. It has to be at least PHP 5.3.3 for Symfony2 2.1 and 5.3.2 for Symfony2 2.0. That’s why I uninstalled XAMPP and installed Apache2+PHP+MySQL using MacPorts. You can see lastest Symfony2 requirements here.

Then you have to install Composer it-self. You can download Composer manually or just run this command (if you have curl installed):

curl -s https://getcomposer.org/installer | php

You can get this error while trying to download Composer:

All settings correct for using Composer
Downloading...
Download failed: failed to open stream: Permission denied
Downloading...
Download failed: failed to open stream: Permission denied
Downloading...
Download failed: failed to open stream: Permission denied
The download failed repeatedly, aborting.

That’s because you are located in a path where you don’t have write permissions. In my case I was in /var/www. That folder has 755 permissions and root:root as user:group owners. I changed its permissions to 775, its group owner to www-data and I added my user to the www-data group (adding www-data at the end of my users configuration line in /etc/group) so I could have write permissions.

Composer uses git to download Symfony2 so you have to install it:

sudo apt-get -y install git

After you have Composer and Git installed you can install the latests 2.2.0 release of Symfony2 running this command (it will take a while):

php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/new_folder 2.2

If you want to download for example the 2.1.x-dev version you can do it by running this command:

php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/new_folder 2.1.x-dev

A new folder will be created in your webroot path with the name you entered in the previous command. Now that Symfony2 is installed you have to make it available on your web server. The web folder of your new Symfony2 project is the only one you have to configure in your server. You can follow the “Configure virtual hosts for XAMPP in Mac OS X” guide to do that. Even the guide is for XAMPP and Mac OS X the process is the same for any Apache web server.

Now all the files are installed and the server is configured but we still have to change user permissions for the cache and log folders so we don’t get any errors when clearing cache and logs. This proccess depends on your system and is explained in the official configuration and setup guide in the “Setting up Permissions” section, but for Ubuntu I had to run this (supposing that the Apache user is www-data):

rm -rf app/cache/*
rm -rf app/logs/*
sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs

In Mac OS X (and other systems that support chmod +a) it would be like this (supposing that the Apache user is _www):

rm -rf app/cache/*
rm -rf app/logs/*
sudo chmod +a "_www allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

Once you have all configured you have to access the app_dev.php file in your browser.

welcome