top:环境MacBook

1、通过composer 安装yii2 【yii2需要php的PDO和pdo_mysql扩展,需要确认已安装】

a. 首先需要配置composer:
我使用的是阿里云的镜像:https://developer.aliyun.com/composer
具体配置参照阿里云的文档,具体使用全局composer命令百度 or Google

b. 安装yii2:
yii2china.com上的文档通过composer安装yii2的命令是:composer create-project --prefer-dist yiisoft/yii2-app-basic basic

进入目录:cd /data0/www/
执行:composer create-project --prefer-dist yiisoft/yii2-app-basic basic
成功的话会在www目录建立一个basic目录,里面为代码

安装时可能遇到的问题有:
可能会遇到的问题1:

Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

这个问题其实我不确定是否解决了,因为我前一天遇到了,第二天百度下执行了 composer self-update之后,再composer就没了。

可能会遇到的问题2:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
- The requested package bower-asset/jquery could not be found in any version, there may be a typo in the package name.
Problem 2
- The requested package bower-asset/inputmask could not be found in any version, there may be a typo in the package name.
Problem 3
- The requested package bower-asset/punycode could not be found in any version, there may be a typo in the package name.
Problem 4
- The requested package bower-asset/yii2-pjax could not be found in any version, there may be a typo in the package name. Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
- It's a private package and you forgot to add a custom repository to find it Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

问题2解析:Yii依靠 Bower 和/或 NPM 软件包来安装 asset(CSS 和 JavaScript)库。 它使用Composer来获取这些库,允许 PHP 和 CSS/JavaScript 包版本同时解析。
问题2是我第一次create-project的时候,执行了这个错误的命令:composer create-project --prefer-dist yiisoft/yii2 ,遇到的。
解决方式为:composer安装composer bower-asset的几个包

查看包版本:composer show -all fxp/composer-asset-plugin
全局安装该包[这里我选了最新版]:composer global require "fxp/composer-asset-plugin:~1.4.6"
此时再安装composer.json中的包就可以成功了: composer install

可能会遇到的问题3:
安装的时候如果提示需要提供Token(hidden):  这里是需要你提供github的token
获取token方式为:
登录github->点击头像->Settings->左栏最下Developer settings->左栏Personal access tokens->Generate new token
然后创建一个tab,选项全勾选,生成token,之后拿这个token复制到Token(hidden): 那里即可继续安装。

之后即可安装成功,框架入口文件为web/index.php。

2、配置启动
a. 使用yii2提供的命令行启动测试服务器:
yii2提供了yii2 serve 可以本地启动服务作为测试使用
命令为:php72 yii serve --docroot='/data0/www/basic/web' --port=8888
浏览器访问http://localhost:8888/ 即可看到恭喜页面。

说一下--docroot这个参数项:该参数为指定web根目录
起初按照文档执行 php yii serve --port=8888时,报错为:Document root "/data0/www/yii2/console/web" does not exist.
百度加google之后,报错原因为:
直接执行 php yii serve,不指定docroot时,yii2无法知道你的项目根目录要的是哪个目录,是前台目录,还是后台目录?所以得手动指定下web目录。

b. nginx配置项目:
根据官网的nginx配置文件走即可:
另外官网的nginx服务建议项还有:
使用该配置时,你还应该在 php.ini 文件中设置 cgi.fix_pathinfo=0 , 能避免掉很多不必要的 stat() 系统调用。
还要注意当运行一个 HTTPS 服务器时,需要添加 fastcgi_param HTTPS on; 一行, 这样 Yii 才能正确地判断连接是否安全。

server {
charset utf-;
client_max_body_size 128M; listen ; ## listen for ipv4
#listen [::]: default_server ipv6only=on; ## listen for ipv6 server_name mysite.test;
root /path/to/basic/web;
index index.php; access_log /path/to/basic/log/access.log;
error_log /path/to/basic/log/error.log; location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
} # uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =;
#}
#error_page /.html; # deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
} location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =;
} location ~* /\. {
deny all;
}
}

