Yii2 – 安装高级模板 advanced project template

在yii2官网,可以看到有两个版本,一个是base template,一个是advanced tempalte,高级模板更加强大一些,初始化后有一个公用的common,三个控制入口,frontend,backend,console,分别对应前台,后台,控制台,很适合线上有一定规模的网站,譬如电商网站,我们用frontend做前端显示,backend做后台,console做一些命令行的数据处理,cron定时处理脚本等,这里,我所要说的是,如何从零安装yii2的高级模板。

composer堪称神器,类似于yum安装,自己解决包依赖,所以,安装的过程中也是用composer来安装。

1.安装composer

curl -sS https://getcomposer.org/installer | php  
mv composer.phar /usr/local/bin/composer 
composer self-update

第一行为下载composer,具体执行log:

[root@iZ942k2d5ezZ ~]# curl -sS https://getcomposer.org/installer | php 
All settings correct for using Composer
Downloading 1.0.2...

Composer successfully installed to: /root/composer.phar
Use it: php composer.phar

 

2.初始安装:fxp/composer-asset-plugin

composer global require "fxp/composer-asset-plugin:~1.1.1"

3.安装yii2

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

安装log如下:

[root@iZ942k2d5ezZ test]# composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
Running composer as root/super user is highly discouraged as packages, plugins and scripts cannot always be trusted
Installing yiisoft/yii2-app-advanced (2.0.8)
  - Installing yiisoft/yii2-app-advanced (2.0.8)
    Downloading: 100%         

Created project in yii-application
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing yiisoft/yii2-composer (2.0.4)               
    Loading from cache

  - Installing swiftmailer/swiftmailer (v5.4.1)
    Loading from cache

  - Installing bower-asset/jquery (2.2.3)
    Loading from cache

  - Installing bower-asset/yii2-pjax (v2.0.6)
    Loading from cache

  - Installing bower-asset/punycode (v1.3.2)
    Loading from cache

  - Installing bower-asset/jquery.inputmask (3.2.7)
    Loading from cache

  - Installing cebe/markdown (1.1.0)
    Loading from cache

  - Installing ezyang/htmlpurifier (v4.7.0)
    Downloading: 100%         

  - Installing yiisoft/yii2 (2.0.8)
    Downloading: 100%         

  - Installing yiisoft/yii2-swiftmailer (2.0.5)
    Loading from cache

  - Installing yiisoft/yii2-codeception (2.0.5)
    Loading from cache

  - Installing bower-asset/bootstrap (v3.3.5)
    Loading from cache

  - Installing yiisoft/yii2-bootstrap (2.0.6)
    Loading from cache

  - Installing yiisoft/yii2-debug (2.0.6)
    Loading from cache

  - Installing bower-asset/typeahead.js (v0.11.1)
    Loading from cache

  - Installing phpspec/php-diff (v1.1.0)
    Loading from cache

  - Installing yiisoft/yii2-gii (2.0.5)
    Loading from cache

  - Installing fzaninotto/faker (v1.5.0)
    Loading from cache

  - Installing yiisoft/yii2-faker (2.0.3)
    Loading from cache

fzaninotto/faker suggests installing ext-intl (*)
Writing lock file
Generating autoload files

 

执行完成上面的,yii2就下载好了,我们需要初始化

4. yii 高级模板初始化

进入yii-application目录(上面用composer安装的目录),执行:

./init

执行log如下:

[root@iZ942k2d5ezZ yii-application]# ./init
Yii Application Initialization Tool v1.0

Which environment do you want the application to be initialized in?

  [0] Development
  [1] Production

  Your choice [0-1, or "q" to quit] 0

  Initialize the application under 'Development' environment? [yes|no] yes

  Start initialization ...

   generate common/config/main-local.php
   generate common/config/params-local.php
   generate frontend/config/main-local.php
   generate frontend/config/params-local.php
   generate frontend/web/index.php
   generate frontend/web/index-test.php
   generate console/config/main-local.php
   generate console/config/params-local.php
   generate backend/config/main-local.php
   generate backend/config/params-local.php
   generate backend/web/index.php
   generate backend/web/index-test.php
   generate tests/codeception/config/config-local.php
   generate yii
   generate cookie validation key in backend/config/main-local.php
   generate cookie validation key in frontend/config/main-local.php
      chmod 0777 backend/runtime
      chmod 0777 backend/web/assets
      chmod 0777 frontend/runtime
      chmod 0777 frontend/web/assets
      chmod 0755 yii
      chmod 0755 tests/codeception/bin/yii

  ... initialization completed.

[root@iZ942k2d5ezZ yii-application]# 

到这里就安装了yii2高级模板的安装,配置nginx

前台地址:frontend/web

后台地址:backend/web

访问的时候,在linux下面需要将web目录下面的assets文件夹设置成可写。

这样就完成了yii2 advanced的安装了

 

linux 安装mysql5.6

Linux:Centos

