LNMP部署、构建

一,部署、构建LNMP

  • 安装部署Nginx、MariaDB、PHP、PHP-FPM;

LNMP部署、构建_第1张图片

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

LNMP部署、构建_第2张图片

  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

LNMP部署、构建_第3张图片

  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  //最多允许几个进程处于空闲状态

LNMP部署、构建_第4张图片

LNMP部署、构建_第5张图片

LNMP部署、构建_第6张图片LNMP部署、构建_第7张图片LNMP部署、构建_第8张图片LNMP部署、构建_第9张图片LNMP部署、构建_第10张图片

 

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;
       }
...

LNMP部署、构建_第11张图片

#nginx -s reload

  
  6,创建PHP页面,测试LNMP架构能否解析PHP页面
  创建PHP测试页面1,/usr/local/nginx/html/test01.php
#vim /usr/local/nginx/html/test01.php


This is HTML message


$c = 12;
$d = 2;
if($c > $d){echo "c is bigger";}
else{ echo "d is bigger";}
?>

LNMP部署、构建_第12张图片

 

创建PHP测试页面,连接并查询MariaDB数据库。
#vim /usr/local/nginx/html/test02.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("
");
        printf("Name:%s",$row[1]);
        printf("
");
}
?>

LNMP部署、构建_第13张图片LNMP部署、构建_第14张图片


   7,客户端访问
#firefox http://201.1.2.100/test02.php
#firefox http://201.1.2.100/test01.php
===============lnmp 环境完工=========

LNMP部署、构建_第15张图片

----------------------------------------------------------------------------------

LNMP 安装包百度网盘  下载地址:

链接:https://pan.baidu.com/s/1FCTgmxN1Aw1YB8fGEdOv2A 
提取码:1p9y 
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

动态页面故障:

LNMP部署、构建_第16张图片LNMP部署、构建_第17张图片

 

你可能感兴趣的:(#,#,运维-nginx)