如何在php项目中安装vendor依赖

在测试开源代码时,提示vendor/autoload.php找不到。
vendor是composer安装后的系统依赖,默认项目里面是没有的。

安装composer

wget -nc http://getcomposer.org/composer.phar
php composer.phar
mv composer.phar /usr/local/bin/composer 
composer -V

有composer环境安装vendor

一般使用composer的工程,目录下都有现成的配置文件composer.json,主要描述了工程需要的各种依赖和需求:

{
  "name": "cheprasov/php-redis-client",
  "version": "1.8.0",
  "description": "Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 4.0",
  "homepage": "http://github.com/cheprasov/php-redis-client",
  "minimum-stability": "stable",
  "license": "MIT",
  "authors": [
    {
      "name": "Alexander Cheprasov",
      "email": "acheprasov84@gmail.com"
    }
  ],
  "autoload": {
    "psr-0": {
      "RedisClient\\": "src"
    }
  },
  "require": {
    "php": ">=5.5"
  },
  "require-dev": {
    "phpunit/phpunit": "4.8.*",
    "cheprasov/php-extra-mocks": "^1.0.0"
  }
}

我们在项目的的composer.json同级目录下执行:

composer install

正常成功后:

Writing lock file
Generating autoload files

至此,verdor目录生成

无composer环境直接安装vendor

如果没有安装过composer,也可以直接通过php安装,在项目根目录下执行(有composer.json的目录):

php composer.phar require xxx

xxx是composer.json 中的name字段。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注