1.先查看系统上有没有安装了旧版本的MySQL ,用下面的命令:

rpm -qa | grep mysql

如果有,用以下命令卸载

rpm -e --nodeps 上步显示mysql名称

安装编译mysql 需要的依赖包

yum install  libevent*  libtool* autoconf* libstd* ncurse* bison* openssl*  
yum -y install gcc gcc-c++

2.安装cmake,mysql5.5之后需要用cmake支持编译安装,下载安装cmake

wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz  
tar -xf cmake-2.8.12.1.tar.gz  
cd cmake-2.8.12.1  
./configure && make && make install  

检查cmake安装好了没

cmake --version

3.下载mysql

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz  
tar xvf mysql-5.6.14.tar.gz  
cd mysql-5.6.14

上面如果下载失败,可以到这里下载:http://download.csdn.net/detail/terry_water/6973721

或者在百度网盘下载:https://pan.baidu.com/s/1kVwRD2Z

4.编译安装

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install

如果在上面的编译报错,Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH),则使用下面的编辑代码:

cmake -DCURSES_LIBRARY=/usr/lib/libncurses.so -DCURSES_INCLUDE_PATH=/usr/include  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

 

要很长时间的等待,我虚拟机中安装是双核2G内存,花了20分钟左右的。

另外还可能遇到下面的错误:

1.

yum install  libevent*  libtool* autoconf* libstd* ncurse* bison* openssl*

报错:
libevent2-devel conflicts with libevent-devel-1.4.13-4.el6.x86_64

则执行:

yum install  libevent2  libtool* autoconf* libstd* ncurse* bison* openssl*

2.
查看 ls /usr/lib/libncurses.so
如果找不到,则
find / -name ‘libncurses.so’
我找到的文件如下:
/usr/lib64/libncurses.so
增加快捷方式

ln -s /usr/lib64/libncurses.so  /usr/lib/libncurses.so

5.配置mysql

groupadd mysql  
useradd -g mysql mysql

 

chown -R mysql:mysql /usr/local/mysql

初始化配置

cd /usr/local/mysql  
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

配置自启动和启动mysql

cp support-files/mysql.server /etc/init.d/mysql  
chkconfig mysql on  
service mysql start

配置PATH

vi /etc/profile  
#在文件末尾添加  
PATH=/usr/local/mysql/bin:$PATH  
export PATH  
#保存退出,生效配置  
source /etc/profile

登陆mysql 并设置root密码

mysql -uroot  
mysql> SET PASSWORD = PASSWORD('123456');  
设置mysql可以远程访问  
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

如果是远程,配置可以远程访问,配置防火墙,允许3306端口

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT  
/etc/rc.d/init.d/iptables save

6.数据库定时备份:

mkdir /backup  
chmod 777 -R /backup
vim /backup/mysql_backup.sh

写入如下内容:-p引号里面是数据库的密码,erp是备份的数据库名字

#!/bin/bash  
date=$(date +%Y%m%d)  
/usr/local/mysql/bin/mysqldump -h localhost -uroot -p'Ddsd#$#2s$!s4343%$^&s' erp > /backup/databases-$date.sql

设置CRON,定时备份:

crontab -e   
00 06 * * * /bin/bash /backup/mysql_backup.sh

 

 

 

Yii2 DWZ JUI 扩展 插件

本人写的一个YII2 DWZ整合的后台账户管理,菜单权限控制,日志管理,缓存管理的的admin UI.欢迎下载:

Yii2 Fancy Ecommerce ADMIN (FEC ADMIN)

DEMO: http://demo.fancyecommerce.com/

测试账户: admin admin123(密码)

下面是github部分的内容,欢迎下载!

github: https://github.com/fancyecommerce/yii2_fec_admin/


作者 :Terry

作者QQ : 2358269014

作者Email : 2358269014@qq.com


有任何建议或者需求欢迎来反馈 issues

欢迎点击右上方的 star 收藏

fork 参与开发,欢迎提交 Pull Requests,然后 Pull Request


1、安装

安装这个扩展的首选方式是通过 composer.

执行

composer require --prefer-dist fancyecommerce/fec_admin

或添加

"fancyecommerce/fec_admin": "~1.3.3"  
composer install

 

2、配置

配置:在原来的基础上添加如下代码:main.php

'modules'=>[  
        'fecadmin' => '\fecadmin\Module',  
    ],  
 'components' => [  
       'user' => [  
            'identityClass' => 'fecadmin\models\AdminUser',  
            'enableAutoLogin' => true,  
        ],  
        'urlManager' => [  
                'class' => 'yii\web\UrlManager',  
                'enablePrettyUrl' => true,  
                'showScriptName' => false,  
                'rules' => [  
                    '' => 'fecadmin/index/index',  
                    //'blog' => 'blog/index/index',  
  
                ],  
            ],  
        ],

param设置:config/param.php

<?php  
return [  
    'theme'             =>  'default',  
    'systemlog'         => [  
                    'enable' => true,  
                ],  
];