Centos7-yum部署配置LNMP+php-fgm,一台机器上部署
一、简介
1、了解nginx特性
请参考,https://www.cnblogs.com/zhangxingeng/p/10150955.html
2、LNMP:linux+nginx+mysql+php
3、什么是php-fpm
先提一下fastCGI,可以将http服务器和脚本解析服务器分开,同时再脚本解析服务器上启动一个或多个脚本解析守护进程,http遇到动态请求就交给fastCGI处理。
php-fpm即php-Fastcgi Process Manager,php-fpm是 FastCGI 的实现,并提供了进程管理的功能。进程包含 master 进程和 worker 进程两种进程。master 进程只有一个,负责监听端口,接收来自 Web Server 的请求,而 worker 进程则一般有多个(具体数量根据实际需要配置),每个进程内部都嵌入了一个 PHP 解释器,是 PHP 代码真正执行的地方。
4、nginx和php-fpm有两种通信方式:
tcp socket和unix socket。tcp socket可以跨主机配置nginx+php-fpm,unix socket是同一主机进程间通信的一种方式,数据的进出都是在内核中进行,效率比tcp socket高,要求php-fpm开启sock监听,且不能跨主机配置nginx+php-fpm。因此,如果nginx+php-fpm在同一主机上是,建议使用unix socket的连接通信方式。之后测试非同一主机的实验。
5、测试环境
测试部署同一台主机
[root@web1 html]# rpm -qa php-fpm
php-fpm-5.4.-.el7.x86_64
[root@web1 html]# rpm -qa php
php-5.4.-.el7.x86_64
[root@web1 html]# rpm -qa nginx
nginx-1.12.-.el7.x86_64
[root@web1 html]# cat /etc/centos-release
CentOS Linux release 7.3. (Core)
[root@web1 html]# rpm -qa maraidb
[root@web1 html]# rpm -qa mariadb
mariadb-5.5.-.el7_5.x86_64
[root@web1 html]#
5、架构原理

6、nginx+php-fpm原理,c/s架构
nginx本身不会对php进行解析,php页面得请求nginx将交给fastCGI进程监听(ip+端口)或(unix sock)由php-fpm作为动态解析服务器处理后返给nginx,其实现在看到nginx就是个反代,nginx通过反向代理功能将动态请求转像php-fpm,实现了对php解析得支持。
wrapper,fastCGI用于启动一个程序的程序,这个wrapper绑定在某个固定socket上,如果端口或者文件socket,当nginx将CGI请求发送给这个socket的时候,通过fastCGI接口,wrapper接受到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取饭后数据;接着,wrapper再将饭后的数据通过fastCGI接口,沿着固定的socket传递给nginx,最后,nginx将返回的数据发送给客户端。
二、开始yum部署
#准备好源,我这里已经准备好epel源
#关闭selinux
#关闭firewall
1、安装nginx
yum install nginx -y
启动nginx,并设置开机自启
[root@web1 ~]# systemctl start nginx #启动
[root@web1 ~]# systemctl enable nginx #开机启动
[root@web1 ~]# netstat -untlp |grep 80 #查看监听端口
tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master
tcp6 ::: :::* LISTEN /nginx: master
1#查看版本
[root@web1 ~]# rpm -qa nginx
nginx-1.12.-.el7.x86_64
查看一下效果

