一,部署、构建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端口号
pm.max_children = 32 //最大进程数量
pm.start_servers = 15 //最小进程数量
pm.min_spare_servers = 5 //最少需要几个空闲着的进程
pm.max_spare_servers = 32 //最多允许几个进程处于空闲状态
5, 修改nginx配置文件
#vim /usr/local/nginx/conf/nginx.conf
大概45行加上index.php
location / {
root html;
index index.php index.html index.htm;
} //(设置默认首页为index.php,当用户在浏览器地址栏中只写域名或IP,不说访问什么页面时,服务器会把默认首页index.php返回给用户)
...
大概去掉65-68行#,修改70行
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000; //将请求转发给本机9000端口,PHP解释器
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fast cgi_script_name;
include fastcgi.conf;
}
...
#nginx -s reload
6,创建PHP页面,测试LNMP架构能否解析PHP页面
创建PHP测试页面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>
创建PHP测试页面,连接并查询MariaDB数据库。
#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 环境完工=========
----------------------------------------------------------------------------------
LNMP 安装包百度网盘 下载地址:
链接:https://pan.baidu.com/s/1FCTgmxN1Aw1YB8fGEdOv2A
提取码:1p9y
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
动态页面故障: