centos系统下安装使用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

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

时间: 2024-08-30 16:02:34

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

CentOS系统下安装Tomcat7环境教程

安装JDK 在Oracle Java SEDownload页面下载JDK. (1) 勾选「Accept License Agreement」 (2) 点击「jdk-8u91-linux-x64.rpm」 系统为64位时选择x64,32位时选择i586. (3) 把下载的文件用FTP上传到服务器. (4) 安装JDK # rpm -ivh ./jdk-8u91-linux-x64.rpm 安装Tomcat 在Apache Tomcat – Welcome!的Downloads页面下载Tomcat.

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

原文:Linux(CentOS)系统下安装好apache(httpd)服务后,其他电脑无法访问的原因 今天试了下在虚拟机上利用CentOS系统的yum命令安装好了httpd(apache2.4.6),然后在windows系统下访问此虚拟机的ip地址,却访问不了. 因为前段时间有知道过iptable的限制,所以在想是不是因为iptable限制了80端口呢! 所以在网上找了下iptable的命令,并且把tcp的80端口设置成允许任何IP都可以访问: iptables -I INPUT -p TCP

Ubuntu系统下安装VIM编辑器教程

Ubuntu下安装vim还是比较简单的,使用如下命令即可: sudo apt-get install vim 系统就会自动安装好vim,现在系统中就会两种编辑器了,一种是系统自带的nano编辑器,另一种是我们刚才安装vim,如果我们要默认vim为默认编辑器呢 在安装完vim之后,还可以选择通过修改Ubuntu中默认编辑器的命令,来指定vim为默认编辑器:  代码如下 复制代码 sudo update-alternatives --config editor 系统可能会提示如下:  代码如下 复制

在CentOS系统下安装Puppet和Puppet Foreman的教程

  一.系统环境: Centos6.4 x86_64 192.168.6.171 puppet.domain.com 192.168.6.173 agent1.domian.com 二.关闭selinux 和 iptables(我这里是测试环境,也可以增加puppet端口8140) 代码如下: setenforce 0 /etc/init.d/iptables stop && chkconfig iptables off 三.更改主机名.使用host解析 代码如下: [root@test

在CentOS系统下安装SVN服务器的教程

  Subversion支持linux和windows,更多是安装在linux下. svn服务器有2种运行方式:独立服务器和借助apache.2种方式各有利弊. svn存储版本数据也有2种方式:BDB和FSFS.因为BDB方式在服务器中断时,有可能锁住数据,所以还是FSFS方式更安全一点. 一.下载相关软件 代码如下: wget http://subversion.tigris.org/downloads/subversion-1.6.1.tar.gz 代码如下: wget http://sub

在CentOS系统中安装Websvn的教程

  大家好,今天我们会在CentOS 7.0 上为 subversion(SVN)安装Web 界面 WebSVN.(subverion 是 apache 的顶级项目,也称为 Apache SVN 或 SVN) WebSVN 将 Svbverion 的操作你的仓库的各种功能通过 Web 界面提供出来.通过它,我们可以看到任何给定版本的任何文件或者目录的日志,并且可看到所有文件改动.添加.删除的列表.我们同样可以查看两个版本间的差异来知道特定版本改动了什么. 特性 WebSVN提供了下面这些特性:

Centos系统下安装PHP扩展各种方法总结

安装PHP扩展 # wget http://pecl.php.net/get/gearman-1.1.1.tgz # tar zxvf gearman-1.1.1.tgz # cd gearman-1.1.1 # /usr/local/server/php/bin/phpize # ./configure --with-php-config=/usr/local/server/php/bin/php-config --with-gearman=/usr/local/server/gearmand

Linux系统下安装GD库教程

也是因为折腾一些东西的时候呢,需要GD库的支持.我们先介绍一下GD库吧 GD库,是php处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片. 检查GD库 检查GD库是否安装命令 php5 -m | grep -i gd 或者 php -i | grep -i --color gd   下面安装的呢主要是从服务器上安装,这样比较方便也减少了错误,也可以自己编译着安装.这里就不过多说明了,需要编译安装的话可能比较麻烦. 安装GD库 debian apt-g

Centos系统下安装SVN服务器方法介绍(非常详细)

分支开发的意义: 场景一,有客户想对产品做定制,但是我们并不想修改原有的svn中trunk的代码. 场景二,我们正在开发产品下阶段的任务,但上阶段的工作发现问题 以场景二为例,项目某一阶段开发完成后,这个时候要做一个tag,tag_mfcai_V1.01.00, 然后基于这个tag发布一个新的版本,假设项目是web项目,那么基于这个tag发布一个web包. 然后trunk进入下阶段继续开发,但是很不幸发布的版本被检测出来了bug,有人会提议,把bug放到下阶段的任务中去.假设下阶段的任务才刚开始