Liunx +nginx/mysql/php lnmp环境搭建

网上安装lnmp的教程很多,但是还是安装失败过好多次,所以自己写了一份教程,本人只是菜鸟,仅供新手参考,大神勿喷。

此教程是CentOS下的安装如需Ubuntu请参考Ubuntu lnmp安装

  1. MYSQL安装

1.1 下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

1.2 安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

1.3 安装MYSQL

sudo yum install -y mysql-server

1.4 更改MYSQL用户权限:

sudo chown -R root:root /var/lib/mysql

1.5 重启服务

systemctl restart mysql.service

1.6 登录,并修改密码:

mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user='root';
mysql > flush privilgegs;
mysql > exit;

2.NGINX 安装

2.1 下载对应当前系统版本的nginx包

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.2 建立nginx的yum仓库(默认yum是没有nginx的)

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.3 下载并安装nginx

yum install nginx -y

2.4 nginx 重启

systemctl start nginx.service

3.安装PHP

3.1 rpm 安装 Php7 相应的 yum源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 

3.2 安装php7.0

yum install -y php70w 

3.3 安装PHP扩展

yum install -y  php70w-mysql.x86_64   php70w-gd.x86_64   php70w-ldap.x86_64   php70w-mbstring.x86_64  php70w-mcrypt.x86_64

3.4 安装PHP FPM

yum install -y php70w-fpm 

4.修改配置文件
4.1 修改NGINX配置文件

nginx配置文件位置:(/etc/nginx/conf.d/default.conf)

vim /etc/nginx/conf.d/default.conf

4.2 修改 root目录,可自定义:

root  /forest/nginxDir/html;

4.3 修改配置php解析:

location ~.php$ {
 root  /usr/WWW;
 ​ fastcgi_pass 127.0.0.1:9000;​
  fastcgi_index index.php;
  ​fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;​ include  fastcgi_params;
  } 

4.4 修改php-fpm配置文件

php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)

修改

user =nginx
group=nginx 

放入测试文件

cd /usr/WWW
vim index.php
<?php
	echo "hello word";
?>

5.启动服务

5.1 启动nginx服务:

systemctl start nginx.service 

查看启动状态:

systemctl status nginx 

看到以下字眼说明启动成功!

​Active: active (running) since 六 2016-11-19 13:40:04 CST; 50min ago

5.2 启动PHP-FPM:

systemctl start php-fpm.service 

查看启动状态:

systemctl status php-fpm.service 

看到以下字眼说明启动成功!

​Active: active (running) since 六 2016-11-19 14:14:33 CST; 18min ago

6.测试

在浏览器打开 ip地址/index.php

参考 https://www.jb51.net/article/137565.htm

猜你喜欢

转载自blog.csdn.net/qq_38324424/article/details/89011464