Updating your Composer-based installation (e.g. Laravel) as root

On August 17, 2017 by aTutorMe

If you have root access to your web server (congratulations!) and you need to update your composer-based installation, e.g. Laravel, then you may get the following warning if you try to run composer update as root.

Take a read of https://getcomposer.org/root for more details.

 

Thanks to user Weboide’s answer on AskUbuntu Question 839107 I was able to run composer as www-data (the Apache user).

Steps:

  1. chsh www-data
  2. Enter the new value, or press ENTER for the default: /bin/bash
  3. su www-data
  4. run composer update in your Laravel directory

[Edit, 28 Feb 2018] PS: For future access you only need to run steps 3 and 4.

[Another edit, 28 Feb 2018]

Sometimes your memory may still be limited (e.g. on a VPS controlled by someone else) and the composer update doesn’t work. I found that shutting down apache, mysqld and php frees up valuable memory.
kill $(ps aux | grep '[p]hp' | awk '{print $2}')[1]

systemctl stop apache2.service
systemctl stop mysqld
[2]

 

[1] https://easyengine.io/tutorials/linux/kill-all-processes/
[2] https://askubuntu.com/questions/824979/stop-lamp-in-16-04