PHP-FPM

From The Brainwrecked Wiki
Jump to navigation Jump to search
First Appeared 2007-06-19
Original Author Andrei Nigmatulin
License PHP License
(OSI and FSF Approved)
Web Site https://www.php.net
Documentation FastCGI Process Manager (FPM)
See Also: PHP Programming at Wikibooks

PHP-FPM is the recommended solution to run a FastCGI server for PHP for Nginx.

Prerequites

Web Server
Serve PHP pages

Required Packages

sudo pacman -Syu --needed php-{acpu,fpm,gd,imagick,intl,redis,sodium}

Configuration

Look for and edit the following lines in /etc/php/php.ini:

/etc/php/php.ini
[PHP]
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/dev/urandom:/proc/meminfo
include_path = ".:/php/includes:/usr/share/pear"
upload_max_filesize = 8M

extension=apcu
extension=dba
extension=exif
extension=gd
extension=gettext
extension=iconv
extension=imagick
extension=imap
extension=intl
extension=sodium
extension=ldap
extension=mysqli
zend_extension=opcache
extension=pdo_mysql
extension=soap

[Date]
date.timezone = <timezone>

[Pdo_mysql]
pdo_mysql.cache_size = 2000

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1

tmpfs for PHP Sessions

/etc/php/php.ini
[Session]
session.save_path = "/srv/phptmp"

Find the id and gid of the mysql user and group:

$ id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
/etc/fstab
# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir>           <type>  <options>                                       <dump> <pass>
...
tmpfs		/srv/phptmp	tmpfs	rw,noatime,gid=27,uid=27,size=100M,mode=0750	0 0
...
Note: If you're using ZFS, add x-systemd.after=zfs.mount to the mount options.

Finalization

Then make sure the php-fpm service is enabled and running:

sudo systemctl enable --now php-fpm