Ubuntu – Running Composer without using sudo (tried changed owner and permissions)


Every time I run composer (e.g., sudo composer install, sudo composer self-update etc.) I need to run this with sudo as the owner of the file is root.

However every time I use the composer with sudo root owns the vendor folder and then I have to change the owner of that folder/privileges from root to www-data.

What is the best way to fix this so I do not have to run sudo every time?

Change the owner of /usr/local/bin/composer from root to www-data?

Is this the ideal way to handle this to avoid having to change ownership and assign permission every time I use sudo composer install?

The permissions for composer are currently -rwxr-xr-x. And I've tried switching the owner of /usr/local/bin/composer over to www-data:www-data with permissions set to 775, and still I can't run composer without running sudo.

Best Answer

If "everyone" is allowed to read and execute composer, you don't need to use sudo:

sudo chmod 755 /var/local/bin/composer

Since you already executed composer at least once as root, composers (per-user-)cache directory is now owned by root and therefore isn't writable by your normal user.

sudo chown -R lamp:lamp /home/lamp/.composer

will fix the file-owner.

Related Question