I'm trying to get the Laravel PHP framework installed and for that I need to install Composer. However I'm getting stuck there. I installed it before for Symfony but I couldn't get it to work so I think I deleted it.
When I open the terminal on Mac and enter one of the commands for installing composer like:
curl -sS https://getcomposer.org/installer | php
I get:
-bash: php: command not found
curl: (23) Failed writing body (0 != 1635)
Why is this?
You can install it via Brew.
First, install Brew;
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then you can use Brew to install Composer;
brew install composer
That's it, it's now installed. You can verify this by running composer --version
download file from https://getcomposer.org/installer
execute the file
sudo php installer
and move the file
mv composer.phar /usr/local/bin/composer
Here it is:
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
First install brew if not installed in Mac:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update brew and install php and composer.
$ brew update
$ brew install php
$ brew install composer
Verify by checking version:
$ composer -V
I hope it helps.
try
~ which php
/usr/bin/php
curl -sS https://getcomposer.org/installer | /usr/bin/php
just open your terminal and follow this steps,
here odbase is username of my mac.
cd /Users/odbase/Downloads
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar
mv composer.phar /usr/local/bin/composer
(if this produce error please run with prefix sudo. {sudo mv composer.phar /usr/local/bin/composer})
installed for check
cd /usr/local/bin
ls
I deleted some files that I should not have deleted. Did a repair install of OS X and now it works.
Related
I was trying to install the Composer on my macOS version: high sierra--> 10.13.4
but after using the command:
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
It created some files and directory but it didn't download the composer.
My terminal displayed following error:
No log handling enabled - using stderr logging
Created directory: /var/db/net-snmp
Created directory: /var/db/net-snmp/mib_indexes`
How can I resolve this problem?
OLD Answer (The Ruby Homebrew installer is now deprecated and has been rewritten in
Bash.):
First install Brew on your MAC:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
NEW Answer:
First install Brew on your MAC:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install PHP:
brew update
brew install php
brew install composer
To test installation, run:
$ composer -V
Install Brew in Mac Terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Composer
brew install composer
Check Composer
composer -V
Install download the composer using the following curl command in the
terminal:
curl -sS https://getcomposer.org/installer | php
After the command, you will have composer.phar file in the current
directory and the composer command is available as:
php composer.phar [composer commnad]
In order to make composer available globally, you have to move the
recently downloaded composer.phar to local user’s bin folder as follow:
go to /usr/local/bin folder . You can click Shift + Command + G to open
the dialog to go to folder.
move the recently downloaded composer.phar in the usr/local/bin folder
create a alias using command alias composer="php
/usr/local/bin/composer.phar"
Now, you can access the composer from the terminal simply using the
composer command. Thats it.
I'm trying to install composer running the command provided on the getcomposer.org/download documentation site:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
But I get an error message saying:
Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in Command line code on line 1
Warning: copy(): Failed to enable crypto in Command line code on line 1
Warning: copy(https://getcomposer.org/installer): failed to open stream: operation failed in Command line code on line 1
Yoshihiros-MacBook-Pro:~ yoshihiro$ php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Warning: hash_file(composer-setup.php): failed to open stream: No such file or directory in Command line code on line 1
Installer corrupt
Warning: unlink(composer-setup.php): No such file or directory in Command line code on line 1
Yoshihiros-MacBook-Pro:~ yoshihiro$ php composer-setup.php
Could not open input file: composer-setup.php
I'm also trying to install it globally but I can't get out of this message. Please help D:
I had same issues but this what I did:
I copy paste this into the terminal php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" on the terminal which download the composer to the directory where you are currently In.
(the problem was causing because of the https protocol)
And then
php composer-setup.php --install-dir=/usr/local/bin --filename=composer run this command, which installs the Composer to my bin folder so that i could run it globally.
Then you have to unlink the composer php -r "unlink('composer-setup.php');"
Finally check the see the Composer installed composer -V.
Good Luck !
I had the same problem-
here is the right way
clean dir > Terminal > mkdir composer
cd composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/
vim ~/.bash_profile
alias composer="php /usr/local/bin/composer.phar"
I had same issues but this what I did:
I ran curl -sS https://getcomposer.org/installer | php on my terminal which made composer to be installed on my PC.
And then I moved Composer to my bin folder so that i could run it globally mv Composer.phar usr/local/bin/composer.
It works for me as follows:
I ran
curl -sS https://getcomposer.org/installer | php
on my terminal which made composer to be installed on my PC.
And then I moved Composer to my bin folder so that I could run it globally:
mv Composer.phar usr/local/bin/composer
The instructions in Composer official page is sometimes confusing
or not working on macOS Sierra.
But installation is still simple like before.Just simply run two lines of command on your Terminal.
curl -sS https://getcomposer.org/installer | php
mv composer.phar usr/local/bin/composer
I have same problem and I try this step:
Open your terminal
Copy this code in your php folder, In My laptop, I have use lampp then I go to xampp folder.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
So, if you have get this message below:
All settings correct for using Composer
Downloading...
Composer (version 2.0.8) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
You can copy this code:
php -r "unlink('composer-setup.php');"
Untill here you have succesfully install composer
Check it with this code composer
Thanks
Please don’t use any of it. I’m not saying its wrong.
Please follow the link https://getcomposer.org/download/ for installing latest version of composer.
The reason is because hen you download from getcomposer.org you are downloading latest file like https://getcomposer.org/installer & composer-setup.php.
And comparing with wrong SHA384 hash_file (like e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae), so it will not work.
I had also the same issues to install composer after a clean install of macOS Sierra. My solution to get it work:
Open your terminal
sudo php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');"
sudo php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php
sudo php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
To verify if it's all installed properly type: composer -V
You can also just put composer.phar (which is what you end up with after you do the install) wherever you want and create a symlink in /usr/local/bin/composer to it using ln -s
I use this method .and works fine for me on ubuntu 17.10
1-create file bash
1-1 Create a directory on the desktop.And then open the terminal
sudo touch sh1.sh
sudo 777 sh1.sh
2-edited file sh1.sh writing this statements
#!/bin/sh
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RESULT=$?
exit $RESULT
3-on terminal run
./sh1.sh
Please just copy the link and paste it to your terminal:
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Now you can run composer without any error....
You can easily download PHP Composer by following the official documentation, here's the link
These are the steps.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
To verify if it's all installed properly type: composer -V
This will work on both Linux and macOS.
I am trying to update Composer without any luck!
What I have tried:
$ composer self-update
[InvalidArgumentException]
Command "self-update" is not defined.
$ sudo -H composer self-update
[InvalidArgumentException]
Command "self-update" is not defined.
$ sudo apt-get install composer
Reading package lists... Done Building dependency tree Reading
state information... Done composer is already the newest version. The
following packages were automatically installed and are no longer
required: libntdb1 linux-headers-4.2.0-30
linux-headers-4.2.0-30-generic linux-image-4.2.0-30-generic
linux-image-extra-4.2.0-30-generic python-ntdb Use 'apt-get
autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove
and 10 not upgraded.
I am trying to self-update Composer because I am facing the following each time I try:
$ composer update
Loading composer repositories with package information Updating
dependencies (including require-dev)
[RuntimeException]
Could not load package rmrevin/yii2-fontawesome in
http://packagist.org: [UnexpectedValueException] Could not parse
version constraint v4.1 .: Invalid version string "v4.1."
[UnexpectedValueException]
Could not parse version constraint v4.1.: Invalid version string
"v4.1."
How can I fix this issue?
My PHP version is:
php --version
PHP 5.6.11-1ubuntu3.4 (cli) Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
My composer version is:
composer --version
Composer version #package_branch_alias_version# (#package_version#)
#release_date#
As Waqleh said, you have to uninstall PHP Composer and install it again. First, execute:
sudo apt-get remove composer
Then, execute these commands. The checksum here is for Composer 1.10.13, but you'll get the newest Composer (2.0.4 at the moment of editing this answer) when running the first line, so be sure to check in https://getcomposer.org/download/:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Now move file composer.phar to a directory that is in your path (from Installation - Linux / Unix / macOS):
sudo mv composer.phar /usr/local/bin/composer
And execute composer from any directory. That's all!
PS: If you're using PhpStorm (or maybe other IDEs), you'll have to close it and open it again.
Since I posted my answer, I have learnt a new easier way to install Composer programmatically: How do I install Composer programmatically?
Old Answer:
As per #JimL comment, I was able to self update Composer by:
Uninstalling Composer from the package manager (apt).
I installed it according to the official documentation
Now it works as expected.
Install the latest version:
Remove your current Composer version, for example Ubuntu/Debian:
sudo apt-get remove composer
Now, head to https://getcomposer.org/download/ and paste the script in your command line. This ensures that you get the latest version of Composer (as time of writing: v2.0.7).
Like this:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
After some time passed, you can update and there isn't any need to use the sudo prefix:
composer self-update
It worked for me (linux, Ubuntu 20.04):
sudo apt-get remove composer
sudo apt-get update
sudo apt-get install curl
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
If you have an old version of Composer you need to follow these commands:
composer -V
sudo apt remove composer
cd /tmp
wget http://getcomposer.org/download/1.10.5/composer.phar
php composer.phar -V
sudo mv composer.phar /usr/bin/composer
sudo chmod 750 /usr/bin/composer
composer -V
You can specify the installation directory and filename while setting up PHP Composer - php composer-setup.php like so:
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
Already there are many answers, Would like to share my experience with this.
I am using Ubuntu 20.04, and My previous Composer version was Composer 2.0.11 and my Project requirement was Composer 2.1.15.
I didn't had to remove anything, I simply used the following command and it worked fine for me :)
I've installed Homebrew and it saves me a lot.
Install brew and then brew install composer to install Composer.
composer 2 on debian :
cd /usr/src
sudo apt-get install curl php7.2-cli
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
chmod 777 composer
nano ~/.bashrc
add : PATH=$PATH/usr/local/bin/
source ~/.bashrc
verify :composer -v
Composer self-update may not work for others and using the documentation from the composer may be confusing for some. The following steps may help reinstall the composer to solve the problem.
#update the package manager
sudo apt update
#install the required packages
sudo apt install php-cli unzip
#retrieve the installer
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
#obtain the latest hash from the Composer page
HASH=`curl -sS https://composer.github.io/installer.sig`
echo $HASH #verify the obtained value
#verify that the installation script safety
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
#installing composer globally
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
#test your installation
composer
That's it. Credit: Erika Heidi
Install the latest Composer by the following steps:
Uninstalling Composer
sudo apt-get remove composer
Run following commands
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
Install Composer in the /usr/bin directory to run Composer from anywhere
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
Remove the installer
php -r "unlink('composer-setup.php');"
To check or self update
composer self-update
From within the directory holding my composer.phar file, I can't execute any composer commands.
I can see Composer is running when I execute
php composer.phar
But any direct composer statements fail.
Not sure if it matters but Composer was included within a cloned repository.
I just want to install a single Oauth library, then likely not touch Composer again for several months, so I don't need to run it globally. I'm just confused why I can't run Composer from within this directory.
This problem arises when you have composer installed locally.
To make it globally executable,run the below command in terminal
sudo mv composer.phar /usr/local/bin/composer
I am using CentOS and had same problem.
I changed /usr/local/bin/composer to /usr/bin/composer and it worked.
Run below command :
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
Verify Composer is installed or not
composer --version
Your composer.phar command lacks the flag for executable, or it is not inside the path.
The first problem can be fixed with chmod +x composer.phar, the second by calling it as ./composer.phar -v.
You have to prefix executables that are not in the path with an explicit reference to the current path in Unix, in order to avoid going into a directory that has an executable file with an innocent name that looks like a regular command, but is not. Just think of a cat in the current directory that does not list files, but deletes them.
The alternative, and better, fix for the second problem would be to put the composer.phar file into a location that is mentioned in the path
This is for mac or ubuntu user, try this on terminal
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
or mac brew can try
brew install composer
MacOS: composer is available on brew now (Tested on Php7+):
brew install composer
Install instructions on the Composer Docs page are quite to the point otherwise.
First I did alias setup on bash / zsh profile.
alias composer="php /usr/local/bin/composer.phar"
Then I moved composer.phar to /usr/local/bin/
cd /usr/local/bin
mv composer.phar composer
Then made composer executable by running
sudo chmod +x composer
Step 1 : Open Your terminal
Step 2 : Run bellow command
curl -sS https://getcomposer.org/installer | php
Step 3 : After installation run bellow command
sudo mv composer.phar /usr/local/bin/
Step 4 : Open bash_profile file create alias follow bellow steps
vim ~/.bash_profile
Step 5 : Add bellow line in bash_profile file
alias composer="php /usr/local/bin/composer.phar"
Step 6 : Close your terminal and reopen your terminal and run bellow command
composer
https://getcomposer.org/download/
it might help
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
this code for ubuntu and wsl2.
Open terminal and run the following command,
sudo ln -s /usr/bin/php71 /usr/bin/php
Works in RHEL 8, php 7.4
sudo mv composer.phar /usr/bin/composer
I downloaded the project.
My task to run this project through the xampp server.
They told me to install composter to the server.
I downloaded the project into htdocs/mysite/
I install composer
C:\bin>php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
He called through С:/xamppp/php/php composer.phar
When I run project Dependencies are not tightened(yii,...)
when I
С:/xamppp/php/php composer.phar create project C:/...htdocs/mysite/
Error:InvalidArgumentExeption
Cannot find project with stability stable
My answer may not be relevant to OP question for anyone looking to install composer
Linux - Ubuntu
sudo apt-get install composer
Or ..
Manual installation based on getcomposer.org
#!/usr/bin/env bash
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
run these command in a bash file or one by one.
Or ..
# this answer is copied and not tested
curl -s http://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/
If I've read this correctly, are you trying to install yii?
If so, this guide should help:
http://www.yiiframework.com/wiki/392/creating-yii-applications-with-composer/
It has a link to a sample Github project too.
Get latest stable version of composer
wget https://getcomposer.org/download/latest-stable/composer.phar
Move to bin
sudo mv composer.phar /usr/bin/composer