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' \
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
Start php-fpm
After the installation is completed, we try to start:
The startup command is:
/usr/local/php/sbin/php-fpm
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
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
Edit this configuration file:
vim php-fpm.conf pid = run/php-fpm.pid user = www group = www 再次尝试启动: /usr/local/php/sbin/php-fpm
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
Okay, let’s create a new www user group:
groupadd www useradd -g www www
Start it again:
/usr/local/php/sbin/php-fpm
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
[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]#
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
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`
php-fpm restart:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
