10

I'm trying to install composer on my Website. The Composer documentations suggests running this command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"`

but when I do, I get an error:

Error in argument 1, char 2: option not found r

I use PHP Version 7.0

What's going on here?

5
  • welcome to SO. if you are copy/pasting text make sure it is not pasting Smartquotes Jan 5, 2017 at 18:31
  • I checked this, that was not the problem.
    – ca2510fl
    Jan 5, 2017 at 18:38
  • php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" worked for me on php 5.4.45 perhaps its a 7.0 thing Jan 5, 2017 at 18:41
  • I've edited your question fairly aggressively. If you feel I've gone too far, please feel free to edit further or even roll it back.
    – HPierce
    Jan 6, 2017 at 1:37
  • 2
    I used php5-cli instead of php, which worked.
    – Tjalsma
    Oct 22, 2017 at 20:44

2 Answers 2

9

I suspect php in your case is referring to PHP's CGI-SAPI binary instead of the CLI that it should be. As documented in the PHP manual, the CGI-SAPI does not include the -r option:

Note: -r is available in the CLI SAPI, but not in the CGI SAPI.

You can confirm that this is the case by checking "php's" version with the -v flag.

Proper setup should show that php is a CLI interupter:

C:\Users\HPierce>php -v
PHP 7.0.8 (cli) (built: Jun 21 2016 15:27:20) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Improper setup might show that it is the CGI SAPI:

C:\Users\HPierce>php-cgi -v
PHP 7.0.8 (cgi-fcgi) (built: Jun 21 2016 15:27:08)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

You can resolve this by referencing the CLI binary with an absolute path instead of the php shortcut that utilizies your OS's $PATH environment variable:

C:\php\php.exe -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
2

I had the same problem, and used curl and it worked:

curl -sS https://getcomposer.org/installer | /usr/bin/php7.1-cli

Additionally, to do specific commands to install a package, I needed to specify the php version Composer was installed on, and write "composer.phar" instead of only composer:

php7.1-cli composer.phar require exampleAppDirectory/exampleAppName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.