Home  >  Article  >  Backend Development  >  How to compile and install PHP-FPM from source code

How to compile and install PHP-FPM from source code

PHPz
PHPzOriginal
2023-04-12 09:03:171483browse

With the popularity and use of PHP, PHP-FPM is also known and used by more and more users and developers. Because PHP-FPM comes with more advanced process management and reloading tools, it is widely used in PHP programs in high-traffic and HTTP high-concurrency scenarios.

This article will explain how to compile and install PHP-FPM from source code, and explain it step by step. I believe that after reading the article, readers will easily and quickly install PHP-FPM for their systems to better adapt to various application scenarios.

1. Notes

Before installing PHP-FPM, you need to pay attention to the following:

1. Confirm the required system dependencies (including runtime and Dependencies during build);
2. Select the required PHP-FPM version, it is recommended to choose the latest version;
3. Unzip the source code of PHP-FPM;
4. Compile PHP-FPM and install ;
5. You need to know some configuration file parameters and command line options.

2. Installation environment

Before starting the installation, please confirm your operating system and the version of PHP-FPM you need to install. In this article, we will choose PHP-FPM-7.4.12 version and use CentOS 7 operating system.

3. Confirm the required system dependencies

To install PHP-FPM on CentOS 7, you need to install some system dependencies first. The following are the dependencies we need to install:

1. Install GCC and make compiler;
2. Install OpenSSL and OpenSSL-devel;
3. Install libxml2 and libxml2-devel;
4. Install bzip2 and bzip2-devel;
5. Install libjpeg and libjpeg-devel;
6. Install libpng and libpng-devel;
7. Install libmcrypt and libmcrypt-devel;
8 .Install zlib and zlib-devel;
9.Install libzip and libzip-devel.

Please follow the steps below to install the required dependencies:

1. Use yum to install GCC and make compiler:

sudo yum -y install gcc make

2. Install OpenSSL and OpenSSL-devel:

sudo yum -y install openssl openssl-devel

3. Install libxml2 and libxml2-devel:

sudo yum -y install libxml2 libxml2-devel

4. Install bzip2 and bzip2-devel:

sudo yum -y install bzip2 bzip2-devel

5. Install libjpeg and libjpeg- devel:

sudo yum -y install libjpeg libjpeg-devel

6. Install libpng and libpng-devel:

sudo yum -y install libpng libpng-devel

7. Install libmcrypt and libmcrypt-devel:

sudo yum -y install libmcrypt libmcrypt-devel

8. Install zlib and zlib-devel:

sudo yum -y install zlib zlib-devel

9. Install libzip and libzip-devel:

sudo yum -y install libzip libzip-devel

4. Install PHP-FPM

After confirming the installation environment and dependencies, you can start the installation of PHP-FPM.

1. Unzip the source code of PHP-FPM:

tar xzf php-7.4.12.tar.gz
cd php-7.4.12/

2 .Compile and configure:

./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --with-gd -- enable-gd --with-jpeg --with-png --with-freetype --enable-bcmath --enable-fpm --enable-mbstring --enable-mysqlnd --with-zlib --with-zip -- with-mysqli --with-pdo-mysql --with-openssl

Please note that the above configure command will compile and configure PHP-FPM, and install library files, configuration files, etc. to /usr /local/php directory.

3. Install:

make && make install

4. Copy php.ini:

cp php.ini-production /usr/local /php/lib/php.ini

5. Modify the PHP-FPM configuration file:

cp /usr/local/php/etc/php-fpm.conf.default /usr/ local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf

Please modify php-fpm.conf according to the following configuration:

user = www
group = www
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pm.process_idle_timeout = 10s
pm.max_requests = 2048

The above configuration is a basic PHP-FPM configuration example, you can modify it according to actual needs.

6. Start PHP-FPM:

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

5. Test

After the installation is completed, Check whether the /usr/local/php directory exists and whether php-fpm is running. You can use the following command to test whether PHP-FPM has been installed correctly:

/usr/local/php/bin/php - v
/usr/local/php/sbin/php-fpm -v

The above commands are used to view the PHP-FPM version and status respectively.

6. Summary

This article explains the installation and configuration process of PHP-FPM. I hope it will be helpful to the majority of PHP engineers and operation and maintenance engineers to avoid some configuration and installation aspects. The problem. I wish everyone can successfully install and use PHP-FPM and better adapt to various application scenarios!

The above is the detailed content of How to compile and install PHP-FPM from source code. 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