Composer requires sudo for simple -V command - php

I'm trying to set up Composer for use with Heroku, but am running into problems. I've followed the download steps here which generates the composer.phar file. I then moved it to /usr/local/bin/composer per the instructions here. Now when running composer from CLI I get the error
Could not open input file: /Users/myusername/.composer/composer.phar
sudo composer -V gets me the version number,but with the warning
Do not run Composer as root/super user! See https://getcomposer.org/root for details
The link seems unrelated to a simple -V command, which I can't imagine I should need to sudo to run anyway. I've done this installation pretty much by the book, but it seems like this isn't right.

I suspect non-root users do not have execute permissions.. From a shell on my system, I get...
ls -al /usr/local/bin/composer
-rwxr-xr-x 1 root user 1201562 Dec 8 2015 /usr/local/bin/composer
eg; Full perms for root, read & execute for everyone else. You may need to ..
sudo chmod 755 /usr/local/bin/composer

Related

Unable to change file mode on bin: Operation not permitted

I'm trying to install Composer globally on Mac OS.
I tried to move the composer.phar file by using this command in Terminal as instructed in the Getting Started section:
mv composer.phar /usr/bin/composer
I get this error:
mv: rename composer.phar to /usr/bin/composer: No such file or
directory
When I try create the directory it says the operation is not permitted:
bash-3.2# mkdir -p /usr/bin/composer mkdir: /usr/bin/composer:
Operation not permitted
I even tried to navigate to the "bin" directory and it says:
bash-3.2# mkdir composer mkdir: composer: Operation not permitted
I've enabled root successfully but still I try and alter the permissions:
bash-3.2# chmod ugo+rwx "bin" chmod: Unable to change file mode on
bin: Operation not permitted bash-3.2#
What am I doing wrong here?
Thanks in advance!
EDIT:
Thanks for the responses!
When I type the following command:
ls -leO#d /usr/local/bin
It prints:
-rwxrwxr-x 1 username staff - 2212003 27 Mar 17:00 /usr/local/bin
Background: /usr/bin is generally for "standard" binaries, not things you install yourself; those generally belong someplace like /usr/local/bin. In recent versions of macOS, this is enforced by System Integrity Protection and by keeping "system" files/directories on a separate, read-only volume.
The problem: It looks like on your system, there's a file named /usr/local/bin rather than a directory. This can happen if some installer tries to install a program to /usr/local/bin (e.g. with mv someprogram /usr/local/bin) without first making sure a directory by that name exists.
How to solve it: The first thing to do is to move/rename whatever file got installed as /usr/local/bin, and then create it as a directory:
sudo mv /usr/local/bin /usr/local/bin-moved
sudo mkdir -p /usr/local/bin
Once that's straightened out, you should be able to install composer normally. According to this (and adding sudo to get access to the directory), you'd do that with:
sudo mv composer.phar /usr/local/bin/composer
Finally, if you want to, you can try to figure out what program got installed as (rather than in) /usr/local/bin. Or just delete the /usr/local/bin-moved file and don't worry about it.
/usr/bin is a protected system folder. Do not change its permissions.
Instead install it somewhere else, e.g. into /usr/local/bin. You may still need to run the copy command with sudo though: sudo mv composer.phar /usr/local/bin/composer

Jenkins user cannot run composer install

I am trying to run the composer installer from Jenkins project folder as Jenkins user.
/usr/local/bin/composer install
I get the message
Content-type: text/html
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Composer could not find a composer.json file in /usr/local/bin
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
I don't know why it is looking for composer.json inside usr/local/bin.
If I run this as the root user it works. Can someone explain what I am doing wrong?
this is my environment
pwd
/var/lib/jenkins/workspace/project_staging
whoami
jenkins
You should be able to install composer using the following instructions:
curl -sS https://getcomposer.org/installer | php56
In order to avoid any issues
cd ~/bin
ln -s /usr/local/bin/php56 php
Modify your ~/.bash_profile file and change:
PATH=$PATH:$HOME/bin To `PATH=$HOME/bin:$PATH`
Then close your SSH session and start a new one, or run:
source ~/.bash_profile
Then ~/bin path will then take precedence and you will be using the correct version of PHP.

