以下是我学习yii2.0时的配置方法

1.安装 composer

brew install composer (前提安装了brew)

2.更改composer镜像地址

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

3.安装 yii2.0_advanced(高级版前后台分离)

cd /你想安装的文件夹
composer create-project --prefer-dist yiisoft/yii2-app-advanced 文件夹名

4.更改权限

sudo chmod -R 777 文件夹名

5.更新yii依赖

composer update

6.初始化环境

到安装完成的文件夹里点击执行 init

7. 修改数据库地址及密码

common/config/main-local.php
<?php


return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=服务器地址;dbname=数据库名',
            'username' => '用户名',
            'password' => '密码',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
    ],
];

8.新建数据库

  • 我用的是phpmyadmin

    -- --------------------------------------------------------
    CREATE TABLE `user` (
    `id` int(10) NOT NULL,
    `username` varchar(60) NOT NULL,
    `auth_key` char(32) NOT NULL,
    `password_hash` char(60) NOT NULL,
    `password_rese_token` char(60) DEFAULT NULL,
    `verification_token` varchar(60) NOT NULL,
    `avatar_path` varchar(140) DEFAULT NULL,
    `user_status` tinyint(1) DEFAULT 1,
    `created_at` int(10) DEFAULT NULL,
    `updated_at` int(10) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

8.配置完毕后可以成功创建用户但登录不上?

查看这里