这篇教程中,我们将讨论怎样在Ubuntu 14.04搭建LNMP环境
1 安装Nginx
首先我们要更新apt源
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
安装Nginx
sudo apt-get install nginx
Nginx安装完默认以经启动
启动Nginx:service nginx start
关闭Nginx:service nginx stop
重启Nginx:service nginx restart
查看Nginx版本号(目前Nginx最新稳定版本为1.12.1) nginx -v

查看80端口是否起来 netstat -tlun | grep 80

输入服务器IP或域名后到你的浏览器地址栏,看到如下欢迎页,表示Nginx安装成功

2 安装php
首先添加 PPA
sudo LC_ALL=en_US.UTF-8add-apt-repository ppa:ondrej/php -y
sudo apt-get update
安装php7.1
sudo apt-get -y install php7.1
sudo apt-get -y install php7.1-mysql php7.1-fpm
接下来我们测试Nginx能否解析php文件
配置Nginx
vim /etc/nginx/sites-available/default

检查Nginx配置文件是否配置正确 nginx -t

重启Nginx(命令见上面)
配置php-fpm :
vim /etc/php/7.1/fpm/php.ini
打开注释,cgi.fix_pathinfo=1 改为 cgi.fix_pathinfo=0
重启php-fpm: service php7.1-fpm reload
在/var/www/html新建index.php文件测试看看,写上<?php phpinfo();

看到此图说明Nginx能成功解析 php文件
安装php扩展包(扩展包根据个人需求安装,这里我只演示安装curl,其余的安装包安装的照葫芦画瓢)
apt-cache search php7.1 查看php扩展包
sudo apt install php7.1-curl 安装curl
重启php-fpm,查看phpinfo

curl安装成功
3 安装Mysql
下载mysql-apt的配置包,并安装
wget https://dev.mysql.com/get/mysql-apt-config_0.8.1-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.1-1_all.deb (在安装的过程中,会要求选择mysql版本,选择mysql5.7版本后,点击“OK”。)
sudo apt-get update
安装mysql
sudo apt-get install mysql-server (安装过程会要求设置root密码)
安装mysql 后,使用mysql_upgrade升级数据库文件版本
sudo mysql_upgrade -uroot -p '你的数据库密码'
进入mysql,查看版本号
mysql -u root -p
select version();
用Navicat远程登录mysql(默认root用户不能远程登录),我们得创建一个用户用来远程登录
打开msyql配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address = 127.0.0.1注释
进入数据库,运行以下2条命名创建用户进行远程登录
CREATE USER 'xuecong'@'%' IDENTIFIED BY 'xuecong';
GRANT ALL ON *.* TO 'xuecong'@'%';

重启mysql: service mysql restart
用Navicat登录

至此我们LNMP环境以经搭建完毕,如有不对的地方,可以给我留言。谢谢!!!