yii配置
一、在config/web.php中添加如下代码(开启debug工具和gii工具)
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['192.168.*']
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class'=>'yii\gii\Module',
'allowedIPs'=>['192.168.*'],
];
}
注:debug工具要在入口文件中开启
defined('YII_DEBUG') or define('YII_DEBUG', true);
注:gii工具需要下载
php composer.phar require --prefer-dist yiisoft/yii2-gii "*" 或者
composer.json 中加入 "yiisoft/yii2-gii": "*"
二、配置url
(1)在config/web.php 的 $config 中加入如下代码
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
(2)apache 部署 yii 虚拟主机
(2.1)直接在Apache配置文件或者在一个虚拟主机的配置文件中进行一次性配置
<VirtualHost *:80>
ServerAdmin basic.com
DocumentRoot "/web_data/basic/web"
ServerName basic.com
ErrorLog "logs/basic.com-error_log"
CustomLog "logs/basic.com-access_log" common
<Directory /web_data/basic/web>
AllowOverride All
Options FollowSymLinks
RewriteEngine on
# 如果请求的是真实存在的文件或目录,直接访问
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 如果请求的不是真实文件或目录,分发请求至 index.php
RewriteRule . index.php
</Directory>
</VirtualHost>
(2.2)虚拟主机配置 + 文件配置
(1)在虚拟机配置文件中添加如下配置
<VirtualHost *:80>
ServerAdmin 2022281825@qq.com
ServerName admin.yii.local
DocumentRoot /var/www/html/myYii/backend/web
ErrorLog ${APACHE_LOG_DIR}/admin.yii.local-error.log
CustomLog ${APACHE_LOG_DIR}/admin.yii.local-access.local combined
<Directory /var/www/html/myYii/backend/web>
AllowOverride All
</Directory>
</VirtualHost>
(2)在web目录下新建".htaccess",并在其中写入如下代码
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
三、配置数据库
编辑 config/db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
];
yii配置的更多相关文章
- YII配置mysql读写分离
Mysql 读写分离 YIi 配置 <?php return [ 'class' => 'yii\db\Connection', 'masterConfig' => [ // 'ds ...
- YII配置rabbitMQ时前期工作各种坑
背景如下: 项目需要做一个订阅/发布的功能,然后一大堆讨论不做说明,确认使用rabbitMQ来做: okay,既然 要这个来做,我们下载这个东西吧!在官网上下载就okay了,不做说明,下载安装的时候会 ...
- Yii 配置默认controller和action
设置默认controller 在/protected/config/main.php添加配置 <?php return array( 'name'=>'Auto', 'defaultCon ...
- YIi配置debug工具、yii配置gii工具
$config['bootstrap'][] = 'debug';$config['modules']['debug'] = [ 'class'=>'yii\debug\Module', 'al ...
- yii配置访问路由权限配置
'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'logout' => ['post', 'ge ...
- Yii 同域名的单点登录 SSO实现
SSO (Single Sign-on) 顾名思义就是几个子项目共用一个登录点. 原理简单来说就是服务端session 共享, 客户端跨域cookies. 实现非常简单,protected/confi ...
- Yii框架-Smarty-整合
一.搭建yii框架 一.首先你得下个YII框架的源码 :下载地址:http://www.yiiframework.com/download/ 二.把下载到的源码解压放到一个PHP可访问的位置:如我的 ...
- YII安装步骤(windows)
一.首先你得下个YII框架的源码 :下载地址:http://www.yiiframework.com/download/ 二.把下载到的源码解压放到一个PHP可访问的位置:如我的 F:\site(已具 ...
- Yii2 Apache + Nginx 路由重写
一.什么是路由重写 原本的HTTP访问地址: www.test.com/index.php?r=post/view&id=100 表示这个请求将由PostController 的 action ...
随机推荐
- Android UI--ViewPager扩展Tab标签指示
Android UI--ViewPager扩展Tab标签指示 2013年8月30日出来冒冒泡 ViewPager这个控件已经不算是陌生的了,各种玩Android的小伙伴们都有发表相应的文章来讲它.我看 ...
- jquery 使用ajax调用c#后台方法
$.ajax({ type: "get", cache: false, ...
- 怎样用U盘安装Ubuntu系统/ubuntu系统怎么安装
Linux一直以来都是比较小众的系统,特别是在国内,用户相对Windows来说,更是少,甚至给人一种高端,复杂的印象,不过这些年来,使用 linux的人越来越多了,基本用的都是程序猿,而Ubuntu作 ...
- Windows下Oracle服务介绍
如图,截取的是11gR2下RAC其中一个节点的Oracle服务列表. oracle在处理一般事务时并不需要全部启动其后台的所有服务由于oracle服务所占用系统资源比较大,一般情况下,对于单实例的OR ...
- MVC5.0 中如何提高Controller 的优先级
//在area下建立的Home namespace WebApplication8.Areas.Weather.Controllers { public class HomeController : ...
- XML 文档解析操作
sing System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security; ...
- JS提取URL中的参数
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- [NOIP2001提高组]CODEVS1014 Car的旅行路线(最短路)
最短路,这个不难想,但是要为它加边就有点麻烦..还好写完就过了(虽然WA了一次,因为我调试用的输出没删了..),不然实在是觉得挺难调的.. ------------------------------ ...
- [LeetCode]题解(python):105-Construct Binary Tree from Preorder and Inorder Traversal
题目来源: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题意分析: ...
- python自学笔记(五)python文本操作
一.python自带方法 r:read 读 w:write 写 a:append 尾行追加 先命令行进入python后 >>>d = open('a.txt','w') #在对应路径 ...