Composer global require Laravel/Installer not working on Ubuntu

I'm trying to run composer global require "laravel/installer" on my Ubuntu machine (Trenta OS Distro) and for some reason I can't get it to install.
file_put_contents(./composer.json): failed to open stream: Permission denied
I get the error above on every attempt. I've been unable to find any help on google so I'm guessing this isn't a very common problem. I tried whereis command on that file and it gives me a location
/usr/local/bin/composer
I tried running chmod -R 777 on that file but it did nothing. I don't know what else to do.
Composer was installed on my machine with the following command
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
I thought composer.json only comes with projects, but I shouldn't need an existing project in order to simply set up the Laravel Installer right?
I had the same problem and after reading this answer I solved it updating the .composer folder permissions:
sudo chown -R $USER:$USER /home/$USER/.composer
Where $USER is your machine's username.
Update: As #Lucas Bustamante pointed, you don't need to change $USER for your username, its an environment variable already.
As Ian Warner commented out, is not a good idea to run composer as sudo user, because it can lead to security issues.
usr/local/bin/composer composer global require "laravel/installer"
usr/local/bin/composer composer create-project --prefer-dist laravel/laravel myblog
I think this may solve your problem as it did for me.
I made a bash file for the whole process of global installation of Laravel.
download it from here, open a terminal in the bash file directory and run the command below:
bash Laravel_Global_Installer.sh
This bash file manages installations of:
Latest version of PHP and its extensions
Latest version of Composer (Global)
Latest version of Laravel (Global)
This will help you install Composer Globally and without sudo. Therefore you will be able to install Laravel Globally.
first run whereis composer then
navigate to the that directory and run
sudo chown -R $USER:$USER / composer
use sudo before the command,
for e.g.: sudo composer global require "laravel/installer"

permission denied for composer in /usr/local/bin/

