User Tools

Site Tools


php-fpm

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

php-fpm [2017/01/05 06:15] (current)
felixonmars created
Line 1: Line 1:
 +==== PHP-FPM Installation on Ubuntu Server ====
 +<​code>​
 +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
 +</​code>​
 +
 +==== IonCube ====
 +<​code>​
 +wget http://​downloads3.ioncube.com/​loader_downloads/​ioncube_loaders_lin_x86-64_5.1.2.tar.gz
 +tar xf ioncube_loaders_lin_x86-64_5.1.2.tar.gz
 +cp ioncube/​ioncube_loader_lin_5.6.so /​usr/​lib/​php/​20131226/​ioncube.so
 +cat > /​etc/​php/​5.6/​cli/​conf.d/​00-ioncube.ini << EOF
 +zend_extension=ioncube.so
 +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
 +</​code>​
 +
 +==== PHP-FPM Nginx Integration ====
 +<​code>​
 +tee /​etc/​nginx/​conf.d/​php.conf << EOF
 +upstream php {
 +    server unix:/​var/​run/​php/​php5.6-fpm.sock;​
 +}
 +EOF
 +</​code>​
 +
 +In any site configurations:​
 +<​code>​
 +    location ~ \.php?$ {
 +        include /​etc/​nginx/​fastcgi_params;​
 +        fastcgi_index index.php;
 +        fastcgi_pass php;
 +    }
 +</​code>​
 +
 +==== Fix Blank Page Problem ====
 +Append to /​etc/​nginx/​fastcgi_params:​
 +<​code>​
 +fastcgi_param ​ SCRIPT_FILENAME ​   $request_filename;​
 +</​code>​
 +
 +==== Restart Server ====
 +<​code>​
 +service nginx restart
 +service php5.6-fpm restart
 +</​code>​
 +
 +==== FPM Tuning ====
 +=== For Low Memory Server ===
 +<​code>​
 +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)
 +</​code>​
 +(The config file is at ''/​etc/​php/​5.6/​fpm/​pool.d/​www.conf''​ by default)
 +
 +==== Nginx Tuning For Fastcgi ====
 +<​code>​
 +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;
 +</​code>​
 +
 +==== Remove ::ffff: From IPv4 Compatible Addresses ====
 +<​code>​
 +set $remote_addr_new $remote_addr;​
 +if ($remote_addr ~* ^::​ffff:​(.*))
 +{
 + set $remote_addr_new $1;
 +}
 + 
 +fastcgi_param ​  ​REMOTE_ADDR ​       $remote_addr_new;​
 +</​code>​
 +
 +==== Increase POST Size Limit ====
 +Edit /​etc/​php5/​fpm/​php.ini:​
 +<​code>​
 +upload_max_filesize = 100M
 +post_max_size = 100M
 +</​code>​
 +
 +References:
 +
 +  * http://​apt-blog.net/​best-practise-nginx-php-via-php-fpm-on-ubuntu
 +  * http://​wiki.beyondhosting.net/​PHP-FPM_and_Nginx
 +  * http://​wiki.ptsang.net/​Debian%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE
 +  * http://​www.wenzk.com/​archives/​1239
 +  * http://​hi.baidu.com/​lizhm/​blog/​item/​6c7e359bcfd515a2c8eaf434.html
 +  * http://​rtcamp.com/​wordpress-nginx/​tutorials/​php/​increase-file-upload-size-limit/​
 +  * https://​blog.felixc.at/​2014/​05/​fix-debian-wheezy-blank-page-issue-when-using-nginx-official-deb-and-php-fpm/​
  
php-fpm.txt ยท Last modified: 2017/01/05 06:15 by felixonmars