To install Composer in my shared host, I ran from my home directory:
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Then I was told to run: $ php bin/composer.phar
And following that I was able to use Composer, confirmed by running:
$ composer.phar -V
Composer version 1.0-dev
Can someone please explain the command php bin/composer.phar
?
Is it simply telling php to unpack the .phar file? If so, where does it unpack it to? I see bin/bin/composer.phar*
after having run it. Then I have to run composer using the entire path to the phar file, unless I'm in the home directory.
A .phar
file is a ZIP-like file that contains all the files that make up a PHP application, and some initial code in the file header that sets up some stuff and then transfers execution to the first zipped file.
The command php bin/composer.phar
is calling PHP and gives the phar file as a parameter to make PHP execute that file. This will make PHP read that file, find the header with the bootstrapping code and execute that. PHP will initialize PHAR execution and go further into that compressed file.
The command composer.phar
will only work if that file has been marked with the x file flag to make it executable, and it is placed in a directory that is mentioned in the $PATH
environment variable. Part of the PHAR file is the first line of the file header that is called "shebang". This line is used in all script files for the command line to specify the interpreter that should be used to execute the file. In case of composer.phar
, this interpreter is PHP. So in essence, the same thing happens as with the first call: PHP is "running" the PHAR file, but with less typing on the command line.