本文主要是关于在MacOS下Composer和Yii2的安装,以及Yii2的运行。安装php环境网上教程比较多就略了,而且也可以使用mamp之类的套件。

安装Composer:

  1. 按顺序依次执行以下四个命令:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
  1. 将Composer设为全局:
mv composer.phar /usr/local/bin/composer

Yii2高级版安装:

  1. 执行:
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii2-advanced
  1. 初始化:
php init
  1. 分别打开前后台网址运行:
http://localhost:8888/yii2-advanced/frontend/web/
http://localhost:8888/yii2-advanced/backend/web/

数据库配置:

  1. 进入phpmyadmin,创建数据表yii2advanced
  2. 打开common/config/main-local.php,添加数据库端口及修改账号密码。
  3. 执行数据迁移命令:
php yii migrate