php composer

2017年4月23日 11:14:09 星期日

PHP的composer可以类比 java的maven, node的npm, 或者linux centos的yum

开发时注意

尽量使用 compser install 命令, 这个命令根据lock文件保证了生产跟开发环境使用的插件是同一个版本,

如果使用 composer undate 会使插件都为最新版本导致跟生产不一样, 对于一些依赖特定版本的程序会有问题

安装

1. 要先到国外的composer官网下载install文件 

2. 用PHP执行该install 文件, 检查一下当前PHP配置, 没啥问题的话这个install 会自动下载composer.phar到当前目录下边

注: 这里提示了, 需要安装开启PHP的zlib扩展, 随后在运行的时候还会提示xdebug会影响效率, 而且不能一root权限去运行composer命令

3. composer.phar是PHP的一个包, 类似java的jar包, 它是个可执行文件, 文件第一行指明了需要PHP命令执行他自己, 因此可以直接运行该文件

先将它复制到PHP的bin下边, 保证可以被全局访问到, 然后命令行输入 composer

 1 cp composer.phar /usr/local/web/php/bin/composer
 2 
 3 composer -v
 4 You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
 5 Do not run Composer as root/super user! See https://getcomposer.org/root for details
 6    ______
 7   / ____/___  ____ ___  ____  ____  ________  _____
 8  / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
 9 / /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
10 \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
11                     /_/
12 Composer version 1.4.1 2017-03-10 09:29:45
13 
14 Usage:
15   command [options] [arguments]
16 
17 Options:
18   -h, --help                     Display this help message
19   -q, --quiet                    Do not output any message
20   -V, --version                  Display this application version
21       --ansi                     Force ANSI output
22       --no-ansi                  Disable ANSI output
23   -n, --no-interaction           Do not ask any interactive question
24       --profile                  Display timing and memory usage information
25       --no-plugins               Whether to disable plugins.
26   -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
27   -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

 

4. 因为composer不能以root权限运行, 所以一些写操作不能执行, 因此, 在安装项目的时候, 一定要先把项目目录的权限设置为可写可执行的

sudo chmod -R 777 composer/

否则会报写失败(file_put_contents...失败):

composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing monolog/monolog (1.0.2): Downloading (100%)         

                                                                                
  [ErrorException]                                                              
  file_put_contents(./composer.lock): failed to open stream: Permission denied  
                                                                                

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值