Ubuntu 安装yii2 advanced版 遇到的坑
1.安装 Composer
https://www.yiichina.com/doc/guide/2.0/start-installation
通过 Composer 安装
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

解决方案
sudo vim /etc/php/7.2/cli/php.ini
zlib.output_compression = ON

安装成功
2.安装yii2 高级版
安装yii2
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
报错:
更换源:
composer config repo.packagist composer https://packagist.phpcomposer.com
报错:
加参数-g global
composer config -g repo.packagist composer https://packagist.phpcomposer.com
再次安装yii2
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

更改网络连接方式,桥接方式
安装php-mbstring
sudo apt-get install php-mbstring
报网络连接超时
在浏览器打开安装包地址
http://ppa.launchpad.net/ondrej/php/ubuntu/pool/main/p/php7.2/php7.2-mbstring_7.2.9-1+ubuntu16.04.1+deb.sury.org+1_amd64.deb
不能访问,
发现另外一个复制的虚拟机也打开了,怀疑是IP地址冲突,关掉另外一台虚拟机后,可以打开这个地址
再次安装,报错:
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application


执行:sudo apt-get install phpunitsudo apt-get install php7.2-xml
再次安装,安装成功
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application



3.配置nginx
sudo vim /etc/nginx/sites-available/default
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name frontend.test;
root /home/jay/yii-application/frontend/web/;
index index.php;
access_log /home/jay/yii-application/log/frontend-access.log;
error_log /home/jay/yii-application/log/frontend-error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name backend.test;
root /home/jay/yii-application/backend/web/;
index index.php;
access_log /home/jay/yii-application/log/backend-access.log;
error_log /home/jay/yii-application/log/backend-error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~* /\. {
deny all;
}
}
重启nginx
sudo service nginx reload
sudo service nginx restart
查看错误日志
journalctl -xe
文件不存在
"/home/jay/yii-application/log/frontend-access.log" failed (2: No such file or directory)
解决方案:创建一个log文件夹
nignx 403
解决方案:初始化yii-application
~/yii-application$ php init

配置hosts
打开http://backend.test
报错502
安装php-fpm
sudo apt-get install php7.2-fpm
php-fpm监听地址有问题,需要与nginx监听地址一致 127.0.0.1:9000
sudo vim /etc/php/7.2/fpm/pool.d/www.conf
重启php7.2-fpm
sudo service php7.2-fpm restart
打开http://backend.test 跳转到login页面
http://frontend.test/ 跳转到欢迎页面
check php info
在/home/jay/yii-application/frontend/web 目录创建一个test.php文件
运行http://frontend.test/test.php
4.配置mysql
check mysql 服务是否打开,有localhost:mysql则表示服务已打开
sudo netstat -tap | grep mysql

start service
/etc/init.d/mysql start
stop service
/etc/init.d/mysql stop
连接mysql
mysql -u root -p
报错
切换到root用户
sudo su root
连接mysql,连接成功
mysql -u root -p

查看有哪些数据库
mysql> show databases

查看yii2 配置的数据库:
创建 yii2advanced数据库
mysql> create database yii2advanced
登陆报错,php mysql driver没有安装
安装php mysql 扩展
sudo apt-get install php7.2-mysql
再次登陆,报错:
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

修改用户名密码
mysql -u root -p yii2advanced
mysql> select plugin from mysql.user where user = 'root';
mysql> update mysql.user set plugin='mysql_native_password';
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('abc123_') WHERE user='root';
mysql> flush privileges;
mysql> exit


再次连接mysql
mysql -u root -p yii2advanced
输入abc123_
登陆成功
#5. 访问数据库
login
报 The table does not exist: {{%user}} 未找到
创建user表
CREATE TABLE IF NOT EXISTS `user`(
`id` INT UNSIGNED AUTO_INCREMENT,
`status` varchar (100),
`username` varchar (100),
`password` varchar (50),
`email` varchar (50),
`password_hash` varchar (200),
`password_reset_token` varchar (200),
`auth_key` varchar (50),
`created_at` varchar (50),
`updated_at` varchar (50),
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
注册报错:
Setting unknown property: common\models\User::password_hash

gii生成代码
http://127.0.0.1/index.php?r=gii

报错:
Unable to write the file /yii-application/backend/models/Test.php'.
设置权限
sudo chmod -R 0777 backend
CURD


生成成功
查看文件目录
访问http://backend.test/index.php?r=test/index

phpMyAdmin 查询user表报错
$ sudo vim /usr/share/phpmyadmin/libraries/sql.lib.php
找到
(count($analyzed_sql_results['select_expr'] == 1)
1
改成和下面这句话一样就可以了~
(count($analyzed_sql_results['select_expr']) == 1

注册,登陆成功
数据插入到数据库里面了
作 者:
Jackson0714
出 处:http://www.cnblogs.com/jackson0714/
关于作者:专注于微软平台的项目开发。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!
Ubuntu 安装yii2 advanced版 遇到的坑的更多相关文章
- yii2 advanced版基础部分
yii2 advanced版 一.目录结构 1.backend 和 frontend : 前后台入口,相当于是一个单独的Basic应用,有自己的 mvc 目录.配置文件目录.入口文件目录 2.cons ...
- linux mint & ubuntu 安装QQ国际版
ubuntu安装QQ相对简单 下载qq国际版deb文件,直接安装即可. 下载地址: http://pan.baidu.com/s/1hqmYzlU 下面就重点说一下linux mint 安装qq. 1 ...
- 【Caffe】Ubuntu 安装 Caffe gpu版
安装环境:Ubuntu 16.04lts 64位, gcc5.4 gpu1050ti,cuda8.0,cudnn5.1.10 1. 安装依赖库 sudo apt-get install libprot ...
- Ubuntu安装deepin wine版QQ
1.安装deepin wine环境 https://github.com/wszqkzqk/deepin-wine-ubuntu 直接下载zip包(或者用git方式克隆) 使用unzip解压到指定文件 ...
- Ubuntu安装Windows官方版QQ和微信(使用deepin wine)
- Yii2 advanced版API接口开发 基于RESTful架构的 配置、实现、测试
参考地址: http://www.xiaoxiangzi.com/Programme/PHP/3348.html http://www.cnblogs.com/ganiks/p/yii2-restfu ...
- Windows下使用Composer安装yii2
Composer简介 Composer 是PHP中用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer会帮你安装这些依赖的 ...
- Win10 下安装Ubuntu 21.04桌面版 双系统 并设置win10为默认启动系统 详细教程
@ 目录 〇.写在前面 〇 - Plus:如何进入BIOS 〇 - Plus - Plus:U盘启动快捷键 一.磁盘分区:Win10划分未分配空间 二.下载Ubuntu 21.04镜像 三.安装U盘启 ...
- Ubuntu 16.04安装QQ国际版图文详细教程
因工作需要,我安装了Ubuntu 16.04,但是工作上的很多事情需要QQ联系,然而在Ubuntu上的WebQQ很是不好用,于是在网上搜索了好多个Linux版本的QQ,然而不是功能不全 ...
随机推荐
- JS奇淫巧技:防抖函数与节流函数
应用场景 实际工作中,我们经常性的会通过监听某些事件完成对应的需求,比如: 通过监听 scroll 事件,检测滚动位置,根据滚动位置显示返回顶部按钮 通过监听 resize 事件,对某些自适应页面调整 ...
- Golang 嵌套map赋值办法
http://my.oschina.net/sol/blog/159060 m := map[string]map[string]string{} mm, ok := m["kkk" ...
- JAVAEE——Mybatis第二天:输入和输出映射、动态sql、关联查询、Mybatis整合spring、Mybatis逆向工程
1. 学习计划 1.输入映射和输出映射 a) 输入参数映射 b) 返回值映射 2.动态sql a) If标签 b) Where标签 c) Sql片段 d) Foreach标签 3.关联查询 a) 一对 ...
- tomcat设置端口号,访问指定ip就访问指定项目
1.修改背景: A.通常我们访问我们的web应用格式为: http://ip:端口号/项目名称 例如: http://127.0.0.1:8080/projectName B.如果想直接输入" ...
- lsb_release -a 查询Linux系统版本
LSB是Linux Standard Base的缩写,lsb_release命令用来显示LSB和特定版本的相关信息.如果使用该命令时不带参数,则默认加上-v参数.-v, --version显示版本信息 ...
- 使用jvisualvm
jvisualvm是java开发,调试,监控,分析内存的一个可视化工具,可以在安装完JDK中找到,一般在bin目录下 之前调试tomca内存分配,现在总结下心得, windows下的tomcat修改c ...
- C++类中静态变量和普通变量的区别
静态变量: 1.静态变量会被编到程序的exe里面,从程序启动到结束,它一直存在: 2.静态变量的初始化值为0: 3.全局变量默认是静态变量: 4.在类中的函数变量前面加了static的也是静态变量,只 ...
- 再谈async与await
回顾C#5.0是如何进行异步编程的 static void Main(string[] args) { string url = "https://docs.microsoft.com/zh ...
- 从壹开始微服务 [ DDD ] 之一 ║ D3模式设计初探 与 我的计划书
缘起 哈喽大家周四好!又是开心的一天,时间过的真快,我们的 <从壹开始 .net core 2.1 + vue 2.5>前后端分离系列共 34 篇已经完结了,当然以后肯定还会有更新和修改, ...
- Vue.js 牛刀小试(持续更新~~~)
一.前言 这个系列的文章开始于今年9月从上一家公司辞职后,在找工作的过程中,觉得自己应该学习一些新的东西,从前几章的更新日期也可以看出,中间隔了很长的时间,自己也经历了一些事情,既然现在已经稳定了,就 ...