Home Backend Development PHP Tutorial Installation and startup of php-fpm

Installation and startup of php-fpm

Jul 29, 2016 am 09:11 AM
php-fpm

This article mainly introduces the installation and startup of php-fpm. Students who are interested in PHP tutorials can refer to it.

I have studied the mod_php mode, mode_fastcgi and php-fpm mode in php before. I roughly described the differences between several modes and also understood that php-fpm is the manager of fastcgi mode (Address: https:/ /www.zybuluo.com/phper/note/50231). Today let’s take a look at how to install php-fpm in php and run it.

Install php-fpm

My machine is centos 6.2 and php 5.4.11 has been installed before. PHP has written php-fpm into the php source code core after 5.3.3. So there is no need to download it separately. Mine is 5.4.11 so I can use it directly.

Since my php has been installed, and I did not bring the fpm mode when compiling before, I have to find the source code and recompile it:

To make php support php-fpm, I only need to bring - when compiling. -enable-fpm will do the trick.

So, I need to find the previous compilation parameters, add --enable-fpm after it, and recompile. As mentioned before, there are two ways to find the previous compilation parameters:

1. Find config.nice in the source code /lamp/php-5.4.11/, this is the previous compilation parameter

2. Find the Configure related configuration in the php.ini configuration file: /usr/local/php/bin/php -i |grep 'Configure'

Okay, let's start and find the previous compilation parameters:

[root@localhost /]# cd /lamp/php-5.4.11 & vi config.nice
'./configure' \
'--prefix=/usr/local/php' \
'--with-config-file-path=/usr/local/php/etc/' \
'--with-apxs2=/usr/local/apache/bin/apxs' \
'--with-mysql=/usr/local/mysql/' \
'--with-libxml-dir=/usr/local/libxml2/' \
'--with-png-dir=/usr/local/libpng/' \
'--with-jpeg-dir=/usr/local/jpeg8/' \
'--with-freetype-dir=/usr/local/freetype/' \
'--with-gd=/usr/local/gd/' \
'--with-zlib-dir=/usr/local/zlib/' \
'--with-mcrypt=/usr/local/libmcrypt/' \
'--with-mysqli=/usr/local/mysql/bin/mysql_config' \
'--enable-soap' \
'--enable-mbstring=all' \
'--enable-sockets' \
Copy after login

After adding --enable-fpm, recompile:

[root@localhost /]# cd /lamp/php-5.4.11
[root@localhost php-5.4.11]# './configure' \
    '--prefix=/usr/local/php' \
    '--with-config-file-path=/usr/local/php/etc/' \
    '--with-apxs2=/usr/local/apache/bin/apxs' \
    '--with-mysql=/usr/local/mysql/' \
    '--with-libxml-dir=/usr/local/libxml2/' \
    '--with-png-dir=/usr/local/libpng/' \
    '--with-jpeg-dir=/usr/local/jpeg8/' \
    '--with-freetype-dir=/usr/local/freetype/' \
    '--with-gd=/usr/local/gd/' \
    '--with-zlib-dir=/usr/local/zlib/' \
    '--with-mcrypt=/usr/local/libmcrypt/' \
    '--with-mysqli=/usr/local/mysql/bin/mysql_config' \
    '--enable-soap' \
    '--enable-mbstring=all' \
    '--enable-sockets' \
    '--enable-fpm'
[root@localhost php-5.4.11] make && make install
Copy after login

Start php-fpm

After the installation is completed, we try to start:

The startup command is:

/usr/local/php/sbin/php-fpm
Copy after login
Copy after login

The error is reported:

[26-Feb-2015 15:39:55] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

[26-Feb-2015 15:39:55] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'

[26-Feb-2015 15:39:55] ERROR: FPM initialization failed
Copy after login

The error message says that php-fpm.conf cannot be found

Oh, it turns out to be php -fpm.conf is not there yet, we go to the /usr/local/php/etc directory and copy php-fpm.conf.default into php-fpm.conf

cd /usr/local/php/etc/

cp php-fpm.conf.default php-fpm.conf
Copy after login

Edit this configuration file:

vim php-fpm.conf
pid = run/php-fpm.pid
user = www
group = www
再次尝试启动:
/usr/local/php/sbin/php-fpm
Copy after login

again An error is reported saying that the www user does not exist:

[26-Feb-2015 15:57:38] ERROR: [pool www] cannot get uid for user 'www'
[26-Feb-2015 15:57:38] ERROR: FPM initialization failed
Copy after login

Okay, let’s create a new www user group:

groupadd www
useradd -g www www
Copy after login

Start it again:

/usr/local/php/sbin/php-fpm
Copy after login
Copy after login

There is no output, indicating success! ! !

php-fpm occupies port 9000. Let’s check the process:

[root@localhost php-5.4.11]# ps -ef|grep php-fpm
root      1377  1231  0 11:19 pts/1    00:00:00 grep php-fpm
root     29249     1  0 06:22 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www      29250 29249  0 06:22 ?        00:00:00 php-fpm: pool www
www      29251 29249  0 06:22 ?        00:00:00 php-fpm: pool www
root     32132  6158  0 08:25 pts/2    00:00:00 vi php-fpm.conf
Copy after login
[root@localhost php-5.4.11]# netstat -tnl | grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      
[root@localhost php-5.4.11]#
Copy after login

Okay, the installation and startup are OK.

Start php-fpm at startup

I mentioned before that php-fpm is a layer server independent of the web server and php, so we need to start it at startup

