在 Windows 10 系统中安装 Laravel Installer
好处和坏处
好处
可以通过 Laravel Installer 安装 Laravel。它比用 Composer Create-Project 的好处是:
- 命令简单
$ laravel new blog
# VS
$ composer create-project --prefer-dist laravel/laravel blog
- 来源不同
使用 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 协议》,转载必须注明作者和本文链接
file_put_contents 下载文件真方便
首先要让
composer
的源穿越长城,或者中国源吧,记得以前中国的源不稳定@BradStev 如果需要,你可以将 Composer 镜像下载地址更改为 Packagist / Composer 中国全量镜像 的地址: