Ubuntu 16 下部署 Laravel LNMP 环境

环境介绍

  • 阿里云 ECS 服务器
  • Ubuntu 16.04
  • Nginx
  • PHP 7.1
  • MYSQL 5.7
  • Laravel 5.6

在 Ubuntu 16 上部署 LNMP 环境
使用了 Laravel china 社区中 Summer 的教程 Ubuntu 14/16 下的 Laravel LNMP 线上环境自动部署脚本

此脚本用于在一台全新的 Ubuntu 14.04 LTS( Ubuntu 16 请使用这个脚本) 上部署适合 Laravel 使用的 LNMP 生产环境。
此脚本参照了 Homestead 环境设置脚本 ,并做了更加适用于生产环境的效率和安全调优。

也可参考另一篇不错的文章 阿里云 ECS 服务器 Ubuntu14.04 部署 Laravel 5.5 项目上线

FAQ

按照上面的步骤执行下来发现很多软件没有安装成功?

Ubuntu 16.04下,按照 summer 的教程操作之前,需依次执行:

apt-get update
apt-get -y upgrade
apt-get install -y software-properties-common curl 

Nginx 无法正常启动

原因是 80 端口被 apache2 占用,删除 apache2,依次执行

sudo apt-get --purge remove apache-common
sudo apt-get --purge remove apache
sudo find /etc -name "apache" |xargs rm -rf
sudo rm -rf /var/www
$ sudo rm -rf /etc/apache2

缺少一些 PHP 扩展

sudo apt-get -y install php7.1-mysql
sudo apt-get install php7.1-mbstring
sudo apt-get install php7.1-xml 
sudo apt-get install php7.1-gd

远程链接 MYSQL 数据库报 2003(“2013 - lost connection to mysql server at ")错误

解决方法:打开文件 /etc/mysql/mysql.conf.d/mysqld.cnf,找到 bing-address 将其注释掉

bind-address            = 127.0.0.1 

注释后

#bind-address

远程链接 MYSQL 数据库报 1130(1130-host ... is not allowed to connect to this MySql server")错误

解决方法:

$ mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 51
Server version: 5.7.22-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql>use mysql;  
mysql>update user set host = '%' where user ='root';  
mysql>select host, user from user;  
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //赋予任何主机访问数据的权限  
mysql>FLUSH PRIVILEGES //修改生效  
mysql>EXIT //退出MySQL  
service mysql restart 重启mysql  

MYSQL 数据库报1698错误 “1698 Access denied for user @”, root 用户不需要任何密码也可以登入

解决方法:

$ sudo mysql  
mysql> USE mysql;  
mysql> UPDATE user SET plugin='' WHERE User='root';  
mysql> FLUSH PRIVILEGES;  
mysql> exit;  
$ service mysql restart  

也有可能遇到忘记 MYSQL 数据库 root 用户登录密码

解决办法是打开文件 /etc/mysql/mysql.conf.d/mysqld.cnf 在最后加入一句 skip-grant-tables

图片.png | left | 696x81

然后重启 mysql

$ service mysql restart;

不需要密码进入

$ mysql -u root;

修改 root 密码

 $ use mysql;
 $ update user set authentication_string=password('123456') where user='root';
 $ flush privileges;

主要是记录一下自己遇到的问题
感谢 @Summer@Yvan 分享的文章

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 1

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!