博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux - 配置php-fpm 以及 配置nginx支持php
阅读量:5256 次
发布时间:2019-06-14

本文共 11227 字,大约阅读时间需要 37 分钟。

配置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-fpmroot       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 wwwnobody     9679   9677  0 20:00 ?        00:00:00 php-fpm: pool wwwroot       9681   4092  0 20:01 pts/1    00:00:00 grep php-fpm

或者通过netstat查看

[root@localhost php7]# netstat -anpo | grep 9000tcp        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-fpmtcp        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 startStarting php-fpm  done[root@localhost php7]# service php-fpm stopGracefully shutting down php-fpm . done[root@localhost php7]# service php-fpm restartGracefully 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-fpmroot       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 nginxroot       9583      1  0 19:24 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnginx      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

422101-20180110140524519-39279248.png

[root@localhost php7]# service php-fpm stopGracefully shutting down php-fpm . done

关闭了php-fpm就会出现错误了。

422101-20180110140710832-2059556628.png

配置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行,支持pathinfolocation ~ \.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

转载于:https://www.cnblogs.com/jiqing9006/p/8258510.html

你可能感兴趣的文章
程序的静态链接,动态链接和装载 (补充)
查看>>
关于本博客说明
查看>>
线程androidAndroid ConditionVariable的用法
查看>>
转载:ASP.NET Core 在 JSON 文件中配置依赖注入
查看>>
socket初识
查看>>
磁盘测试工具
查看>>
代码变量、函数命名神奇网站
查看>>
redis cli命令
查看>>
Problem B: 占点游戏
查看>>
python常用模块之sys, os, random
查看>>
HDU 2548 A strange lift
查看>>
Linux服务器在外地,如何用eclipse连接hdfs
查看>>
react双组件传值和传参
查看>>
[Kaggle] Sentiment Analysis on Movie Reviews
查看>>
价值观
查看>>
mongodb命令----批量更改文档字段名
查看>>
使用 SharedPreferences 分类: Andro...
查看>>
TLA+(待续...)
查看>>
题解: [GXOI/GZOI2019]与或和
查看>>
MacOS copy图标shell脚本
查看>>