LNMP部署、构建
一,部署、構(gòu)建LNMP
- 安裝部署Nginx、MariaDB、PHP、PHP-FPM;
1,裝nginx
#yum -y install gcc pcre-devel openssl-devel.i686 zlib-devel
#useradd -s /sbin/nologin nginx
#tar -xf nginx-1.10.3.tar.gz?
#cd nginx-1.10.3/
#./configure --help
#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
#make && make install
#/usr/local/nginx/sbin/nginx
#ln -s /usr/local/nginx/sbin/nginx /sbin/
#nginx -V
#ss -anutlp | grep nginx
? 2,裝mariadb
#yum -y install mariadb mariadb-server.x86_64 mariadb-devel
#systemctl restart mariadb.service?
#systemctl enable mariadb.service?
#ss -anutlp | grep mysql
? 3,裝php(php-fpm自己下載包)
#yum -y install php php-mysql
#yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm
#systemctl restart php-fpm.service?
#systemctl enable php-fpm.service?
#ss -anutlp | grep php
? 4,查看php-fpm配置文件
# vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000 ? ? ? ?//PHP端口號(hào)
pm.max_children = 32 ? ? ? ? ?//最大進(jìn)程數(shù)量
pm.start_servers = 15 ? ? ? ?//最小進(jìn)程數(shù)量
pm.min_spare_servers = 5 ? ?//最少需要幾個(gè)空閑著的進(jìn)程
pm.max_spare_servers = 32 ?//最多允許幾個(gè)進(jìn)程處于空閑狀態(tài)
?
5, 修改nginx配置文件
#vim /usr/local/nginx/conf/nginx.conf
大概45行加上index.php
location / {
? ? root ? html;
? ? index index.php index.html index.htm;
? ?} ? ? ? ? ? ? ?//(設(shè)置默認(rèn)首頁(yè)為index.php,當(dāng)用戶在瀏覽器地址欄中只寫域名或IP,不說(shuō)訪問什么頁(yè)面時(shí),服務(wù)器會(huì)把默認(rèn)首頁(yè)index.php返回給用戶)
...?
? 大概去掉65-68行#,修改70行
location ~ \.php$ {
? ? ? ?root ? ? ? ? ? html;
? ? fastcgi_pass ? 127.0.0.1:9000; //將請(qǐng)求轉(zhuǎn)發(fā)給本機(jī)9000端口,PHP解釋器
? ? fastcgi_index ?index.php;
? ? #fastcgi_param ?SCRIPT_FILENAME ?/scripts$fast ? ?cgi_script_name;
? ? ?include ? ? ? ?fastcgi.conf;
? ? ? ?}
...
#nginx -s reload
??
? 6,創(chuàng)建PHP頁(yè)面,測(cè)試LNMP架構(gòu)能否解析PHP頁(yè)面
? 創(chuàng)建PHP測(cè)試頁(yè)面1,/usr/local/nginx/html/test01.php
#vim /usr/local/nginx/html/test01.php
<html>
<body>
This is HTML message
</br>
<?php?
$c = 12;
$d = 2;
if($c > $d){echo "c is bigger";}
else{ echo "d is bigger";}
?>
</body>
</html>
?
創(chuàng)建PHP測(cè)試頁(yè)面,連接并查詢MariaDB數(shù)據(jù)庫(kù)。
#vim /usr/local/nginx/html/test02.php
<?php
$mysqli = new mysqli('localhost','root','','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>");
}
?>
? ?7,客戶端訪問
#firefox http://201.1.2.100/test02.php
#firefox http://201.1.2.100/test01.php
===============lnmp 環(huán)境完工=========
----------------------------------------------------------------------------------
LNMP 安裝包百度網(wǎng)盤? 下載地址:
鏈接:https://pan.baidu.com/s/1FCTgmxN1Aw1YB8fGEdOv2A?
提取碼:1p9y?
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
動(dòng)態(tài)頁(yè)面故障:
?
總結(jié)
- 上一篇: Nginx优化、服务器状态模块(--wi
- 下一篇: Nginx--------地址重写