14-LNMP搭建

介绍

LNMP: Linux + Nginx + Mysql/Mariadb + PHP
借助LNMP,我们就能搭建一个动态的网页。

安装Nginx

详细nginx教程:https://blog.csdn.net/NetRookieX/article/details/104736601

安装Mariadb

详细Mariadb教程:https://blog.csdn.net/NetRookieX/article/details/104734181

安装PHP

yum -y install php php-fpm
yum -y install php-gd php-mysql php-mbstring php-xml php-mcrypt  php-imap php-odbc php-pear php -xmlrpc  	#与数据库交互的包
systemctl restart php-fpm
systemctl enable php-fpm

使nginx和php能够交互

vim /etc/nginx/nginx.conf
    location / {				#修改此项
        root /usr/share/nginx/html;
        index index.html index.htm index.php;       #注意加上index.php
    }
    location ~ \.php$ {			#添加此项(将所有以.php结尾的url代理到php)
            root            html;            #设置网页根目录
            fastcgi_pass    127.0.0.1:9000;  #指定php的地址   
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include         fastcgi_params;
    }
systemctl restart nginx

测试

vim /usr/share/nginx/html/info.php
    <?php  
    phpinfo();  
    ?>
http://192.168.191.128/info.php		#测试

能看到下面的信息就代表成功了:

UTOOLS1584757412313.png

LNMP原理:

这里我们使用的Linux衍生版本是CentOS7,是操作系统。
Mariadb作为数据库。
Nginx用于处理url,将.php结尾的请求交给PHP处理。
PHP处理动态请求。处理完之后交给nginx。
nginx最后将结果返回给Client。
(整个过程很像NAT)


posted @ 2020-03-21 10:30  NetRookieX  阅读(9)  评论(0编辑  收藏  举报