php composer

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

PHP的composer能够类比 java的maven, node的npm, 或者linux centos的yumhtml

开发时注意java

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

若是使用 composer update 会使插件都为最新版本致使跟生产不同, 对于一些依赖特定版本的程序会有问题linux

安装web

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

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

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

3. composer.phar是PHP的一个包, 相似java的jar包, 它是个可执行文件, 文件第一行指明了须要PHP命令执行他本身, 所以能够直接运行该文件app

先将它复制到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>]...

 使用

2019-5-8 10:08:59 星期三

verson 1.8 (下载官网的exe安装文件, 指定PHP.exe目录, 并将composer添加到环境变量)

新建一个目录, 打开命令行进入目录, 输入 composer init , 会引导你配置一些东西, 配置完毕后就会在当前目录建立composer.json等文件

 

另一篇

相关文章
相关标签/搜索