Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maxccarvalho's avatar

Laravel 5 deploy

Anyone tried to deploy an application using Laravel 5?

I'm getting a error, something like this: Loading composer repositories with package information Installing dependencies (including require-dev) - Installing nikic/php-parser (0.9.x-dev ef70767) 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:983 .....

0 likes
15 replies
bashy's avatar

PHP memory limit being reached. What command(s) is your deploy script doing?

maxccarvalho's avatar

It's just the default deploy command:

git pull origin master composer install php artisan migrate --force

antonioribeiro's avatar
Level 2

First try to run composer this way:

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

If it works, just add memory_limit=-1 to your php.ini and you should be good.

If it doesn't and your box is a Homestead or Ubuntu, check if you have swap memory in your server:

free -h

And you should see something like:

Swap: 2.0G 93M 1.9G

If you don't, you better add some to your box:

sudo dd if=/dev/zero of=/swapfile bs=1024 count=2048k
sudo mkswap /swapfile
sudo swapon -a
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
chown root:root /swapfile
sudo chmod 0600 /swapfile

And reboot it.

6 likes
maxccarvalho's avatar

Hi,

Yes, my droplet is 512mb. Is not homestead, was provided by Forge.

I can upgrade my memory but, do you really believes that this is the problem?

Thanks!

theUnforgiven's avatar

I had the same problem once using 512mb droplet so created a new one with 1gb droplet and was fine. So either do as suggested above or just create a new droplet

maxccarvalho's avatar

I did the memory upgrade and now that error is gone. Unfortunately, there is another one, in my local environment this is not happening:

PHP Fatal error: Class 'Illuminate\Routing\FilterServiceProvider' not found in /home/forge/codigotv.com.br/app/Providers/FilterServiceProvider.php on line 5

Seems to be a simple thing to solve but, as I say, everything is fine in my local machine with homestead.

antonioribeiro's avatar

@maxccarvalho, you don't need to upgrade the memory, just to create some virtual memory on your box. And, yes, it might, as you can see in those Composer issues:

https://github.com/composer/composer/issues/945

https://github.com/composer/composer/issues/2704

https://github.com/composer/composer/issues/1898

I had to create virtual memory in my Forge box as well because of Composer, then I created this Ansible role, to automatize the process: https://github.com/antonioribeiro/dev-box/tree/master/roles/swap/tasks. I was not the exact same message, but it was related to memory.

EDIT:

Sorry I didn't see the memory upgrade has fixed it.

faisal.arbain@gmail.com's avatar

Yup. enable swap resolve the issue for me. In my forge, I create a recipe to enable the swap so I can easily run on new droplets.

sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0 ' | sudo tee -a /etc/fstab
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile
kushpal's avatar

Thanks its work for me

sudo dd if=/dev/zero of=/swapfile bs=1024 count=2048k

sudo mkswap /swapfile

sudo swapon -a

echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

echo 10 | sudo tee /proc/sys/vm/swappiness

echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

chown root:root /swapfile

sudo chmod 0600 /swapfile

dascorp's avatar

Lads I had digitalocean droplet 512mb but upgraded to 1gb and the issue persist, is the swap file only option, please note I'm running only one simple laravel app on the droplet, I noticed mysql consumes a lot of memory, would you recommend to switch to PostgreSQL? and uninstall mysql?

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 8388608) (tried to allocate 32768 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Request.php on line 1

Fatal error: Out of memory (allocated 8388608) (tried to allocate 32768 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Request.php on line 1

Please or to participate in this conversation.