Composer 是 PHP 的一个依赖管理工具。它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们。Composer 不是一个包管理器。是的,它涉及 "packages" 和 "libraries",但它在每个项目的基础上进行管理,下面来看composer安装与使用。

I. 安装

cd path-to-your-project
curl -sS https://getcomposer.org/installer | php

# Composer successfully installed to: /tmp/composer.phar
# Use it: php composer.phar

如果在此提示,那是因为php没有在系统的环境变量$PATH中。

command not found: php

解决方法:

为当前php的路径创建一个软连接

ln -s /usr/local/php/bin/php /usr/local/bin/php

仔细察看composer.phar的权限,应该是755,即-rwxr-xr-x,说明这个文件其他人都有执行权限,所以如果我们将其移动至/usr/local/bin/中,即可全局可用!

mv composer.phar /usr/local/bin/composer

II. 使用

我们先使用-h查看帮助

composer -h
Usage:
 help [--xml] [--format="..."] [--raw] [command_name]

Arguments:
 command               The command to execute
 command_name          The command name (default: "help")

Options:
 --xml                 To output help as XML
 --format              To output help in other formats (default: "txt")
 --raw                 To output raw command help
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --profile             Display timing and memory usage information
 --working-dir (-d)    If specified, use the given directory as working directory.

Help:
 The help command displays help for a given command:

php /usr/local/bin/composer help list

You can also output the help in other formats by using the --format option:

php /usr/local/bin/composer help --format=xml list

To display the list of available commands, please use the list command.
看来想要找到所有的命令需要运行php /usr/local/bin/composer help list

我们试试吧

php /usr/local/bin/composer list
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.0-dev (4f80e7ff68466cab970c22b425725b8058c32970) 2015-06-09 00:03:48

Usage:
 command [options] [arguments]

Options:
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --profile             Display timing and memory usage information
 --working-dir (-d)    If specified, use the given directory as working directory.

Available commands:
 about            Short information about Composer
 archive          Create an archive of this composer package
 browse           Opens the package's repository URL or homepage in your browser.
 clear-cache      Clears composer's internal package cache.
 clearcache       Clears composer's internal package cache.
 config           Set config options
 create-project   Create new project from a package into given directory.
 depends          Shows which packages depend on the given package
 diagnose         Diagnoses the system to identify common errors.
 dump-autoload    Dumps the autoloader
 dumpautoload     Dumps the autoloader
 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.
 info             Show 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, or falls back on the composer.json.
 licenses         Show information about licenses of dependencies
 list             Lists commands
 remove           Removes a package from the require or require-dev
 require          Adds required packages to your composer.json and installs them
 run-script       Run the scripts defined in composer.json.
 search           Search for packages
 self-update      Updates composer.phar to the latest version.
 selfupdate       Updates composer.phar to the latest version.
 show             Show information about packages
 status           Show a list of locally modified packages
 update           Updates your dependencies to the latest version
according to composer.json, and updates the composer.lock file.
 validate         Validates a composer.json

比如:安装bower-asset

composer global require "fxp/composer-asset-plugin:*"

III. 国内镜像

为了更好的使用composer,我们使用phpcomposer国内镜像加速,具体使用方法很简单,你可以参考官网的使用说明!

IV. 在项目中使用composer
比如我们的项目需要使用laravel与monolog,怎么办呢?

首先,在packagist.org中搜索需要的包名,这样我们得到了包名monolog/monolog,laravel同理。

其次,我们需要确定版本,我们看到官网的提示:

{
    "require": {
        "vendor/package": "1.3.2",   # 明确指定版本
        "vendor/package2": "1.*",    # 使用通配符,方便以后执行更新
        "vendor/package2": "~1.3",   # 是指 1.3<= X <2.0的版本
        "vendor/package3": ">=2.0.3", # 指定一个范围
        "vendor/package3": ">=2.0.3-dev" # 默认composer会取稳定版,但是如果指明-dev,则会下载dev版
    }
}

更多使用方法请移步Package Versions

我们在项目根目录下建立文件 composer.json

{
    "require": {
        "monolog/monolog": "1.0.*"
    }
}

你还可以自动生成此composer.json,通过命令 composer init --require "monolog/monolog:1.0.*" -n

转载:http://www.111cn.net/sys/CentOS/88604.htm

