在 Windows 10 系统中安装 Laravel Installer

好处和坏处

好处

可以通过 Laravel Installer 安装 Laravel。它比用 Composer Create-Project 的好处是:

  1. 命令简单
$ laravel new blog

# VS

$ composer create-project --prefer-dist laravel/laravel blog
  1. 来源不同

使用 Laravel Installer 有两种安装项目的命令:

  • laravel new blog
  • laravel new blog --dev

它们对应的下载地址是:

就是说用 Laravel Installer 安装包是从官网提供的地址下载的、不是从 Composer 库里取的

坏处

Laravel Installer 不能指定下载的版本号。这个时候就要用 Composer Create-Project 了。

$ composer create-project --prefer-dist laravel/laravel blog "5.3.*" 

安装

执行命令 composer global require "laravel/installer",全局安装 Laravel Installer。在 Windows 10 系统中,Composer 安装的全局软件放在 C:/Users/zhangb/AppData/Roaming/Composer 文件夹下。

C:\Users\zhangb>composer global require "laravel/installer"
Changed current directory to C:/Users/zhangb/AppData/Roaming/Composer
Using version ^1.3 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
  - Installing symfony/process (v3.3.2): Loading from cache
  - Installing psr/log (1.0.2): Loading from cache
  - Installing symfony/debug (v3.3.2): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.4.0): Loading from cache
  - Installing symfony/console (v3.3.2): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
  - Installing guzzlehttp/guzzle (6.3.0): Downloading (100%)
  - Installing laravel/installer (v1.3.6): Downloading (100%)
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/filesystem ()
Writing lock file
Generating autoload files

将路径 C:\Users\zhangb\AppData\Roaming\Composer\vendor\bin 添加到全局变量中。下面打开命令行界面,就可以使用 laravel 命令了。

源码

刚才有说,「Laravel Installer 安装包是从官网提供的地址下载的、不是从 Composer 库里取」。依据何在——从源码里看到的。源码在 C:/Users/zhangb/AppData/Roaming/Composer/vendor/laravel/installer/src/NewCommand.php 中。有一个 download 方法。

/**
 * Download the temporary Zip to the given file.
 *
 * @param  string  $zipFile
 * @param  string  $version
 * @return $this
 */
protected function download($zipFile, $version = 'master')
{
    switch ($version) {
        case 'develop':
            $filename = 'latest-develop.zip';
            break;
        case 'master':
            $filename = 'latest.zip';
            break;
    }

    $response = (new Client)->get('http://cabinet.laravel.com/'.$filename);

    file_put_contents($zipFile, $response->getBody());

    return $this;
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 3

file_put_contents 下载文件真方便

7年前 评论

首先要让 composer 的源穿越长城,或者中国源吧,记得以前中国的源不稳定

7年前 评论

@BradStev 如果需要,你可以将 Composer 镜像下载地址更改为 Packagist / Composer 中国全量镜像 的地址:

$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!