Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of php fpm error

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to solve the problem of php fpm error". In daily operation, I believe many people have doubts about how to solve the problem of php fpm error. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to solve the problem of php fpm error"! Next, please follow the editor to study!

Solutions to php fpm errors: 1, create a php detection script index.php;2 in the nginx directory, find the part where nginx loads the php configuration; 3, modify the path.

This article operating environment: linux5.9.8 system, PHP5.5 version, Dell G3 computer.

How to solve the problem of php fpm error?

Nginx call php-fpm error resolution and nginx configuration details

This article introduces the solution to the error of nginx calling php-fpm, and finally gives the method of nginx configuration, which can be referred to by friends who need it.

After nginx and php-5.5 are installed, and nginx is configured to call php, start php-fpm.

Use the following command

The code is as follows:

/ usr/local/php/sbin/php-fpm

It's ready to start.

Create a php detection script index.php in the directory of nginx

As a result, http://localhost/index.php is opened.

The tragic discovery can't be opened. Check the log file to see the reason for the error.

The code is as follows:

22:34:26 on 2013-07-01 [error] 321440: * 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"

Check the port. Seeing that port 9000 of php-fpm has been opened, it shows that there is nothing wrong with php-fpm, but the problem lies in nginx. Maybe there's something wrong with my profile.

Find the piece where nginx loaded the php configuration. In addition, I refer to the configuration file of nginx on the Internet.

There is a path to invoke the script on line 69

The code is as follows:

Fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name

I'll just change the path to the one below.

The code is as follows:

Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; http://localhost/index.php

The version information of php can appear.

You can also refer to the following configuration method

Php-fpm no longer has to rely on other fastcgi initiators, such as lighttpd's spawn-fcgi.

Php-fpm is very convenient to use, and the configuration is all in the php-fpm.ini file.

Startup and restart can be carried out from php/sbin/php-fpm.

What is more convenient is that after modifying php.ini, you can directly use php-fpm reload to load without killing the process to complete the modified loading of php.ini.

The results show that the performance of php can be greatly improved by using php-fpm.

The process controlled by php-fpm. CPU recovery is relatively slow. The memory is allocated evenly.

On the other hand, the process controlled by spawn-cgi, CPU, drops rapidly. And the allocation of memory is relatively uneven.

Many processes seem to be unassigned, while others are highly occupied.

It may be due to the uneven distribution of process tasks. And this also leads to a decline in the overall response speed.

And the reasonable distribution of php-fpm. Leads to the mention of the overall response and the average of the task

Using php-fpm requires patching the php source code, and then recompiling php

one。 Download php-fpm

Wget http://cn.php.net/get/php-5.2.8.tar.gz/from/www.php.net/mirrorwget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz

At the same level as php-5.2.9

Gzip-cd php-5.2.8-fpm-0.5.10.diff.gz | patch-d php-5.2.9-p1

After the patch is completed, the following parameters are added when compiling php:

-enable-fpm activates fpm support for fastcgi mode

-configuration file for with-fpm-conf php-fpm (default is PREFIX/etc/php-fpm.conf)

-the log file of with-fpm-log php-fpm (default is PREFIX/logs/php-fpm.log)

-pid file of with-fpm-pid php-fpm (default is PREFIX/logs/php-fpm.pid). / configure-- prefix=/EBS/php\-- with-config-file-path=/EBS/php/etc\-- enable-fastcgi\-- enable-fpm\-- OTHERS

Note:-- enable-fastcgi\ needs to precede-- enable-fpm\, otherwise fpm cannot be compiled on.

two。 After compiling the php, modify the configuration file

Vi / EBS/php/etc/php-fpm.conf

You need to pay attention to the following configurations

127.0.0.1:9000

This represents the ip address and port that the fastcgi process of php listens to.

Nobodynobody

Indicates the user and user group under which the fastcgi process of php runs. By default, the line is commented out and needs to be opened.

0

Whether or not to display php error messages

five

Maximum number of child processes

Run php-fpm:

Php-fpm uses a program to control the fastcgi process, which is found in $PREFIX/sbin/php-fpm

/ usr/local/php/sbin/php-fpm

The program has the following parameters:

Start starts the fastcgi process of php

Stop forcibly terminates php's fastcgi process

Quit smoothly terminates the fastcgi process of php

Restart restarts the fastcgi process of php

Reload reloads php.ini for php

Logrotate re-enables log files

That is, after modifying the php.ini, we can use the

/ usr/local/php/sbin/php-fpm reload

In this way, the php.ini is reloaded while the fastcgi process of php is running continuously.

The code is as follows:

User www www;worker_processes 10 errorists 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 48k; 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 log_format access 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;}}

New profile

The code is as follows:

/ usr/local/nginx/conf/fcgi.conf

Note: nginx comes with a configuration file, / usr/local/nginx/conf/fastcgi_params, which lacks a bold font, which will cause a 404 error when accessing the php file.

The copy code is as follows:

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

Four configuration XCache

1. Install the xcache module

Wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gztar-xvzf xcache-1.2.2.tar.gzcd xcache-1.2.2/usr/local/php/bin/phpize./configure-with-php-config=/usr/local/php/bin/php-config-enable-xcache--enable-xcache-optimizermakemake install

2. Calculate the MD5 value of the password

Echo-n "password" | md5sum5f4dcc3b5aa765d61d8327deb882cf99

3. Configure XCache

Note: zend_extension, the extension used to load zend, is the absolute path, extension is the relative path, relative to extension_dir, non-zend extension

If you change the path, be sure to apachectl stop before start, not restart.

Vi / usr/local/php/etc/php.ini

Add:

The code is as follows:

[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 namexcache.admin.user = "admin"; Change xcache.admin.pass to the MD5 fingerprint of your password; Use md5-s "your_secret_password" to find the fingerprintxcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99" [xcache] Change xcache.size to tune the size of the opcode cachexcache.size = 24Mxcache.shm_scheme = "mmap" xcache.count = 2xcache.slots = 8Kxcache.ttl = 0xcache.gc_interval = 0 Change xcache.var_size to adjust the size of variable cachexcache.var_size = 8Mxcache.var_count = 1xcache.var_slots = 8Kxcache.var_ttl = 0xcache.var_maxttl = 0xcache.var_gc_interval = 300xcache.test = Offxcache.readonly_protection = Onxcache.mmap_path = "/ tmp/xcache" xcache.coredump_directory = "" xcache.cacher = Onxcache.stat = Onxcache.optimizer = off [xcache.coverager] xcache.coverager = Onxcache.coveragedump_directory = ""

5. Restart the PHP module

After normal load

In the information shown by phpinfo

Zend, this should add the content of XCache.

6. The other two acceleration modules:

In our tests, the results are better than xcache, these three acceleration can not exist at the same time, there are conflicts.

6.1 apc

The code is as follows:

Wget http://pecl.php.net/get/APC-3.0.19.tgzcd 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-configmakemake install6.2 eacceleratorwget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zipcd eaccelerator -0.9.5.3/usr/local/php/bin/phpize./configure-enable-eaccelerator=shared-with-php-config=/EBS/php/bin/php-configmakemake installvi php.inizend_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 "

5. Use nginx to correspond to multiple facgi servers

Idea: the front end of a nginx, used for load balancing and processing static pages. Use the upstream module of nginx to distribute the php request to the php-fpm server in the later segment.

There are multiple php-fpm servers at the back end, and only php-fpm services are used to handle php.

This reduces the number of nginx services on php-fpm, which is equivalent to one less layer.

At this point, the study on "how to solve the problem of php fpm errors" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 292

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report