centos系统下安装使用composer教程的更多相关文章

  1. Linux(CentOS)系统下安装好apache(httpd)服务后,其他电脑无法访问的原因

    原文:Linux(CentOS)系统下安装好apache(httpd)服务后,其他电脑无法访问的原因 今天试了下在虚拟机上利用CentOS系统的yum命令安装好了httpd(apache2.4.6), ...

  2. CentOS系统下安装python3+Django

    转载:CentOS系统下安装python3+Django 1.首先用yum安装下vim,因为CentOS 7可能根本没自带完整vim,经常出现输入乱码:yum -y install vim 2.安装开 ...

  3. centos系统下安装Nginx

    参考链接 CentOS 7 用 yum 安装 Nginx Nginx负载均衡配置 下载并安装 #使用以下命令 sudo yum install -y nginx #sudo表示使用管理员权限运行命令 ...

  4. CentOS系统下安装 LNAM环境

    系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP,OpenVZ的另外 ...

  5. centos 系统下安装FastDFS+nginx+fastdfs-nginx-module安装配置

    前言: 以前的项目上传的文件都是保存到本地或者是局域网内的共享文件夹下,由于数据量,服务器的负载均衡(分机的某些图片无法访问的问题处理)等因素的情况下,就想到用fastdfs来文件管理,花了几天时间硬 ...

  6. CentOS系统下安装以及卸载mysql

    CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 [root@localhost `]$ wget htt ...

  7. Windows系统下安装MySQL详细教程(命令安装法)

    1.安装包下载. 下载地址:https://dev.mysql.com/downloads/mysql/ 点击下载之后,可以选择注册Oracle账号,也可以跳过直接下载. 下载完成后,选择一个磁盘内放 ...

  8. centos系统下安装MySQL5.7.18

    1.首先安装依赖包 yum install -y gcc gcc-c++ ncurses-devel perl openssl-devel 最最重要的是,不要忘了安装openssl-devel 2.安 ...

  9. CentOS系统下安装配置ftp服务

    安装配置步骤: rpm -ivh /opt/bak/vsftpd-2.2.2-11.el6.x86_64.rpm --本地安装vsftpd ll /etc/vsftpd/  --查看vsftpd的配置 ...

随机推荐

  1. 1.4.2 solr字段类型--(1.4.2.7)字段属性使用案例

    1.4.2 solr字段类型 (1.4.2.1) 字段类型定义和字段类型属性. (1.4.2.2) solr附带的字段类型 (1.4.2.3) 使用货币和汇率 (1.4.2.4) 使用Dates(日期 ...

  2. 修改avd路径

    1.比如你要把AVD放在D盘AndroidAVD下面,则预先在D盘下建立一个文件夹 AndroidAVD.必须的.不然设置了环境变量也没有用,因为模拟器不会自动创建该文件夹. 2.在桌面右击“我的电脑 ...

  3. [JavaEE] WEB-INF有关的目录路径总结

    1.资源文件只能放在WebContent下面,如 CSS,JS,image等.放在WEB-INF下引用不了. 2.页面放在WEB-INF目录下面,这样可以限制访问,提高安全性.如JSP,html 3. ...

  4. [Arduino] 逗号分隔文本到数组的两种方法

    以下是今日练习通过逗号来分割字符数组/字符串的2个例子和方法" 1.通过indexOf函数 /* *Splitsplit sketch *split a comma-separated st ...

  5. 【阿里云产品公测】一句话告诉你什么样的人该使用ACE,如何使用ACE

    作者:阿里云用户小鸡咕咕 首先回应标题,这一句话就是:看完这篇帖子你就知道了.     前言 写在文章之前,我想先阐述一下写这篇文章的意义.可能大伙就要说了,写这篇文章不就是为了200的代金券吗?错, ...

  6. 21世纪C语言(影印版)

    <21世纪C语言(影印版)> 基本信息 原书名:21st Century C 作者: Ben Klemens 出版社:东南大学出版社 ISBN:9787564142056 上架时间:201 ...

  7. 连续区间覆盖染色问题 ------ SHUOJ 1716

    题目链接:http://202.121.199.212/JudgeOnline/problem.php?id=1716 [题意] 1到N的区间,一种操作让编号从a到b的数变为z,但不会低于2,问多次操 ...

  8. 在网页中制作icon图标

    用字体在网页中画icon图标 第一步:获取字体资源IconMoon网站https://icomoon.io iconMoon中有很多免费小图标可用,还能设置下载图标的使用属性(通过网站中设立的按钮pr ...

  9. Linq 数据库操作(增删改查)

    Linq数据库增删改查 Linq是一种查询语言,集成包含在formwork中,包含在C#语言中,它的作用是降低查询的门槛,提高开发效率,是我们必须掌握的技术之一,下面是我自己对linq数据库操作的方法 ...

  10. Pure-ftpd无法连接到服务器 425错误

    今天是五一假期的前一天,闲来没事,打开自己的博客,发现很久没有备份数据了,由于工作方面的原因,自己慢慢的退出了技术界,但本人还是依然向往技术界啊!各位技术宅们,加油! 问题发现 当我打开FTP客户端软 ...