The configuration file for startup is: / etc/rc.local, just add /usr/local/php/sbin/php-fpm

[root@localhost init]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/apache/bin/apachectl start
/usr/local/bin/redis-server /etc/redis.conf
/usr/local/php/sbin/php-fpm
Copy after login

It’s useless just to install php-fpm. It has to be used with the web server. In the next section, I want to learn nginx Install, and connect nginx to php-fpm to use php.

Restart php-fpm

After we install the extension, we need to restart php-fpm to make the extension effective.

The simplest and crudest way to restart php-fpm is:

First find the process number of php-fpm, kill it, and then use /usr/local/php/sbin/php-fpm to start it like this.

In fact, there are more gentle methods, which is to use signals.

INT, TERM: terminate immediately

QUIT: terminate smoothly

USR1: reopen the log file

USR2: smoothly reload all worker processes and reload configuration and binary modules

Example:

php- fpm shutdown:

kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
Copy after login

php-fpm restart:

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
Copy after login
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
How to use php-fpm for high-performance tuning How to use php-fpm for high-performance tuning Jul 08, 2023 am 11:30 AM

How to use php-fpm for high-performance tuning PHP is a very popular server-side scripting language that is widely used to develop web applications and dynamic websites. However, as traffic increases, the performance of your PHP application may suffer. In order to solve this problem, we can use php-fpm (FastCGIProcessManager) for high-performance tuning. This article will introduce how to use php-fpm to improve the performance of PHP applications and provide code examples. one,

How to use PHP-FPM optimization to improve the performance of PrestaShop applications How to use PHP-FPM optimization to improve the performance of PrestaShop applications Oct 05, 2023 pm 12:33 PM

How to use PHP-FPM optimization to improve the performance of PrestaShop applications. With the rapid development of the e-commerce industry, PrestaShop has become the e-commerce platform chosen by many merchants. However, as the size of the store increases and the number of visits increases, the PrestaShop application may encounter performance bottlenecks. In order to improve the performance of the PrestaShop application, a common method is to use PHP-FPM to optimize and improve the application's processing capabilities. PHP-FPM (FastCGI

How to improve the performance of your WooCommerce application using PHP-FPM optimization How to improve the performance of your WooCommerce application using PHP-FPM optimization Oct 05, 2023 am 08:24 AM

How to Improve the Performance of WooCommerce Applications Using PHP-FPM Optimization Overview WooCommerce is a very popular e-commerce plugin for creating and managing online stores on WordPress websites. However, as your store grows and traffic increases, WooCommerce apps can become slow and unstable. To solve this problem, we can use PHP-FPM to optimize and improve the performance of WooCommerce applications. What is PHP-FP

Use php-fpm connection pool to improve database access performance Use php-fpm connection pool to improve database access performance Jul 07, 2023 am 09:24 AM

Overview of using php-fpm connection pool to improve database access performance: In web development, database access is one of the most frequent and time-consuming operations. The traditional method is to create a new database connection for each database operation and then close the connection after use. This method will cause frequent establishment and closing of database connections, increasing system overhead. In order to solve this problem, you can use php-fpm connection pool technology to improve database access performance. Principle of connection pool: Connection pool is a caching technology that combines a certain number of databases

Use php-fpm process management to achieve load balancing Use php-fpm process management to achieve load balancing Jul 09, 2023 pm 01:07 PM

Using php-fpm process management to achieve load balancing As Internet applications become increasingly complex and the number of users increases, load balancing has become an indispensable technology. The goal of load balancing is to distribute traffic to multiple servers to improve system stability and performance. In PHP applications, php-fpm (PHPFastCGIProcessManager) is a common process management tool that can be used to achieve load balancing and provides flexible configuration options. This article will introduce how to use

How to use PHP-FPM optimization to improve the performance of Phalcon applications How to use PHP-FPM optimization to improve the performance of Phalcon applications Oct 05, 2023 pm 01:54 PM

How to use PHP-FPM to optimize and improve the performance of Phalcon applications. Introduction: Phalcon is a high-performance PHP framework. Combining with PHP-FPM can further improve the performance of applications. This article will introduce how to use PHP-FPM to optimize the performance of Phalcon applications and provide specific code examples. 1. What is PHP-FPMPHP-FPM (PHPFastCGIProcessManager) is a PHP process independent of the web server

Detailed explanation of php-fpm tuning method Detailed explanation of php-fpm tuning method Jul 08, 2023 pm 04:31 PM

PHP-FPM is a commonly used PHP process manager used to provide better PHP performance and stability. However, in a high-load environment, the default configuration of PHP-FPM may not meet the needs, so we need to tune it. This article will introduce the tuning method of PHP-FPM in detail and give some code examples. 1. Increase the number of processes. By default, PHP-FPM only starts a small number of processes to handle requests. In a high-load environment, we can improve the concurrency of PHP-FPM by increasing the number of processes

PHP-FPM performance improvement strategies and practice guide PHP-FPM performance improvement strategies and practice guide Oct 05, 2023 pm 03:55 PM

Introduction to PHP-FPM Performance Improvement Strategies and Practice Guide: With the rapid development of the Internet and the increasing number of website visits, it is particularly important to improve the performance of PHP applications. PHPFastCGIProcessManager (PHP-FPM) is a commonly used PHP process manager that can improve the performance of PHP applications through a series of strategies and practices. This article will introduce some PHP-FPM performance improvement strategies, combined with specific code examples, to help readers better understand

See all articles