I followed the documentation on https://getcomposer.org/doc/00-intro.md#globally to install composer globally on arch linux. When I do composer self-update, I get this message:
[ErrorException]
rename(/home/hannes/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied
The permissions in /usr/local/bin/ (I changed them to 777, but it did not help):
-rwxrwxrwx 1 hannes users 1104202 30. Mai 18:07 composer
In my home directory I did this:
sudo chmod -R 777 .composer/
In /etc/php/php.ini, the open_basedir looks so:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/usr/local/bin/
I also tried sudo composer self-update but it did not work as well and is possibly not the right way. (?). What else could I try to make this work?
On Ubuntu server >= 16.04
FIRST
sudo rm /usr/local/bin/composer
AND
cd ~/.cache/composer
chmod 755 composer-temp.phar
sudo mv composer-temp.phar /usr/local/bin/composer
this might be the case if you have downloaded composer.phar directly ,
but not by running php composer-setup.php
make composer.phar executable with following command before moving it to /usr/local/bin/composer or after moving
sudo chmod 755 composer.phar
composer-setup.php will make this change for us by default
You should check the permissions of the directory /usr/local/bin/, not just the file within. The process has to write both, the file and into the directory which both must be granted.
Apart from that, a general hint: do not always set everything to 777. There is no reason for that and it makes your system vulnerable.
According to the line you posted in the last comment the directory is currently writeable only for the root user himself. That would explain the error you get. You should not make your own user account the owner, Linux systems are multi user environments. Instead think about one of these approaches:
add the account that is meant to execute the composer to the group root (a user account can belong to several groups) and make the directory group writeable
change the groups ownership of the directory to a group that account is a member of and make the directory group writeable
use the sudo utility to install and update the composer utility
The last option is the typically chosen and preferred one. It leaves permissions as they are (conservative) and only uses raised privileges for system maintenance jobs like installation and upgrade.
Use sudo command for any command which writes to root files of folder. It worked for me.
use sudo "your command"
Even after moving the file via sudo mv composer.phar /usr/local/bin/composer I was getting a permission error when trying to run the composer command. sudo chmod 755 /usr/local/bin/composer fixed things for me.
You could temporarily add the rights to your working user, then update composer w/o errors and then get back the rights.
sudo chmod 777 /usr/bin/
composer self-update
sudo chmod 755 /usr/bin/
Now, there is a package for composer in arch linux which works for me:
sudo pacman -S composer
This did the job for me on Centos 7
chown -R apache:apache path/to/composer
chmod 755 path/to/composer
make sure composer already at /usr/local/bin and then do following things
chmod 755 composer
if permission denied, add sudo
For those who are using shared server here are the steps.
Let's first download composer file.
cd ~
curl -sS https://getcomposer.org/installer | php
Now we can access composer by:
~/composer.phar
Assuming you have /public_html in root directory, here are the steps to use latest composer.
cd public_html
~/composer.phar update
In future, if you want to update composer:
~/composer.phar self-update
Hope this is helpful.
My solution on macOs was the following:
First delete the directory yo created. Somehing like '/usr/local/bin/composer' using this command: rmdir /usr/local/bin/composer.
Now try to install composer again using Homebrew :
Step 1: brew install composer.
Step 2: brew link composer.
Now you can run composer in terminal.
For composer 2
sudo composer self-update --2
For composer 1
sudo composer self-update --1
if permission denied you should use the command with sudo like:
sudo composer self-update

"sudo composer" command works but "composer" is not?

This is going to be easy one I guess. On my OS X - Yosemite I have copied composer.phar to my /usr/bin directory. I have been using it for a while but today I needed to run "composer update". It didnt work of course so I ran "sudo composer update". Then I got the message "command composer not found". Chmm
I copied composer to /usr/local/bin according to the documentation and now "sudo composer" works like charm. BUT when I run "composer" without sudo, it still uses the old one in "/usr/bin" directory. So I deleted it.
Now composer works only with sudo command. I get "Could not open input file: /usr/bin/composer.phar" otherwise. What should I do to point command "composer" to the new location in /usr/local/bin?
Another alternative to get a nice composer command instead of composer.phar:
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin
$ ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
Edit:
/etc/bashrc
Add this to that file:
alias composer="php /usr/local/bin/composer"
run:
source /etc/bashrc
Composer should now run without sudo.
Okay, I encountered issues of having to run composer commands with sudo as well, but in order to get it working without throwing this kind of error (in Ubuntu 15.10):
[ErrorException]
copy(/home/randomuser/.composer/cache/files/barryvdh/laravel-cors/056068736ff8f002514178e1416c7665732eaddc.zip): failed to open stream: Permission denied
What simply solved the issue for me is:
Navigating to my home directory $ cd
Changing the ownership of .composer with: sudo chown -R $USER:$USER .composer/
Then composer install works smoothly.
PS: this might be different for other situation.
Hope this helps :)
i will answer you how i solve it in my Ubuntu 16.10 and you can compare yours
my composer folder set in
/home/abdallah/.composer/
i only give this file the 777 permission so can be reached by any user group
sudo chmod -R 777 /home/abdallah/.composer/
and that is it
i hope this helpful for you
Judging from other answers it seems the solution can vary depending on your system. This is how I fixed the problem on Mac 10.12.
My composer executable in /usr/local/bin/composer had a different group than ~/.composer/ config and cache files.
/usr/local/bin/composer myusr admin
~/.composer/ myusr staff
The primary group for myusr is staff so I changed the group for /usr/local/bin/composer to staff.
/usr/local/bin myusr$ chgrp staff composer
Cache files that had been created when running composer as sudo in the past were still causing problems so I deleted those. Composer cache files are located here: ~/.composer/cache/
If updating hangs during composer update for a project check/empty cache files in the .composer directory for the project.

Categories