Linux - 配置php-fpm 以及 配置nginx支持php
配置php-fpm
[root@localhost php7]# which php-fpm
/usr/local/php7/sbin/php-fpm
[root@localhost php7]# php-fpm
[09-Jan-2018 19:52:28] ERROR: failed to open configuration file '/usr/local/php7/etc/php-fpm.conf': No such file or directory (2)
[09-Jan-2018 19:52:28] ERROR: failed to load configuration file '/usr/local/php7/etc/php-fpm.conf'
[09-Jan-2018 19:52:28] ERROR: FPM initialization failed
[root@localhost php7]# find / -name 'php-fpm.conf.default'
/usr/local/php7/etc/php-fpm.conf.default
[root@localhost php7]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php7]# php-fpm
[09-Jan-2018 19:58:27] WARNING: Nothing matches the include pattern '/usr/local/php7/etc/php-fpm.d/*.conf' from /usr/local/php7/etc/php-fpm.conf at line 125.
[09-Jan-2018 19:58:27] ERROR: No pool defined. at least one pool section must be specified in config file
[09-Jan-2018 19:58:27] ERROR: failed to post process the configuration
[09-Jan-2018 19:58:27] ERROR: FPM initialization failed
[root@localhost php7]# ll /usr/local/php7/etc/php-fpm.d/
total 20
-rw-r--r--. 1 root root 18521 Dec 28 22:13 www.conf.default
[root@localhost php7]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost php7]# php-fpm
启动php-fpm成功!
[root@localhost php7]# ps -ef | grep php-fpm
root 9677 1 0 20:00 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 9678 9677 0 20:00 ? 00:00:00 php-fpm: pool www
nobody 9679 9677 0 20:00 ? 00:00:00 php-fpm: pool www
root 9681 4092 0 20:01 pts/1 00:00:00 grep php-fpm
或者通过netstat查看
[root@localhost php7]# netstat -anpo | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 9677/php-fpm off (0.00/0/0)
[root@localhost php7]# netstat -anpo | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 9677/php-fpm off (0.00/0/0)
unix 3 [ ] STREAM CONNECTED 232696 9677/php-fpm
unix 3 [ ] STREAM CONNECTED 232695 9677/php-fpm
配置 php-fpm 服务
[root@localhost php7]# cp /usr/local/src/php-7.1.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php7]# chmod a+x /etc/init.d/php-fpm
[root@localhost php7]# service php-fpm start
Starting php-fpm done
[root@localhost php7]# service php-fpm stop
Gracefully shutting down php-fpm . done
[root@localhost php7]# service php-fpm restart
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?
Starting php-fpm done
[root@localhost php7]# ps -ef | grep php-fpm
root 9825 1 0 21:33 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 9826 9825 0 21:33 ? 00:00:00 php-fpm: pool www
nobody 9827 9825 0 21:33 ? 00:00:00 php-fpm: pool www
root 9829 4092 0 21:33 pts/1 00:00:00 grep php-fpm
配置nginx支持php
[root@localhost ~]# useradd nginx -s /sbin/nologin -M
[root@localhost php7]# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; # 指定Nginx服务的用户和用户组
[root@localhost php7]# nginx -s reload
[root@localhost php7]# ps -ef | grep nginx
root 9583 1 0 19:24 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 9862 9583 0 21:49 ? 00:00:00 nginx: worker process
root 9866 4092 0 21:50 pts/1 00:00:00 grep nginx
这个时候用户就编程nginx了。
继续修改其他配置。
#user nobody;
user nginx nginx; # 指定Nginx服务的用户和用户组
worker_processes auto;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
server_tokens off;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
send_timeout 30;
gzip on;
server {
listen 80;
server_name localhost;
charset UTF-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/webroot;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/webroot;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/webroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/webroot/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
[root@localhost php7]# mkdir /var/webroot
[root@localhost php7]# vim /var/webroot/index.php
[root@localhost php7]# nginx -s reload
[root@localhost php7]# service php-fpm stop
Gracefully shutting down php-fpm . done
关闭了php-fpm就会出现错误了。
配置rewrite
#user nobody;
user nginx nginx; # 指定Nginx服务的用户和用户组
worker_processes auto;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
server_tokens off;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
send_timeout 30;
gzip on;
server {
listen 80;
server_name localhost;
charset UTF-8;
#charset koi8-r;
#access_log logs/host.access.log main;
set $root /var/webroot/tp5admin;
location / {
root $root;
index index.php index.html index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/webroot;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .+\.php($|/) {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 81;
server_name localhost:81;
set $root /var/webroot;
location / {
root $root;
index index.php index.html index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/webroot;
}
location ~ .+\.php($|/) {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
燕十八的方案
# 典型配置
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
include fastcgi_params;
}
# 修改第1,6行,支持pathinfo
location ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
fastcgi_param PATH_INFO $1; # 把pathinfo部分赋给PATH_INFO变量
include fastcgi_params;
}
如果遇到session无法启用的问题,就赋予权限。
[root@localhost var]# chmod 777 -R tmp
[root@localhost var]# chown -R root:root /var/tmp/sessions
Linux - 配置php-fpm 以及 配置nginx支持php的更多相关文章
- 高性能web服务器(热死你)Resin Linux的安装、配置、部署,性能远超Nginx支持Java、PHP等
高性能web服务器(热死你)Resin Linux的安装.配置.部署,性能远超Nginx支持Java.PHP等 一. 安装resin 1. 下载resin: 下载地址:http://cauch ...
- Linux下安装php环境并且配置Nginx支持php-fpm模块[www]
Linux下安装php环境并且配置Nginx支持php-fpm模块 http://www.cnblogs.com/freeweb/p/5425554.html 5分钟搭建 nginx +php --- ...
- LNMP搭建04 -- 配置Nginx支持PHP
首先建立存放网页文件的目录,执行 mkdri /usr/local/server/www 然后进入到该目录中 cd /usr/local/server/www 然后创建一个测试文件: phpinfo ...
- nginx在linux上的安装与配置详解(一)
Nginx的安装与配置详解 (1)nginx简介 nginx概念: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like ...
- Ubuntu下安装LNMP之php7的安装并配置Nginx支持php及卸载php
据了解,php7是比之前的版本性能快很多的.http://php.net/get/php-7.2.2.tar.gz/from/a/mirror 安装前也可提前将相关依赖库安装好,或者在安装php时若安 ...
- 配置Nginx支持SSL SNI(一个IP绑定多个证书) 以及Haproxy实现多域名证书
概述 传统的每个SSL证书签发,每个证书都需要独立ip,假如你编译openssl和nginx时候开启TLS SNI (Server Name Identification) 支持,这样你可以安装多个S ...
- centos6.5配置uwsgi与nginx支持django
一.centos中升级python 1. > wget https://www.python.org/ftp/python/3.5.4/Python-3.5.4.tgz # https://ww ...
- Nginx 在 Linux 上的安装和配置
一.Nginx的安装 1.单台Nginx的安装 Nginx在Linux上的安装可以参考这篇博客:http://blog.csdn.net/molingduzun123/article/details/ ...
- 已安装nginx支持https配置 the "ssl" parameter requires ngx_http_ssl_module
原文链接:https://blog.seosiwei.com/detail/28 nginx已安装,ssl模块未安装的解决方法: 如果需要在linux中编译自己的nginx服务器,请参照:https: ...
随机推荐
- 闲谈Spring-IOC容器
闲聊 无论是做j2ee开发还是做j2se开发,spring都是一把大刀.当下流行的ssh三大框架中,spring是最不可替代的,如果不用hibernate和struts,我觉得都无关紧要,但是不能没有 ...
- 《CSS Mastery》读书笔记(3)
第三章 可视化格式模型 三个最重要的CSS概念需要掌握,浮动floating,定位positioning, 框模型(有些书翻译成盒子模型)box model. 这些概念控制了元素在页面中的安放和显示. ...
- scrollWidth clientWidth offsetWidth
scrollWidth:对象的实际内容的宽度,不包边线宽度,会随对象中内容超过可视区后而变大. 实际内容+padding 不包括滚动条 边框client ...
- 大型工程多个目录下的Makefile写法
1.前言 目前从事于linux下程序开发,涉及到多个文件,多个目录,这时候编译文件的任务量比较大,需要写Makefile.关于Makefile的详细内容可以参考网上流传非常广泛的<跟我一起写Ma ...
- Arduino DS18B20温度检测
一.实物图 注:电阻选取4.7k欧 二.事例代码 注:先下载Onewire库到arduino libraries目录下,然后就有例子 #include <OneWire.h> // One ...
- BZOJ 1864: [Zjoi2006]三色二叉树 树形DP + 读入
Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. 题解:本题大水 ...
- SPLAY or SPALY ?
写在前面: 由我们可爱的Daniel Sleator和Robert Tarjan提出的一种数据结构,平衡树的一种,本质是二叉树. 至于到底是splay还是spaly,我认为可能splay更对一些 毕竟 ...
- eas之添加表格列宽自动调整设置
设置表格整体宽度自动调整为所在panel的宽度 KDTable table=new KDTable(); table. setAutoResize (boolean); 注意:该功能在冻结功能启用后, ...
- 【剑指Offer】40、数组中只出现一次的数字
题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字.要求时间复杂度为O(n),空间复杂度为O(1). 解题思路: 这道题目相对比较难 ...
- 终于等到你!微软正式上线 Windows Terminal 预览版
前一段时间,一直在知乎.技术社区收到技术小伙伴们的终极拷问:微软Build 大会上提到的**6月中旬**要上Windows store 的 Windows Terminal 到底啥时候可以用到呀? 有 ...