Home >Backend Development >PHP Problem >Detailed introduction to the installation and use of PHP-FPM
PHP-FPM is a FastCGI process manager, which is a very important component of PHP and can provide better PHP performance and reliability.
This article will introduce the installation and use of PHP-FPM to help developers quickly master this important component.
1. Install PHP-FPM
1.1 Install PHP
Before installing PHP-FPM, you need to install PHP first. PHP has many different versions and extensions, and you can choose different versions of PHP according to your project needs. In general, you can install PHP through the following command:
sudo apt-get install php
The above command is an example of installing PHP on an Ubuntu system. The specific installation method may vary depending on the operating system.
1.2 Install php-fpm
Installing php-fpm can be achieved through the following command:
sudo apt-get install php-fpm
After installing php-fpm, you need to start it:
sudo service php-fpm start
2. Configure PHP-FPM
Before using PHP-FPM, some configurations are required. Generally, configuration can be done in the following files:
/etc/php/7.2/fpm/php.ini /etc/php/7.2/fpm/pool.d/www.conf
Among them, the php.ini
file is the main configuration file of PHP, in which some basic parameters of PHP can be set; ## The #www.conf file is the configuration file of PHP-FPM, in which you can set some parameters of PHP-FPM, such as the number of processes, the maximum number of connections, etc.
www.conf file:
; Start a new pool named 'www'. [www] ; The user and group the PHP-FPM process will run as. user = www-data group = www-data ; The address on which to accept FastCGI requests. listen = /run/php/php7.2-fpm.sock ; Set permissions on the socket to allow the web server to access it. listen.owner = www-data listen.group = www-data listen.mode = 0660 ; The number of child processes to spawn. pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 5The above configuration is a relatively simple example and can be modified according to the actual situation. 3. Using PHP-FPMUsing PHP-FPM can be done through the FastCGI protocol. The following is an example configuration using PHP-FPM:
location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }The above configuration will URI Requests ending in .php are forwarded to the PHP-FPM process and communicate using the FastCGI protocol. 4. SummaryPHP-FPM is an important component of PHP that can provide better performance and reliability. Before using PHP-FPM, you need to install and configure it, and understand some usage methods. Hope the above content can help developers quickly master the installation and use of PHP-FPM.
The above is the detailed content of Detailed introduction to the installation and use of PHP-FPM. For more information, please follow other related articles on the PHP Chinese website!