最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

PHP Composer 依赖管理工具 xampp下安装

FEE ajiang-tuzi 7230浏览

今天装magento2的时候 提示了这个 我用的环境是XAMPP

Autoload error
Vendor autoload is not found. Please run 'composer install' under application root directory.
 

首先,什么叫composer呢?
请自行百度 或 查看

 http://baike.baidu.com/view/1657652.htm
 

那么如何在windows下安装composer呢?

1.检查是否开启开启ssl扩展 如果没有
修改php.ini,打开extension = php_openssl.dll
2.进入到php目录,执行php命令。
进入到项目文件htdocs,在dos中输入

php -r"eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

稍等片刻,会看到以下提示:

# php -r"eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: E:\XPP\composer.phar
Use it: php composer.phar 

3.在你项目文件中,新建一个xx.bat的文件,编辑内容如下

:
@ECHO OFF
SET SUBDIR=%~dp0
php %SUBDIR%\composer.phar %*

然后执行一下。这个文件,是要把当前的路径定义成composer、当然,你也可以不执行该文件。
4.到这里,composer就基本安装好了。那么接下来我们要安装扩展包了、
打开htdocs中的composer.json,输入我们要安装的扩展:
格式大致如下:

    {
    "require": {
        "chrisboulton/php-resque": "1.2",
        "lisachenko/go-aop-php": "*",
        "monolog/monolog":"1.2.*"
    }
}

5.如果执行了第四步的文件,直接在htdocs目录下执行composer install
如果未执行第四步的文件,则需要php composer.phar install
好了,安装到这里就完成了,扩展包,也下载好了。htdocs会多出一个vendor的文件夹,打开之后会发现,多出 chrisboulton,lisachenko,monolog三个文件夹。现在来看看自动加载吧……

我们再需要用到扩展包的地方,

require_once ROOT_PATH . 'vendor/autoload.php';

然后直接调用扩展包中的类名即可。
示例如下:

<?php
require_once ROOT_PATH . 'vendor/autoload.php';//ROOT_PATH是根目录
$redis = Resque::redis();//这里直接调用vendor/chrisboulton/php-resque/lib/resque.php的类名,无需引入该文件
var_dump($redis);

这个redis变量,就是php-resque的一个redis类

6 我在这里遇到个小问题 就是

 Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested PHP extension ext-intl * is missing from your system.
 

解决办法是

//about line 998
;extension=php_intl.dll 
change as
extension=php_intl.dll

然后 这个就算按装完成了
比如我先在在这个目录下安装magento2

 e:\XPP\htdocs\magento2\magento2-develop 

你可以把

 composer.phar

拷贝到网站的根目录
由于网络原因 最终还是安装失败

 # php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
  - Installing magento/magento-composer-installer (0.1.5)
    Downloading: 100%

  - Installing braintree/braintree_php (2.39.0)
    Downloading: 100%

  - Installing justinrainbow/json-schema (1.5.0)
    Downloading: 100%
    Invalid zip file, retrying...
  - Installing justinrainbow/json-schema (1.5.0)
    Downloading: 100%
    Downloading: 100%

  - Installing symfony/console (v2.6.11)
    Downloading: 100%
    Downloading: 100%

  - Installing symfony/process (v2.7.5)
    Downloading: 100%

  - Installing symfony/finder (v2.7.5)
    Downloading: 100%

  - Installing seld/jsonlint (1.3.1)
    Downloading: 100%
    Downloading: 100%
    Downloading: 100%

  - Installing composer/composer (1.0.0-alpha10)
    Downloading: 100%

  - Installing magento/composer (1.0.2)
    Downloading: 100%
    Downloading: 100%
    Downloading: 100%



  [Composer\Downloader\TransportException]
  The "https://packages.magento.com/_packages/composer-1.0.2.zip" file could not be downloaded: SSL: crypto enabling
  timeout
  Failed to enable crypto
  failed to open stream: operation failed



install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [packages1] ... [packagesN]

 

转载请注明:(●--●) Hello.My Weicot » PHP Composer 依赖管理工具 xampp下安装