arrow_back
Back

PHP on Linux: installation, configuration, and PHP-FPM

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

On a typical Linux server, PHP is a compiled binary plus configuration files.

Installation (CentOS/RHEL 7)

The default repos ship only PHP 5.4. For newer versions, add the open_in_new Remi repository , enable the repo for the version you need, then install:

yum install php-cli

See what is installed

rpm -qa | grep php

Example output:

php55w-intl-5.5.38-1.w6.x86_64
php55w-gd-5.5.38-1.w6.x86_64
php55w-5.5.38-1.w6.x86_64
...

Common packages

Package Description
php55w-common Core PHP files
php55w-cli PHP CLI
php55w Apache module

ZTS + pthreads

See open_in_new this guide .

Installing modules

List available PHP packages:

yum list | grep php

Examples:

php-mbstring.x86_64                         5.4.16-46.el7              base
php-mysql.x86_64                            5.4.16-46.el7              base
php-pdo.x86_64                              5.4.16-46.el7              base

Configuration

Default php.ini on CentOS/RHEL:

/etc/php.ini

The session save directory must be writable by the web server user:

session.save_path = "/var/lib/php/session"

Memory limit:

memory_limit = 128M

For heavy workloads:

memory_limit = 2048M

Security — disable path-info fallback (allows executing unintended PHP files):

cgi.fix_pathinfo=0

Quick checks

Loaded config file:

php -r 'echo "\n" . php_ini_loaded_file() . "\n";'

Current memory limit:

php -r "echo ini_get('memory_limit').PHP_EOL;"

Loaded modules:

php -m

PHP-FPM (CentOS/RHEL)

yum install php-fpm

Pool settings in /etc/php-fpm.d/www.conf:

user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx

Further reading: open_in_new How To Install Linux, Nginx, MySQL, PHP (LEMP) stack on CentOS 7 .

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Nginx on Linux: installation, configuration, and virtual hosts

arrow_forward