centos系统下安装使用composer教程

摘要:
Composer是PHP的依赖管理工具。它允许您声明项目所依赖的代码库,并将在项目中为您安装它们。Composer不是包管理器。是的,它涉及“包”和“库”,但它是基于每个项目进行管理的。让我们来看看composer的安装和使用。1.将cdpath安装到projectcurl sShttps://getcomposer.org/installer| Php#composer已成功安装到:/tmp/comporter。phar#Useit:phpcomposer。phar如果这里出现提示,这是因为php不在系统的环境变量$PATH中。
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同理。

搜索 monolog

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

{
    "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教程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇DevExpress 控件使用之BarManager获取DOS命令的返回值.下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

PostgreSQL 10编译安装(CentOS 7)

  版本说明:           Postgres 10.9    CentOS 7.6  1 安装必要软件 # yum groupinstall -y "Development tools" # yum install -y bison flex readline-devel zlib-devel gcc   2 获取Postgres资源并编译...

centos安装、卸载openssh

1.卸载openssh 执行rpm-qaopenssh* 查看是否已经安装过了。 [root@node51 ~]# rpm-qaopenssh* openssh-server-6.6.1p1-11.el7.x86_64 openssh-6.6.1p1-11.el7.x86_64 openssh-clients-6.6.1p1-11.el7.x86_64...

ubuntu下升级R版本

在测试《机器学习 实用案例解析》一书的邮件分类代码时,windows系统下rstudio中无法读取特殊字符,在ubuntu下可以。在ubuntu虚拟机下安装tm包(install.packages("tm"))时,提示R版本过低(需要3.1,但是只有3.0,最新版本是3.2),百度了下,网上的资料说,需要配置下/etc/apt/sources.list文件...

centos中安装tomcat

1.先保证centos中安装了jre的环境。 2.上传tomcat的压缩包到root根目录。 3.切换到根目录 输入命令cd ~ , 然后 ll , 查看上传情况: 4.选中复制压缩文件,输入解压命令,tar -zxvf apache-tomcat-7.0.57.tar.gz -C /usr/local,  把它解压到/usr/local目录下,该目录是...

centos vsftpd

CentOS 配置vsftpd 登陆报错500 OOPS: could not open chroot() list file:/etc/vsftpd/chroot_list解决 第一是: 限制用户只能访问配置的目录,不能访问其他路径 修改vi /etc/vsftpd/vsftpd.conf chroot_list_enable=YES //限制访问自身目...

centos使用yum下载至本地及使用本地缓存安装包

centos使用yum下载至本地及使用本地缓存安装包  yum install --downloadonly --downloaddir=/home/java java https://www.iteye.com/blog/mywaylife-2435856 https://blog.csdn.net/weixin_30861797/article/det...