Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

php - Composer install Error in argument 1, char 2: option not found r

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?

question from:https://stackoverflow.com/questions/65649825/using-php-in-putty

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:UsersHPierce>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:UsersHPierce>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:phpphp.exe -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...