If you’re trying to deploy a Symfony project – or Laravel, or pretty much anything using composer – and your deployment server is a little anemic on the memory side of things (Amazon AWS, tiny Digital Ocean droplets, even the basic Linode offerings), then you may well hit an issue when you run
composer update during your deploy.
Anyway, after much frustration, here is my fix – which works for me, hopefully it will work for you too.
This assumes you are developing locally and then deploying to prod using git, which I highly advise. But it will work for any type of deploy if you follow the steps and tweak accordingly.
- Do a composer update on your dev box
- Commit the updated composer.lock file
- Push the commit with the lock file to your prod server (or wherever you’re getting that error)
- From the prod server (or wherever), delete your composer cache (
rm -rf ~/.composer)
- From the prod server (or wherever), delete your vendor folder (
rm -rf vendor)
- From the prod server (or wherever), run
So, whilst the above is the high level overview, here’s how I did it irl.
- Using ssh, I connected to my development virtual machine (VMWare), where from the Symfony root dir (/var/www/html/myproject.dev/), I ran
- Wait a while, whilst number 1 finishes.
- From my local machine, download the newly updated
composer.lockfile. Git sees this as a changed file, and so I can then do a
git commiton the updated composer.lock file
- As I have already set up a
git remotefor my production server, I can then do a
git pushfor the commit with the lock file to my production server.
- When the commit hits the server, the post-receive hook is run automatically, which does all the Symfony deploy stuff like clearing the cache, dumping assets, reinstalling vendors etc.
If all this sounds great, but deploying with Git is something you’re unsure of, I highly recommend this Digital Ocean article, which makes it very easy.
Hope it helps!