标签(空格分隔): Yii2
1 安装 Composer
[ahcj@localhost ~]$ curl -sS https://getcomposer.org/installer | php
[ahcj@localhost ~]$ mv composer.phar /usr/bin/composer
2 安装资源管理插件 Composer asset plugin
Composer asset plugin 是通过 Composer 管理 bower 和 npm 包所必须的,此命令全局生效
[ahcj@localhost ~]$ composer global require "fxp/composer-asset-plugin:^1.2.0"
3 安装应用和模板
注意: 在安装过程中 Composer 可能会询问你 GitHub 账户的认证信息,因为可能在使用中超过了 GitHub API (对匿名用户的)使用限制。
# 切换到 www 目录
[ahcj@localhost ~]$ cd www
# 安装基本应用模板
[ahcj@localhost www]$ composer create-project --prefer-dist yiisoft/yii2-app-basic basic
4 高级模板(可选)
#安装 Yii 的最新开发版
[ahcj@localhost www]$ composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic-dev
# 开发复杂应用时安装高级模板
[ahcj@localhost www]$ composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-advanced
5 使用内置服务器启动
# 切换到程序所在目录
[ahcj@localhost ~]$ cd basic
# 启动内置 server
[ahcj@localhost basic]$ ./yii serve
Server started on http://localhost:8080/
Document root is "/home/ahcj/www/basic/web"
Quit the server with CTRL-C or COMMAND-C.
接下来就可以使用 http://localhost:8080/ 访问应用了。 如果没有看到页面,运行自检程序检查
[ahcj@localhost basic]$ php requirements.php
6 内置服务器功能
语法
./yii serve [address] [options]
address 可选,可以指定访问的网址(ip),不写的话使用默认值localhost:8080。
PS
./yii serve mysite.com
#or
./yii serve 192.168.1.25:8081
帮助
[ahcj@localhost basic]$ ./yii serve -h
DESCRIPTION
Runs PHP built-in web server
USAGE
yii serve [address] [...options...]
- address: string (defaults to 'localhost')
address to serve on. Either "host" or "host:port".
OPTIONS
--appconfig: string
custom application configuration file path.
If not set, default application configuration is used.
--color: boolean, 0 or 1
whether to enable ANSI color in the output.
If not set, ANSI color will only be enabled for terminals that support it.
--docroot, -t: string (defaults to '@app/web')
path or [path alias](guide:concept-aliases) to directory to serve
--help, -h: boolean, 0 or 1
whether to display help information about current command.
--interactive: boolean, 0 or 1 (defaults to 1)
whether to run the command interactively.
--port, -p: int (defaults to 8080)
port to serve on.
--router, -r: string
path to router script.
See https://secure.php.net/manual/en/features.commandline.webserver.php