Composer 是一个新的安装包管理工具,服务于 PHP 生态系统。
简单来说,能拉取别人的东西
[root@VM_0_26_centos 129]#wget https://getcomposer.org/download/1.0.0-alpha8/composer.phar #下载包,下面会显示下载进度条
wget https://getcomposer.org/download/1.0.0-alpha8/composer.phar
--2019-11-11 16:16:55-- https://getcomposer.org/download//1.0.0-alpha8/composer.phar
100%[==========================================================>] 960,311 26.7KB/s in 30s
2019-11-11 16:17:27 (30.9 KB/s) - ‘composer.phar’ saved [960311/960311]
[root@VM_0_26_centos 129]# mv composer.phar /usr/local/bin/composer#记得查看路径是否存在
[root@VM_0_26_centos 129]# chmod +x /usr/local/bin/composer#给权限
[root@VM_0_26_centos 129]# composer config -g repo.packagist composer https://packagist.phpcomposer.com #由于某些不能说的原因,魔法上网成本太高,只好切回国内源,另外这里可能出现安全警告,关闭某些东西的报错,不用管
[root@VM_0_26_centos 129]# composer #输入此命令,出现下面的东西说明安装成功
[root@VM_0_26_centos 129]# composer
PHP Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/vendor/composer/xdebug-handler/src/Process.php on line 149
Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/vendor/composer/xdebug-handler/src/Process.php on line 149
PHP Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/bin/composer on line 57
Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/bin/composer on line 57
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.8.5 2019-04-09 17:46:47
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
about Shows the short information about Composer.
archive Creates an archive of this composer package.
browse Opens the package's repository URL or homepage in your browser.
check-platform-reqs Check that platform requirements are satisfied.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Sets config options.
create-project Creates new project from a package into given directory.
depends Shows which packages cause the given package to be installed.
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader.
dumpautoload Dumps the autoloader.
exec Executes a vendored binary/script.
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
home Opens the package's repository URL or homepage in your browser.
i Installs the project dependencies from the composer.lock file if present, orfalls back on the composer.json.
info Shows information about packages.
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, orfalls back on the composer.json.
licenses Shows information about licenses of dependencies.
list Lists commands
outdated Shows a list of installed packages that have updates available, including their latest version.
prohibits Shows which packages prevent the given package from being installed.
remove Removes a package from the require or require-dev.
require Adds required packages to your composer.json and installs them.
run-script Runs the scripts defined in composer.json.
search Searches for packages.
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Shows information about packages.
status Shows a list of locally modified packages, for packages installed from source.
suggests Shows package suggestions.
u Upgrades your dependencies to the latest version according to composer.json,and updates the composer.lock file.
update Upgrades your dependencies to the latest version according to composer.json,and updates the composer.lock file.
upgrade Upgrades your dependencies to the latest version according to composer.json,and updates the composer.lock file.
validate Validates a composer.json and composer.lock.
why Shows which packages cause the given package to be installed.
why-not Shows which packages prevent the given package from being installed.
成功
如果遇上
PHP Fatal error: Uncaught PharException: phar "/usr/local/bin/composer" has a broken signature in /usr/Local/bin/composer:23
/usr/local/bin/composer(23): Phar: :mapPhar( i composer .phar')
#l {main}
thrown in /usr/local/bin/composer on line 23
的话,说明下载的包有问题,删了重下再给权限运行
另外如果安装composer时,出现了我上面的PHP Warning: putenv()
报错问题,这是因为安全考虑,禁用了某些危险函数,我是Linux+Nginx+MySQL+PHP的环境,如果要开启这项函数,那么就要到PHP安装目录找到php.ini(我是宝塔面板+PHP-7.2),该配置文件在 /www/server/php/72/etc/php.ini
下,
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_ope n,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru
将“disable_functions”中的putenv删除即可,并保存php.ini文件,重启服务,刷新。即可解决报错问题。