1.10企业实战 LNMP 高性能服务器
前言
FastCGI 是语言无关的 、可伸缩架构的CGI开放扩展 , 将 CGI 解释器进程保持在内存中 , 以此获得较高的性能 。 Fast CGI 是一 个协议,php-fpm实现了这个协议, php-fpm 的FastCGI 协议需要有进程池,php-fpm实现的FastCGI进程叫php-cgi,所以php-fpm其实是他自身的 FastCGI或php-cgi进程管理器,如图所示:
企业级LNMP (Nginx+PHP( FastCGI )+ MySQL ) 主流架构配置方法如下,分别安装 Nginx 、MYSQL、 PHP服务 , 步骤如下 :
( 1 ) Nginx 安装配置
#安装PCRE库支持
yum install pcre-devel pcre -y
#下载Nginx源码包
cd /usr/src wget -c http://nginx.org/download/nginx-1.16.0.tar.gz
#解压Nginx源码包
tar -xzf nginx-1.16.0.tar.gz
#进入解压目录,然后sed修改Nginx版本信息为JWS
cd nginx-1.16.0; sed -i -e 's/1.16.0//g' -e 's/nginx\//JWS/g' -e 's/"NGINX"/"JWS"/g' src/core/nginx.h
#预编译Nginx
useradd www;./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#.configure预编译成功后,执行make命令进行编译
make
#make执行成功后,执行make install 正式安装
make install
#至此Nginx WEB服务器安装完毕。
(2)MYSQL 安装配置
参见我的博客地址:
二进制安装https://editor.csdn.net/md/?articleId=106838120
源码编译安装https://editor.csdn.net/md/?articleId=107658011
(3)PHP 安装配置
php源码编译安装地址https://blog.csdn.net/weixin_42257277/article/details/107710870
(4)Nginx 配置文件配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root /usr/share/nginx/ html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
( 5 ) 测试 LNMP架构测试 ,创建 index.php 测试页面
<?php
#查看php版本模块等信息
phpinfo();
#测试php与数据库的链接
#php5.0开始就不推荐使用mysql_connect()函数,php7.0则直接舍弃了,替代函数为mysqli_connect()
$link=mysql_connect('192.168.2.204','zabbix','123456');
if($link) echo "<h1>Success!!</h1>"; #显示Success表示连接数据成功
else echo "Fail!!";
mysql_close();
?>