Ubuntu下安装PHP-FPM

把VPS的Lenny5换成了Ubuntu10.04,借这个机会试一下效率更高的 PHP-FPM

以下是fabric脚本:

def init_nmp():
    install_nginx()
    install_php()
    install_phpfpm()
 
def install_nginx():
    sudo("add-apt-repository ppa:nginx/stable")
    sudo("apt-get update")
    sudo("apt-get -y -q install nginx-full nginx-common")
 
def install_php():
    # More packages upon request
    sudo("apt-get -y -q --force-yes install php5-cli php5-cgi php5-mysql")
    sudo("apt-get -y -q --force-yes install php5-mcrypt libmcrypt mcrypt") 
 
def install_phpfpm():
    # TODO: use canonical php-fpm package when available
    sudo("add-apt-repository ppa:brianmercer/php")
    sudo("apt-get update")
    sudo("apt-get -y -q install php5-fpm")

/etc/php5/fpm/php5-fpm.conf里将tcp修改成unix socket方式,单机情况下性能更好。

listen = /var/run/php5-fpm.sock
;listen = 127.0.0.1:9000

Nginx里的配置:

location ~ \.php$ { 
    try_files $uri = 404; 
    include /etc/nginx/fastcgi_params; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
 
    fastcgi_split_path_info         ^(.+\.php)(.*)$; 
    include fastcgi_params; 
    fastcgi_intercept_errors        on; 
    fastcgi_ignore_client_abort     off; 
    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; 
}

标签: , , , ,