Linux|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
root967710 20:00 ?00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody967896770 20:00 ?00:00:00 php-fpm: pool www
nobody967996770 20:00 ?00:00:00 php-fpm: pool www
root968140920 20:01 pts/100:00:00 grep php-fpm
或者通过netstat查看
[root@localhost php7]# netstat -anpo | grep 9000
tcp00 127.0.0.1:90000.0.0.0:*LISTEN9677/php-fpmoff (0.00/0/0)
[root@localhost php7]# netstat -anpo | grep php-fpm
tcp00 127.0.0.1:90000.0.0.0:*LISTEN9677/php-fpmoff (0.00/0/0)
unix3[ ]STREAMCONNECTED232696 9677/php-fpm
unix3[ ]STREAMCONNECTED232695 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-fpmdone
[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-fpmdone
[root@localhost php7]# ps -ef | grep php-fpm
root982510 21:33 ?00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody982698250 21:33 ?00:00:00 php-fpm: pool www
nobody982798250 21:33 ?00:00:00 php-fpm: pool www
root982940920 21:33 pts/100: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
root958310 19:24 ?00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx986295830 21:49 ?00:00:00 nginx: worker process
root986640920 21:50 pts/100:00:00 grep nginx
这个时候用户就编程nginx了。
继续修改其他配置。
#usernobody;
user nginx nginx;
# 指定Nginx服务的用户和用户组
worker_processes auto;
error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
pidlogs/nginx.pid;
events {
worker_connections1024;
}http {
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
#'$status $body_bytes_sent "$http_referer" '
#'"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
server_tokens off;
sendfileon;
#tcp_nopushon;
tcp_nodelay on;
#keepalive_timeout0;
keepalive_timeout65;
send_timeout 30;
gzipon;
server {
listen80;
server_namelocalhost;
charset UTF-8;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
root/var/webroot;
indexindex.php index.html index.htm;
}#error_page404/404.html;
# redirect server error pages to the static page /50x.html
#
error_page500 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_passhttp://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root/var/webroot;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/var/webroot/$fastcgi_script_name;
includefastcgi_params;
}# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#denyall;
#}
}# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#listen8000;
#listensomename:8080;
#server_namesomenamealiasanother.alias;
#location / {
#roothtml;
#indexindex.html index.htm;
#}
#}# HTTPS server
#
#server {
#listen443 ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location / {
#roothtml;
#indexindex.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
#usernobody;
user nginx nginx;
# 指定Nginx服务的用户和用户组
worker_processes auto;
error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
pidlogs/nginx.pid;
events {
worker_connections1024;
}http {
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
#'$status $body_bytes_sent "$http_referer" '
#'"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
server_tokens off;
sendfileon;
#tcp_nopushon;
tcp_nodelay on;
#keepalive_timeout0;
keepalive_timeout65;
send_timeout 30;
gzipon;
server {
listen80;
server_namelocalhost;
charset UTF-8;
#charset koi8-r;
#access_loglogs/host.access.logmain;
set $root /var/webroot/tp5admin;
location / {
root$root;
indexindex.php index.html index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}#error_page404/404.html;
# redirect server error pages to the static page /50x.html
#
error_page500 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_passhttp://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .+\.php($|/) {
root$root;
fastcgi_pass127.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_paramSCRIPT_FILENAME$root$fastcgi_script_name;
includefastcgi_params;
}# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#denyall;
#}
}# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen81;
server_namelocalhost:81;
set $root /var/webroot;
location / {
root$root;
indexindex.php index.html index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
error_page500 502 503 504/50x.html;
location = /50x.html {
root/var/webroot;
}location ~ .+\.php($|/) {
root$root;
fastcgi_pass127.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_paramSCRIPT_FILENAME$root$fastcgi_script_name;
includefastcgi_params;
}}# HTTPS server
#
#server {
#listen443 ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location / {
#roothtml;
#indexindex.html index.htm;
#}
#}}
燕十八的方案
# 典型配置
location ~ \.php$ {
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$DOCUMENT_ROOT$fastcgi_script_name;
includefastcgi_params;
}# 修改第1,6行,支持pathinfolocation ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分
root html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$DOCUMENT_ROOT$fastcgi_script_name;
fastcgi_param PATH_INFO $1;
# 把pathinfo部分赋给PATH_INFO变量
includefastcgi_params;
}
如果遇到session无法启用的问题,就赋予权限。
[root@localhost var]# chmod 777 -R tmp
[root@localhost var]# chown -R root:root /var/tmp/sessions
【Linux|Linux - 配置php-fpm 以及 配置nginx支持php】转载于:https://www.cnblogs.com/jiqing9006/p/8258510.html
推荐阅读
- vue-cli|vue-cli 3.x vue.config.js 配置
- Linux下面如何查看tomcat已经使用多少线程
- CGI,FastCGI,PHP-CGI与PHP-FPM
- Beego打包部署到Linux
- 从战略性的角度可以配置股票
- Linux|109 个实用 shell 脚本
- linux定时任务contab
- 缓存有关的配置和属性
- 芯灵思SinlinxA33开发板Linux内核定时器编程
- Spring|Spring Boot 自动配置的原理、核心注解以及利用自动配置实现了自定义 Starter 组件