2、安装php
yum install -y php php-devel php-fpm php-mysql php-common php-devel php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel
3、开启php-fpm
[root@web1 ~]# systemctl start php-fpm
[root@web1 ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
4、安装数据库,这里安装mariadb,和依赖
yum install mariadb mariadb-server mariadb-libs mariadb-devel
[root@web1 ~]# systemctl start mariadb
[root@web1 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
4 [root@web1 ~]# netstat -untlp |grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25117/mysqld
[root@web1 ~]#
三、配置
1、nginx与php-fpm交互这里使用unix socket
vim /etc/php-fpm.d/www.conf
listen = /dev/shm/php-cgi.sock
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
2、创建nginx服务器location,站点配置文件
vim /etc/nginx/conf.d/default.conf
server{
listen ; #监听81端口
#server_name default.com www.default.com; #绑定域名 default.com 和 www.default.com
server_name 192.168.216.239;
index index.html index.htm index.php; #设置首页文件,越前优先级越高
charset utf-; #设置网页编码
root /usr/share/nginx/html; #设置站点根目录
#运行 PHP
location ~ .*\.php$
{
# fastcgi_pass 127.0.0.1: #默认使用9000端口和PHP通信
fastcgi_pass unix:/dev/shm/php-fpm.sock; #使用 unix sock 和PHP通信,需要和php-fpm配置文件一致
fastcgi_index index.php;
#fastcgi_param DOCUMENT_ROOT /usr/share/nginx/html; #PHP 文档根目录
17 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #PHP 脚本目录
include fastcgi_params;
try_files $uri = ;
}
#设置文件过期时间
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
{
expires 30d;
}
#设置文件过期时间
location ~ .*\.(js|css)$
{
expires 12h;
}
#设置文件访问权限
#location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ {
#allow 127.0.0.1;
#deny all;
#}
#设置文件访问权限
#location ~* \.(ftpquota|htaccess|htpasswd|asp|aspx|jsp|asa|mdb)?$ {
#deny all;
#}
#保存日志
#access_log /var/log/nginx/default-access.log main;
#error_log /var/log/nginx/default-error.log crit;
}
说明
这里的路径是/dev/shm,这是将内存化为虚拟磁盘用的,效率比磁盘速度高得多,这里测试使用内存为虚拟磁盘得unix socket
运行一下看看效果,不出意外应该包502 bad gateway得错误或者设置了error_page 会出现下面如图得error
# location / {
# root /usr/share/nginx/html;
# index index.php index.html index.htm;
# }
# error_page /.html;
# error_page 505 502 503 504 /50x.html;
# location = /50x.html {
# root /usr/share/nginx/html;
# }

这个错误是配置得时候范了个小错误,难免有瑕疵,请看
vim /etc/nginx/conf.d/default.conf
fastcgi_pass unix:/dev/shm/php-fpm.sock;
纠正过来我们重启nginx和php-fpm,在访问一下看看,没问题,成功了

3、修改php.ini的配置
#测试可以不改
vim /etc/php.ini
cgi.fix_pathinfo=1 #将注释去掉,开启PHP的pathinfo伪静态功能。
max_execution_time = 0 #脚本运行的最长时间,默认30秒
max_input_time = 300#脚本可以消耗的时间,默认60秒
memory_limit = 256M#脚本运行最大消耗的内存,根据你的需求更改数值,默认128M
post_max_size = 100M #单提交的最大数据,此项不是限制上传单个文件的大小,而是针对整个表单的提交数据进行限制的。限制范围包括表单提交的所有内容.例如:发表贴子时,贴子标题,内容,附件等…默认8M
upload_max_filesize = 10M#上载文件的最大许可大小 ,默认2M
4、测试mysql
需要新建一个index.php来测试,我们备份,然后新建
cd /usr/share/nginx/html
mv index.php index.php.backup
vim /usr/share/nginx/html/index.php
[root@web1 html]# vim index.php <?php
$conn = mysql_connect('192.168.216.239','test','111111');
if ($conn)
echo succ;
else
echo fail;
mysql_close()
?>
还需要创建root密码,并创建可以远程登陆得test用户
mysql -uroot -p
MariaDB [(none)]> set password for root@localhost = password('');
MariaDB [(none)]> create user 'test'@'%' identified by'';
MariaDB [(none)]> flush privileges;
见证一下

转载请注明出处:https://www.cnblogs.com/zhangxingeng/p/10242902.html
Centos7-yum部署配置LNMP+php-fgm,一台机器上部署的更多相关文章
- 如何在一台机器上部署多个tomcat
1,在/usr/local/下部署两个tomcat7. 2,修改/etc/profile文件,加入下面内容 vi /etc/profile export JAVA_HOME=/usr/java/jd ...
- centos7 yum安装配置redis 并设置密码
原文:https://www.cnblogs.com/fanlinglong/p/6635828.html centos7 yum安装配置redis 并设置密码 1.设置Redis的仓库地址 yum ...
- 在ubuntu机器上部署php测试环境
在ubuntu机器上部署php测试环境 一.部署环境 Ubuntu11.10_X86_32,编译安装相应的软件:nginx+mysql+php. 二.软件安装 2.1 软件下载 libiconv-1. ...
- linux机器上部署多台Tomcat
在Linux机器上部署多台Tomcat, 我部署的是Tomcat8,只需要一步,即避免端口号冲突. 在解压后的tomcat目录下,修改conf下server.xml. 修改shutdown端口: &l ...
- Git 在同一台机器上配置多个Git帐号
在同一台机器上配置多个Git帐号 By:授客 QQ:1033553122 实践环境 win10 Git-2.21.0-64-bit.exe TortoiseGit-2.8.0.0-64bit.msi ...
- 大数据学习day17------第三阶段-----scala05------1.Akka RPC通信案例改造和部署在多台机器上 2. 柯里化方法 3. 隐式转换 4 scala的泛型
1.Akka RPC通信案例改造和部署在多台机器上 1.1 Akka RPC通信案例的改造(主要是把一些参数不写是) Master package com._51doit.akka.rpc impo ...
- Linux的CentOS7系统下配置LNMP
友情提示:在执行以下操作之前,请确保您已经安装了centos7,因为以下所有操作均是在centos7下操作完成的. 1.首先要停掉本机自带的防火墙,再配置iptables,开放21/22/80/808 ...
- CentOS 6.5 yum安装配置lnmp服务器(Nginx+PHP+MySQL)
以下全部转载于 http://blog.csdn.net/lane_l/article/details/20235909 本人于今晚按照该文章使用centos 6.7 64bit安装成功,做个备份, ...
- CentOS7 yum安装配置
一.安装必要包 yum install gcc 二.linux下安装 #下载 wget http://download.redis.io/releases/redis-3.0.0.tar.gz tar ...
随机推荐
- C#中添加log4net(日志文件)
1.先下载引用“log4net” 2.然后再App.config配置 3.添加一个LogHandler类 4.在Assemblyinfo类中添加配置的读取文件 5.运用日志文件 6.显示结果
- Mac_mac下使用ll等指令
Linux有ll等命令,切换到MAC下这些指令是没有的 其实就是别名,用ls -alF也能做到 添加方法: vim ~/.bash_profile 输入一下内容 alias ll='ls -alF'a ...
- jieba库与好玩的词云的学习与应用实现
经过了一些学习与一些十分有意义的锻(zhe)炼(mo),我决定尝试一手新接触的python第三方库 ——jieba库! 这是一个极其优秀且强大的第三方库,可以对一个文本文件的所有内容进行识别,分词,甚 ...
- python获取多线程的返回值
import threading class MyThread(threading.Thread): def __init__(self,func,args=()): super(MyThread,s ...
- win10企业版永久激活方法
步骤: 1.右键点击桌面左下角"windows"图标,点击打开“命令提示符” 2.复制命令:slmgr.vbs /upk,按回车确定,弹出窗口显示“成功地卸载了产品密钥” 3.复制 ...
- 编译的时候出现 usr/bin/ld: cannot find -lxxx 的错误
比如错误为: usr/bin/ld: cannot find -labc 首先要明白的是 labc 代表的是 libabc.so 明白了这个之后,我们就知道了问题是:在编译的过程中,需要 libabc ...
- vue-router路径计算问题
简书原文 昨天刚刚发表了一个前端跨域新方案尝试,今天在开发中就遇到的了问题. 起因 前端使用的是vue-router组件的history模式,但是由于我们的整个页面都是从static(静态资源站)lo ...
- Pycharm中配置鼠标悬停快速提示方法参数
第一步: 第二步: 演示:
- [Swift]LeetCode448. 找到所有数组中消失的数字 | Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- [Swift]LeetCode620. 有趣的电影 | Not Boring Movies
SQL架构 Create table If Not Exists cinema (id ), description varchar(), rating , )) Truncate table cin ...