php fpm出错的解决办法:1、在nginx的目录中创建个php的检测脚本index.php;2、找到nginx加载php配置的部分;3、修改路径即可。
本文操作环境:linux5.9.8系统、PHP5.5版、Dell G3电脑。
如何解决php fpm出错问题?
nginx调用php-fpm出错解决方法和nginx配置详解
这篇文章介绍了nginx调用php-fpm出错的解决方法,最后给出了nginx配置方法,需要的朋友可以参考下
装完了nginx和php-5.5,配置好了nginx调用php后,就开始启动php-fpm。
使用下面的命令
代码如下:
/usr/local/php/sbin/php-fpm
就可以启动了。
在nginx的目录中创建个php的检测脚本index.php
结果在打开http://localhost/index.php
悲剧的发现居然无法打开 。查看日志文件,看了下报错原因
代码如下:
2013/07/01 22:34:26 [error] 3214#0: *64 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.168.19, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.168.140"
查看下端口 。看到php-fpm的9000端口已经打开了,说明php-fpm是没什么问题的,问题出在了nginx上了。可能是我的配置文件有问题。
找到nginx加载php配置的那块。另外参考了下网上nginx的配置文件。
在第69行有一个调用脚本路径
代码如下:
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
我把路径改下,改成下面的就可以了。
代码如下:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; http://localhost/index.php
可以出现php的版本信息了。
大家还可以参考下面的配置方法
php-fpm不用再依赖其它的fastcgi启动器,比如lighttpd的spawn-fcgi。
php-fpm的使用非常方便,配置都是在php-fpm.ini的文件内
而启动,重启都可以从php/sbin/php-fpm中进行
更方便的是修改php.ini后可以直接使用php-fpm reload进行加载 无需杀掉进程就可以完成php.ini的修改加载
结果显示使用php-fpm可以使php有不小的性能提升
php-fpm控制的进程.cpu回收的速度比较慢.内存分配的很均匀
而spawn-cgi控制的进程CPU下降的很快.而内存分配的比较不均匀.
有很多进程似乎未分配到,而另外一些却占用很高.
可能是由于进程任务分配的不均匀导致的.而这也导致了总体响应速度的下降
而php-fpm合理的分配.导致总体响应的提到以及任务的平均
使用php-fpm需要在php源码上打补丁,然后重新编译php
一.下载php-fpm
wget http://cn.php.net/get/php-5.2.8.tar.gz/from/www.php.net/mirror wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz
与php-5.2.9在同一级目录
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1
补丁打好以后,编译php的时候增加了下面几个参数:
–enable-fpm 激活fastcgi模式的fpm支持
–with-fpm-conf php-fpm的配置文件(默认是PREFIX/etc/php-fpm.conf)
–with-fpm-log php-fpm的日志文件(默认是PREFIX/logs/php-fpm.log)
–with-fpm-pid php-fpm的pid文件(默认是PREFIX/logs/php-fpm.pid) ./configure --prefix=/EBS/php \ --with-config-file-path=/EBS/php/etc \ --enable-fastcgi \ --enable-fpm \ --OTHERS
注:--enable-fastcgi \ 需要在--enable-fpm \的前面,否则,fpm不能编译上。
二.编译好php后,修改配置文件
vi /EBS/php/etc/php-fpm.conf
需要注意下面几处配置
<value name="listen_address">127.0.0.1:9000</value>
这个表示php的fastcgi进程监听的ip地址以及端口
<value name="user">nobody</value> <value name="group">nobody</value>
表示php的fastcgi进程以什么用户以及用户组来运行,默认该行是注释掉的,需要打开
<value name="display_errors">0</value>
是否显示php错误信息
<value name="max_children">5</value>
最大的子进程数目
运行php-fpm:
php-fpm用一个程序来控制fastcgi进程,这个文件在$PREFIX/sbin/php-fpm
/usr/local/php/sbin/php-fpm
该程序有如下参数:
start 启动php的fastcgi进程
stop 强制终止php的fastcgi进程
quit 平滑终止php的fastcgi进程
restart 重启php的fastcgi进程
reload 重新加载php的php.ini
logrotate 重新启用log文件
也就是说,在修改了php.ini之后,我们可以使用
/usr/local/php/sbin/php-fpm reload
这样,就保持了在php的fastcgi进程持续运行的状态下,又重新加载了php.ini。
代码如下:
user www www; worker_processes 10; error_log logs/error.log notice; pid logs/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; charset gb2312; server_names_hash_bucket_size 128; #sendfile on; #tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/html application/xml; { listen 80; server_name 192.168.1.2; index index.html index.htm index.php; root /EBS/www; if (-d $request_filename) { rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; } location ~ .*\.php?$ { include fcgi.conf fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; } log_format access '$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 access; } }
新建配置文件
代码如下:
/usr/local/nginx/conf/fcgi.conf
注:nginx自带了一个配置文件,/usr/local/nginx/conf/fastcgi_params,该配置文件缺少粗体字体的部分,会造成访问php文件时报404错误。
复制代码代码如下:
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect #fastcgi_param REDIRECT_STATUS 200;
四 配置XCache
1、安装xcache模块
wgethttp://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz tar -xvzf xcache-1.2.2.tar.gz cd xcache-1.2.2 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache --enable-xcache-optimizer make make install
2、计算密码的md5值
echo -n "password"|md5sum 5f4dcc3b5aa765d61d8327deb882cf99
3、配置XCache
;注:zend_extension,用来加载zend的扩展,是绝对路径, extension是相对路径,相对于extension_dir的相对路径,非zend扩展
如果你更改路径以后,一定要apachectl stop后再start,而不要restart。
vi /usr/local/php/etc/php.ini
添加:
代码如下:
[xcache-common] zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so [xcache.admin] ; Change xcache.admin.user to your preferred login name xcache.admin.user = "admin" ; Change xcache.admin.pass to the MD5 fingerprint of your password ; Use md5 -s "your_secret_password" to find the fingerprint xcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99" [xcache] ; Change xcache.size to tune the size of the opcode cache xcache.size = 24M xcache.shm_scheme = "mmap" xcache.count = 2 xcache.slots = 8K xcache.ttl = 0 xcache.gc_interval = 0 ; Change xcache.var_size to adjust the size of variable cache xcache.var_size = 8M xcache.var_count = 1 xcache.var_slots = 8K xcache.var_ttl = 0 xcache.var_maxttl = 0 xcache.var_gc_interval = 300 xcache.test = Off xcache.readonly_protection = On xcache.mmap_path = "/tmp/xcache" xcache.coredump_directory = "" xcache.cacher = On xcache.stat = On xcache.optimizer = Off [xcache.coverager] xcache.coverager = On xcache.coveragedump_directory = ""
5、重启PHP模块
正常load之后,
在phpinfo显出的信息内
Zend这快应该会加上XCache的内容
6、另外两种加速模块:
在我们的测试中,效果都要好于xcache,这3中加速不能同时存在两种,有冲突。
6.1 apc
代码如下:
wget http://pecl.php.net/get/APC-3.0.19.tgz cd APC-3.0.19 /usr/local/php/bin/phpize ./configure --enable-apc --enable-apc-mmap --with-apxs=/EBS/apache/bin/apxs --with-php-config=/EBS/php/bin/php-config make make install 6.2 eaccelerator wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zip cd eaccelerator-0.9.5.3 /usr/local/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/EBS/php/bin/php-config make make install vi php.ini zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9"
五、使用nginx对应多台facgi服务器
想法:前端一台nginx,用於做為負載平衡和處理靜態頁面。利用nginx的upstream模組將php請求分發到後段的php-fpm伺服器上。
後端多台php-fpm的伺服器,只起php-fpm服務來處理php。
這樣做減少了php-fpm上的nginx服務,相當於少了一層。
推薦學習:《PHP影片教學》
以上是如何解決php fpm出錯問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文比較了酸和基本數據庫模型,詳細介紹了它們的特徵和適當的用例。酸優先確定數據完整性和一致性,適合財務和電子商務應用程序,而基礎則側重於可用性和

本文討論了確保PHP文件上傳的確保,以防止諸如代碼注入之類的漏洞。它專注於文件類型驗證,安全存儲和錯誤處理以增強應用程序安全性。

本文討論了在PHP中實施API速率限制的策略,包括諸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之類的庫。它還涵蓋監視,動態調整速率限制和手

本文討論了使用password_hash和pyspasswify在PHP中使用密碼的好處。主要論點是,這些功能通過自動鹽,強大的哈希算法和SECH來增強密碼保護

本文討論了OWASP在PHP和緩解策略中的十大漏洞。關鍵問題包括注射,驗證損壞和XSS,並提供用於監視和保護PHP應用程序的推薦工具。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!