Centos7配置LNMP + Redis【上篇】

1、安装Nginx

[root@localhost ~]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@localhost ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@localhost ~]# tar -xf nginx-1.12.2.tar.gz
[root@localhost ~]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure
[root@localhost nginx-1.12.2]# make && make install
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

2、修改nginx配置文件

 [root@localhost conf]# cd /usr/local/nginx
 [root@localhost conf]# cp nginx.conf nginx.conf.bak
 [root@localhost conf]# diff nginx.conf nginx.conf.bak 
65,71c65,71
<         location ~ \.php$ {
    
    
<             root           html;
<             fastcgi_pass   127.0.0.1:9000;
<             fastcgi_index  index.php;
<             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
<             include        fastcgi.conf;
<         }
---
>         #location ~ \.php$ {
    
    
>         #    root           html;
>         #    fastcgi_pass   127.0.0.1:9000;
>         #    fastcgi_index  index.php;
>         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
>         #    include        fastcgi_params;
>         #}
[root@localhost conf]# nginx -s stop && nginx

3、安装php解释环境

[root@localhost ~]# yum -y install php-common php-fpm php php-mysql

4.编写test.php进行验证

[root@localhost ~]# systemctl start php-fpm && nginx
[root@localhost ~]# netstat -anultp | grep 80 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      41903/nginx: master 
[root@localhost ~]# netstat -anultp | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      41648/php-fpm: mast 
[root@localhost ~]# echo "<?php phpinfo();?>" > /usr/local/nginx/html/test.php

浏览器测试
在这里插入图片描述
5、安装mysql [附: centos7 安装docker教程]

[root@localhost ~]# docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

6、编写mysql.php测试LNMP

<?php
$mysqli = new mysqli('127.0.0.1','root','123456','mysql');
if (mysqli_connect_errno()){
    
    
	die('Unable to connect!'). mysqli_connect_error();
}
$sql = "select * from user";
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
    
    
	printf("Host:%s",$row[0]);
	printf("</br>");
	printf("Name:%s",$row[1]);
	printf("</br>");
}
?>

浏览器测试
在这里插入图片描述


还剩下个redis
Centos7配置LNMP + Redis【下篇】

猜你喜欢

转载自blog.csdn.net/qq_38900565/article/details/108045021