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)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章