yii2框架的安装&配置启动的更多相关文章

  1. asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程

    最近在学习张善友老师的NanoFabric 框架的时了解到Exceptionless : https://exceptionless.com/ !因此学习了一下这个开源框架!下面对Exceptionl ...

  2. C#实现多级子目录Zip压缩解压实例 NET4.6下的UTC时间转换 [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了 asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 asp.net core异步进行新增操作并且需要判断某些字段是否重复的三种解决方案 .NET Core开发日志

    C#实现多级子目录Zip压缩解压实例 参考 https://blog.csdn.net/lki_suidongdong/article/details/20942977 重点: 实现多级子目录的压缩, ...

  3. 【转】asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程

    最近在学习张善友老师的NanoFabric 框架的时了解到Exceptionless : https://exceptionless.com/ !因此学习了一下这个开源框架!下面对Exceptionl ...

  4. linux centos-7.2-64bit 安装配置启动nginx

    1.安装依赖包yum -y install openssl openssl-develyum install pcre*yum install openssl*yum install zlib yum ...

  5. linux环境下redis数据库的安装|配置|启动

    安装 下载:打开redis官方网站,推荐下载稳定版本(stable) 解压 tar zxvf redis-3.2.5.tar.gz 复制:推荐放到usr/local目录下 sudo mv -r red ...

  6. cloudera impala编译 安装 配置 启动

    无论是采用GDB调试impala或者尝试修改impala源码,前提都是需要本地环境编译impala,这篇文章详细的分享一下impala编译方法以及编译过程遇到的棘手的问题: 前言: impala官方的 ...

  7. mac下fiddler安装配置启动及iphone配置连接

    Getting started 下载安装Mono 如果没有下载则下载:https://www.mono-project.com/download/stable/#download-mac 从Mozil ...

  8. Linux中安装配置启动关闭nginx等一系列动作

    Nginx简介 1.Nginx (engine x) 是一个高性能的Web服务器和反向代理服务器,也可以作为邮件代理服务器: 2.Nginx 是由俄罗斯人 Igor Sysoev 采用C语言开发编写的 ...

  9. Linux下安装配置启动RabbitMQ

    Linux版本:Centos 7RabbitMQ依赖erlang所以需要先安装erlang以及他需要的环境 安装erlang http://www.erlang.org/downloads 拿最新的版 ...

随机推荐

  1. python+selenium元素定位之CSS学习01

    参考文档:https://www.w3school.com.cn/cssref/css_selectors.asp 选择器 例子 例子描述 CSS .class .intro 选择 class=&qu ...

  2. this,static,执行程序的顺序等等留意点

    self.static 和 $this 的区别为了更好地理解 self.static 和 $this 的区别,先来看一个示例. <?phpclass A { protected $name = ...

  3. centos7.4安装mysql

    yum -y install mysql mysql-server mysql-devel mysql-server报错:No package mysql-server available,另外两个没 ...

  4. 基于 VirtualApp 结合 whale hook框架实现hook第三方应用

    要点 1. whale hook framework 使用示例: 2. 参考项目:VirtualHook: 3. 按照 VirtualHook 修改 VirtualApp: 4. 编写 hook pl ...

  5. Scrapy抓取jobbole数据

    1.python版本3.6.1 2.python编辑器:JetBrains PyCharm 2.安装virtualenvwrapper-win pip3 install virtualenvwrapp ...

  6. C#/.NET VS2017+ EF+SQLite.CodeFirst——真正实现CodeFirst

    本文所介绍的是真正的EF+CodeFirst,不需要提前建表,由代码自动生成! 进行前需要准备的: 1.下载Sqlite Experthttp://www.sqliteexpert.com/downl ...

  7. 狼人杀校园升级版:学霸大战学渣 Who is the king of examination!

    之前在微博上看到一个很老的段子 写道 天黑请闭眼.学霸请睁眼,学霸请答题,好的学霸请闭眼:学渣请睁眼,学渣请坐弊,好的学渣请闭眼:监考老师请睁眼,监考老师请确定坐弊考生,监考老师请统一意见,好的监考老 ...

  8. alert(1) to win 2

    function escape(s) { s = s.replace(/"/g, '\\"'); return '<script>console.log("' ...

  9. P4206[NOI2005]聪聪与可可

    链接P4206 [NOI2005]聪聪与可可 类似于开车旅行,如果老鼠确定了那么猫的路线是确定的. 预处理\(g_{i,j}\)表示老鼠在\(i\)号点,猫的下一步方向,\(Bfs\)就行了 设\(f ...

  10. JavaScript 工作原理之十-使用 MutationObserver 监测 DOM 变化

    原文请查阅这里,略有删减,本文采用知识共享署名 4.0 国际许可协议共享,BY Troland. 本系列持续更新中,Github 地址请查阅这里. 这是 JavaScript 工作原理的第十章. 网络 ...