注释: l表示linux系统,n表示nginx服务,m表示mysql服务,p表示php语言;

1,linux环境准备

a.停防火墙,,关闭selinux,配置本地yum

搭建lnmp架构_php

2, 安装nginx服务

2.1 提前安装nginx的依赖包,创建nginx管理用户

[root@localhost ~]# yum -y install pcre-devel zlib-devel gcc openssl-devel

[root@localhost ~]# useradd -s /sbin/nologin nginx   #不允许登录系统

2.2 准备nginx安装包

[root@localhost ~]# wget http://nginx.org/download/nginx-1.8.0.tar.gz

2.3 源码安装nginx

搭建lnmp架构_启动服务_02

[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx    \

--user=nginx --group=nginx --with-http_ssl_module

[root@localhost nginx-1.8.0]# make && make install    

2.4 修改配置文件

搭建lnmp架构_nginx_03

2.5 启动nginx服务

[root@localhost nginx]# /usr/local/nginx/sbin/nginx   #正常启动,命令行没有任何输出

3,安装mysql服务,这里使用mariadb软件包

[root@localhost nginx]# yum -y install mariadb-server mariadb  mariadb-devel 

[root@localhost nginx]# systemctl restart mariadb    #启动服务

4,安装php服务

4.1 上传php-fpm安装包,安装,启动服务

​https://mirrors.lzu.edu.cn/centos/7/os/x86_64/Packages/​​   此网站查找安装包

因依赖关系,需要同时下载以下rpm包

搭建lnmp架构_启动服务_04

[root@localhost php]# systemctl restart php-fpm    #启动服务

5,编写php脚本,并测试

[root@localhost php]# cat /usr/local/nginx/html/test.php  

<?php

phpinfo();

?>

搭建lnmp架构_启动服务_05

6,编写php连接数据库脚本,测试

[root@localhost php]# cat /usr/local/nginx/html/test2.php  

<?php

$links=mysql_connect("localhost","root","");        

if($links){

       echo "link db ok!!!";

}

else{

      echo "link db no!!!";

}

?>

搭建lnmp架构_nginx_06