User Tools

Site Tools


PHP-FPM Installation on Ubuntu Server

apt-get install software-properties-common

add-apt-repository ppa:nginx/stable
add-apt-repository ppa:ondrej/php

apt-get update
apt-get install nginx

apt-get install php5.6-cgi php5.6-mysql php5.6-fpm php5.6-curl php5.6-gd php5.6-imap php5.6-mbstring php5.6-mcrypt php5.6-pspell php5.6-recode php5.6-sqlite php5.6-tidy php5.6-xmlrpc php5.6-xsl


tar xf ioncube_loaders_lin_x86-64_5.1.2.tar.gz
cp ioncube/ /usr/lib/php/20131226/
cat > /etc/php/5.6/cli/conf.d/00-ioncube.ini << EOF
cp /etc/php/5.6/cli/conf.d/00-ioncube.ini /etc/php/5.6/fpm/conf.d/00-ioncube.ini
service php5.6-fpm restart

PHP-FPM Nginx Integration

tee /etc/nginx/conf.d/php.conf << EOF
upstream php {
    server unix:/var/run/php/php5.6-fpm.sock;

In any site configurations:

    location ~ \.php?$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_pass php;

Fix Blank Page Problem

Append to /etc/nginx/fastcgi_params:

fastcgi_param  SCRIPT_FILENAME    $request_filename;

Restart Server

service nginx restart
service php5.6-fpm restart

FPM Tuning

For Low Memory Server

pm = dynamic              ;Dynamic allocate child-processes for php-fpm
pm.max_children = 5       ;Limit number of child-processes
pm.start_servers = 2      ;Start 2 child-processes when server starts
pm.min_spare_servers = 2  ;Remain at least 2 when spare
pm.max_spare_servers = 5  ;Remain at most 5 when spare
pm.max_requests = 300     ;300 requests the most per child-process(and then exit and start new one)

(The config file is at /etc/php/5.6/fpm/pool.d/www.conf by default)

Nginx Tuning For Fastcgi

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

Remove ::ffff: From IPv4 Compatible Addresses

set $remote_addr_new $remote_addr;
if ($remote_addr ~* ^::ffff:(.*))
 set $remote_addr_new $1;
fastcgi_param   REMOTE_ADDR        $remote_addr_new;

Increase POST Size Limit

php-fpm.txt · Last modified: 2017/01/05 06:15 by felixonmars