使用国内镜像快速安装composer以及yii2(附安装脚本)

通过中国镜像安装composer

参考文章 如何安装 Composer

下载安装文件

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

安装

php composer-setup.php

删除安装文件

php -r "unlink('composer-setup.php');"

设置全局路径(windows请按参考文档设置)

sudo mv composer.phar /usr/local/bin/composer

配置使用国内镜像

composer config -g repo.packagist composer https://packagist.phpcomposer.com

安装Yii2

参考文章 Install via Composer

首先安装 Composer Asset Plugin

composer global require "fxp/composer-asset-plugin:^1.2.0"

安装基础模板

php composer.phar create-project yiisoft/yii2-app-basic yiitest

安装高级模板

php composer.phar create-project yiisoft/yii2-app-advanced yiitest

安装过程中如果提示“please create a GitHub OAuth token to go over the API rate limit”,登录github,在https://github.com/settings/tokens生成一个token,权限只需要勾选repo即可

进入项目目录

cd yiitest

测试安装环境

php requirements.php

初始化项目

 ./init

运行项目

./yii serve/index -h
./yii serve/index -t="@frontend/web"
./yii serve/index -t="@backend/web"