Home >Backend Development >PHP Problem >What to do if linux php7-fpm fails to start

What to do if linux php7-fpm fails to start

藏色散人
藏色散人Original
2023-02-20 09:20:464702browse

Linux php7-fpm solution to startup failure: 1. Modify the "error_log" item in the "php-fpm.conf" file; 2. Modify the configuration file location of php; 3. Modify nginx to the current System user name; 4. Create nginx user and user group directly.

What to do if linux php7-fpm fails to start

The operating environment of this tutorial: Windows 10 system, php7.2.1 version, DELL G3 computer

linux What to do if php7-fpm fails to start manage?

Solution to php-fpm startup failure (after installing PHP on centOS)

After compiling and installing php7.2.1 on centOS7.0, because of the newly added php extension, so you need to restart php-fpm;

First, let me talk about my configuration, about configuring php-fpm:

After the initial installation, these few There are no files. You need to create them one by one and start them. If there is no error, you don’t need to read "2. php-fpm startup error:"

1. About configuring php-fpm

cp php.ini-development /usr/local/php7/etc/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

2,

Start php-fpm:

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

2. php-fpm startup error:

Cause and solution:

1. Run it directly, and an error is reported that the configuration file cannot be found.

$ php-fpm

[11-Jan-2014 16:03:03] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
[11-Jan-2014 16:03:03] ERROR: failed to load configuration file '/private/etc/php-fpm.conf'
[11-Jan-2014 16:03:03] ERROR: FPM initialization failed

You can generate the configuration file in the /private/etc/ directory, which requires root permissions (sudo)

Or place the configuration file in a directory with permissions for ordinary users, pass --fpm- The config parameter specifies the location of the configuration file, as follows:

# cp /private/etc/php-fpm.conf.default /etc/php-fpm.conf
$ php-fpm --fpm-config /etc/php-fpm.conf
[11-Jan-2014 16:10:49] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
[11-Jan-2014 16:10:49] ERROR: failed to post process the configuration
[11-Jan-2014 16:10:49] ERROR: FPM initialization failed

The error message displays: The "log" file cannot be opened correctly. The reason is that it works in the /usr/var directory by default. You can modify the configuration file to specify the correct log. File path

$ vim /usr/local/etc/php-fpm.conf

Modify the error_log item in the php-fpm.conf file. The default prefix is ​​/usr/var, but there is no such path

error_log = /usr/local/var/log/php-fpm.log
pid = /usr/local/var/run/php-fpm.pid

or do not modify the configuration item in the configuration file. Path, in the running parameters of php-fpm (-p), specify the relative path prefix

$ php-fpm --fpm-config /php-fpm.conf  --prefix /usr/local/var

where the runtime file is placed. At this point, the php-fpm daemon can basically be started correctly.

Error message:

[12-Jul-2013 17:18:57] ERROR: [/usr/local/php5/etc/php-fpm.conf:144] value is NULL for a ZEND_INI_PARSER_ENTRY
[12-Jul-2013 17:18:57] ERROR: failed to load configuration file '/usr/local/php5/etc/php-fpm.conf'
[12-Jul-2013 17:18:57] ERROR: FPM initialization failed

2. The main reason for the error is /usr/local/php5/sbin/php-fpm configuration error. Check carefully. My mistake was that the = sign was missing here in group = www. So something went wrong

[root@localhost ~]# /usr/local/php5/sbin/php-fpm
PHP:  syntax error, unexpected TC_STRING in /usr/local/php5/etc/php.ini on line 211

3. When starting php-fpm, the error ERROR: [pool www] cannot get uid for user 'nginx'

method 1:

After compiling php7, use the following command to start

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

and then report this error:

[07-Dec-2018 17:59:31] ERROR: [pool www] cannot get uid for user 'nginx'
[07-Dec-2018 17:59:31] ERROR: FPM initialization failed

Modify the location of the php configuration file at www.conf

vi /usr/local/php/etc/php-fpm.d/www.conf

Modify nginx to the user name of the current system as follows:

; Unix user/group of processes
 ; Note: The user is mandatory. If the group is not set, the default user's group
 ;       will be used.
 user = www.emam.cn
 group = www.emam.cn

Method 2:

Create nginx user and user group directly

useradd nginx
groupadd nginx
usermod -G nginx nginx

3. php-fpm content expansion

Start php-fpm:

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

php 5.3.3 and later php-fpm will no longer support the /usr/local/ that php-fpm previously had. php/sbin/php-fpm (start|stop|reload) and other commands, so don’t look at this old-fashioned command anymore. You need to use signal control:

The master process can understand the following signals

INT, TERM Terminate immediately

QUIT Terminate gracefully

USR1 Reopen the log file

USR2 Gracefully reload all worker processes and reload configuration and binary modules

A simple and direct restart method:

First check the master process number of php-fpm

# ps aux|grep php-fpm
root     21891  0.0  0.0 112660   960 pts/3    R+   16:18   0:00 grep --color=auto php-fpm
root     42891  0.0  0.1 182796  1220 ?        Ss   4月18   0:19 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody   42892  0.0  0.6 183000  6516 ?        S    4月18   0:07 php-fpm: pool www
nobody   42893  0.0  0.6 183000  6508 ?        S    4月18   0:17 php-fpm: pool www

Restart php-fpm:

kill -USR2 42891

OK.

The above scheme is generally used when the php-fpm.pid file is not generated. If you want to generate php-fpm.pid, use the following scheme:

You can see the above master process, matster The configuration file /usr/local/php/etc/php-fpm.conf is used. Cat /usr/local/php/etc/php-fpm.conf found:

[global]
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
;pid = run/php-fpm.pid

pid file path should be located at /usr/local/php/var/run/php-fpm.pid, because it was commented out, it was not generated. We remove the comment, then kill -USR2 42891 and restart php-fpm, the pid file will be generated. It will be OK next time. Use the following command to restart and close php-fpm:

php-fpm Close:

kill -INT 'cat /usr/local/php/var/run/php-fpm.pid'

php-fpm Restart:

kill -USR2 'cat /usr/local/php/var/run/php-fpm.pid'

Recommended learning: "PHP Video Tutorial

The above is the detailed content of What to do if linux php7-fpm fails to start. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn