ubuntu下搭建LNMP环境

  1. Nginx安装
sudo apt-get update
sudo apt-get install nginx

# 安装完查看nginx版本
nginx -v

# 浏览器中打开localhost可以看到默认的welcome to nginx页面,如果显示异常可以查看下nginx默认的80端口是否被其他进程占用,比如apache
lsof -i :80
  1. Mysql安装及配置
sudo apt-get install msyql-server
# 查看mysql版本
mysql -V

# 旧版本mysql安装过程中会提示修改密码,新版本省略了该过程,需要安装完毕之后手动配置安全选项
sudo mysql_secure_installation

# 1.命令执行之后,会询问你是否开启密码验证,输入Y即可
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:

# 2.设置密码强度,开发环境只需要设置成最低模式的8位以上字符,输入0即可
There are three levels of password validation policy:
LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG

# 3.输入两次mysql密码,然后会询问你是否重新修改,可根据需要填写
# 4.Disallow root login remotely?[Y/n] 可根据需要关闭远程登录
# 5.Remove anonymous users? [Y/n] 可根据需要删除匿名用户
# 6.Remove test database and access to it? [Y/n] 可根据需要删除test数据库
# 7.Reload privilege tables now? [Y/n] 输入Y重新载入表权限

sudo mysql
# mysql命令行下输入命令,查看所有用户的登陆验证方式,默认情况下mysql的root用户登陆方式是auth_socket,没法通过密码进行登陆,需要修改成authentication_string方式
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> update mysql.user set authentication_string=PASSWORD('你的秘密'),plugin='mysql_native_password' where user='root';
mysql> flush privileges;
mysql> exit;
# 重启mysql服务
sudo service mysql restart
mysql -u root -p
# 正常情况下输入密码即可登陆mysql
  1. php安装及开发常用扩展
sudo apt-get install php7.2 php7.2-cli php7.2-mbstring php7.2-json php7.2-gd php7.2-xml php7.2-common php7.2-fpm
php -v

完结撒花~

你可能感兴趣的:(ubuntu下搭建LNMP环境)