php5-fpm以及fcgiwrap在ubuntu下的安装方法

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:
网上搜索 大部分都是讲怎么编译安装的, 自己也搜索过ubuntu的源, 没有单独的php5-fpm的安装包, 不过按照一个老外的安装方法, 还是可以不用编译的。 

第一步: 

aptitude install python-software-properties 

第二步: 

add-apt-repository ppa:brianmercer/php 

第三步: 

aptitude -y update 

第四步: 

aptitude -y install php5-fpm 

安装好后, 配置一下 /etc/php5/fpm/php5-fpm.conf 

pm.max_children 设置大一点, 默认是10, 这是php5-fpm的进程数。 

然后就是 service php5-fpm start 启动。 

php5-fpm是可以平滑重启的,修改了php.ini文件后, 用service php5-fpm reload 就能重新加载配置文件。 


I've been using the dotdeb.org pacakges for my ubuntu 9.10 servers and they've been running well, except for some necessary patches to contrib modules for php 5.3. 

Now ubuntu 10.04 lucid is out and has php 5.3.2 in it. While php5-fpm won't be included in an official release until at least 5.4, it has become a part of official php development and is contained in the php version control. 

In order to ease installation and upgrade, I've created a debian style .deb package for php5-fpm on launchpad at https://launchpad.net/~brianmercer/+archive/php/. Unlike the dotdeb package, this one is adapted from the official ubuntu lucid source package and so has identical patches and compile options to the ubuntu 10.04 cgi and cli sapis. 

This package will only work on the Ubuntu 10.04 lucid release.
In order to install the package, you need to add the following to your /etc/apt/sources.list file:


deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main
deb-src http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main


and if you don't want to get the unsigned package warnings, add the launchpad key for the ppa with this command: 

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F 

Then it's the usual: 
sudo aptitude update
sudo aptitude install php5-fpm

You can then start (or stop or restart) php5-fpm with:
sudo service php5-fpm start

The new package works with all the usual ubuntu php extensions like php5-mysql, php5-gd, php-apc and php5-memcache. 

The config file is now in an ini style format instead of the xml format and is located at /etc/php5/fpm/php5-fpm.conf. By default it listens on 127.0.0.1:9000 but I typically change the conf to use a unix socket at /var/run/php5-fpm.sock. If you use a socket, you should also uncomment the user and group and mode in the conf file. (I also change the mode to 0660) 

I've set the package to start up 10 children by default. You can increase or decrease that amount depending on your memory constraints. There is a "dynamic" setting in the conf file with starting number, max number, max idle, etc. This "apache-like" system will start and stop children as needed depending on load. However, it is still experimental and it may be better to stick with the static setting for now. 

I've also set up a second repository at https://launchpad.net/~brianmercer/+archive/fcgiwrap with fcgiwrap. nginx does not have the built in ability to act as a cgi gateway for perl scripts, etc, the way that apache and most other web servers do. In order to use things like awstats.pl or nagios you need to proxy those requests to a backend. I previously ran thttpd and let nginx proxy *.pl and *.cgi requests to thttpd. (boa also worked). However, Grzegorz Nosek has written a small wrapper script in C to handle these requests which works well. http://nginx.localdomain.pl/wiki/FcgiWrap 

I've gone ahead and made a debian package from his code and put it up at https://launchpad.net/~brianmercer/+archive/fcgiwrap and it can be installed the same way as php5-fpm by adding the following to /etc/apt/sources.list:
deb http://ppa.launchpad.net/brianmercer/fcgiwrap/ubuntu lucid main
deb-src http://ppa.launchpad.net/brianmercer/fcgiwrap/ubuntu lucid main


and 

sudo aptitude update
sudo aptitude install fcgiwrap


My fcgiwrap package relies on spawn-fcgi but it has its own start/stop init script so you can use
service fcgiwrap start


It runs on 127.0.0.1:8000 by default but you can change the config file at /etc/default/fcgiwrap to also make it run as a unix socket at /var/run/fcgiwrap.sock. 

Then you can put a location in your nginx config such as
  location ~ (.cgi|.pl)$ {
#    auth_basic            "Restricted";
#    auth_basic_user_file  /var/private/htpasswd;  # somewhere outside the http root
    gzip off;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:8000;
#    fastcgi_pass unix:/var/run/fcgiwrap.sock; #if using unix socket instead of TCP
  }


You should be aware of the serious security implications of that section. You don't want someone uploading a nasty perl script to your server and running it. A section like that should only exist behind a protected subdomain or at least should have password authentication added to it. If you're only using awstats then instead of using the location above you can use one like this:
  location = /awstats.pl {
    gzip off;
    root /usr/lib/cgi-bin;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/awstats.pl;
    fastcgi_pass 127.0.0.1:8000;
#    fastcgi_pass unix:/var/run/fcgiwrap.sock;
  }

  location ~ ^/awstats-icon/(.*)$ {
    alias /usr/share/awstats/icon/$1;
  }

I hope these packages are useful and that they ease one of the complications of installing and using nginx. 
Login or register to post comments 
Comments 
php5-fpm for Debian Lenny 
Posted by omega8cc on May 23, 2010 at 4:41pm 

Thanks for this how-to, Brian. 

Since dotdeb.org has also php5-fpm for Debian Lenny and it works great, however still there are too many issues with PHP 5.3 in many contrib Drupal modules, so we are using it only for testing on our dev servers. 

Simple how-to for all Debian fans:
sudo echo "deb http://php53.dotdeb.org stable all" >> /etc/apt/sources.list
sudo echo "deb-src http://php53.dotdeb.org stable all" >> /etc/apt/sources.list
sudo apt-get update
sudo apt-get -y install php5-cli php5-common php5-suhosin php5-memcache php5-imagick php5-apc php5-dev
sudo apt-get -y install php5-curl php5-gd php5-imap php5-mcrypt php5-mysql php5-xsl php-pear
sudo apt-get -y install php5-fpm php5-cgi
invoke-rc.d php5-fpm start


See also: http://www.dotdeb.org/instructions/ 

~Grace 

    Login or register to post comments 

I was using the dotdeb repos 
Posted by brianmercer on May 23, 2010 at 5:26pm 

I was using the dotdeb repos on ubuntu 9.10 for a while and they worked perfectly, and it's good of Guillaume Plessis to make those packages available. I also owe him thanks because I used his scripts to make my Ubuntu packages. 

To use the dotdeb packages on Ubuntu instead of Debian you have to manually install two packages:
http://us.archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb53_1.6.dfsg.4...
http://us.archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu38_3.8-6ubuntu...


and one more if you use php5-mycrypt: 

http://mirrors.kernel.org/ubuntu/pool/main/libt/libtool/libltdl3_1.5.26-... 

I repackaged php5-fpm for Ubuntu on a launchpad ppa for 3 reasons: 

First, I wanted to avoid the extra work for Ubuntu users of manually adding the packages above. 

Second, I wanted to have php built with the identical compile options and patches as Ubuntu's current 10.04 php. Guillaume uses the php bundled gd (which is not a bad idea) and also the mysqlnd native driver, whereas Debian and Ubuntu use the official gd and the libmysql driver. There are also several code patches that Ubuntu applies that Guillaume doesn't. I wanted my php-fpm to match the decisions of the Ubuntu packagers. 

Ubuntu has updated php5 twice this month to incremental releases php5-5.3.2-1ubuntu4.1 and php5-5.3.2-1ubuntu4.2 and I wanted to be able to track those patches immediately and add them to my php-fpm build. 

Third, I wanted the latest version of php-fpm. Guillaume is using the fpm patch from last year that has proved very stable but didn't receive full attention from the fpm originator Andrei Nigmatulin. By the time version 5.3 and 5.2.13 were released, Andrei had already stopped updating his great work. As far as I know, there's no dev maintaining the 5.2.x branch. 

Luckily, since then, fpm has been merged into the official php.net development trunk and is now actively maintained by Antony Dovgal and Jerome Loyet, two php.net devs. Jerome has put in some good work bringing in the apache-like dynamic child spawning, and Antony has been committing patches based on reported problems. They've also committed a conversion from an xml conf file to the ini format. 

I'm using the very latest svn development version of fpm to get the benefits of the new code and watchful eye of php.net devs. 

I completely agree with you about the state of Drupal contrib modules (and core) with respect to 5.3 compatibility. I'm up to nine patches that I have to apply now to core and to contrib modules that I use.
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3月前
|
SQL 安全 PHP
PHP开发中防止SQL注入的方法,包括使用参数化查询、对用户输入进行过滤和验证、使用安全的框架和库等,旨在帮助开发者有效应对SQL注入这一常见安全威胁,保障应用安全
本文深入探讨了PHP开发中防止SQL注入的方法,包括使用参数化查询、对用户输入进行过滤和验证、使用安全的框架和库等,旨在帮助开发者有效应对SQL注入这一常见安全威胁,保障应用安全。
121 4
|
3月前
|
JSON PHP 数据格式
PHP解析配置文件的常用方法
INI文件是最常见的配置文件格式之一。
74 12
|
5月前
|
Java PHP 数据安全/隐私保护
PHP 面向对象,构造函数,析构函数,继承,方法的重写,接口抽象类,static,final,this,parent,self的异同和作用
本文详细介绍了PHP面向对象编程的一系列核心概念和用法,包括构造函数、析构函数、继承、方法重写、访问控制、接口、抽象类、静态成员、final关键字、以及this、self、parent这三个关键字的异同和作用。通过具体示例代码,展示了如何在PHP中使用这些面向对象的特性,以及它们在实际开发中的应用。
PHP 面向对象,构造函数,析构函数,继承,方法的重写,接口抽象类,static,final,this,parent,self的异同和作用
|
5月前
|
设计模式 算法 PHP
PHP中的设计模式:策略模式的深入探索与实践在软件开发的广袤天地中,PHP以其独特的魅力和强大的功能,成为无数开发者手中的得力工具。而在这条充满挑战与机遇的征途上,设计模式犹如一盏明灯,指引着我们穿越代码的迷雾,编写出更加高效、灵活且易于维护的程序。今天,就让我们聚焦于设计模式中的璀璨明珠——策略模式,深入探讨其在PHP中的实现方法及其实际应用价值。
策略模式,这一设计模式的核心在于它为软件设计带来了一种全新的视角和方法。它允许我们在运行时根据不同情况选择最适合的解决方案,从而极大地提高了程序的灵活性和可扩展性。在PHP这门广泛应用的编程语言中,策略模式同样大放异彩,为开发者们提供了丰富的创作空间。本文将从策略模式的基本概念入手,逐步深入到PHP中的实现细节,并通过一个具体的实例来展示其在实际项目中的应用效果。我们还将探讨策略模式的优势以及在实际应用中可能遇到的挑战和解决方案,为PHP开发者提供一份宝贵的参考。
|
5月前
|
IDE 安全 网络安全
Xdebug 在不同版本的 PHP 中配置方法有什么不同?
Xdebug 在不同版本的 PHP 中配置方法有什么不同?
290 4
|
5月前
|
PHP UED 开发者
PHP中处理异常的现代方法
【9月更文挑战第26天】在PHP的世界里,异常处理是代码健壮性的守护神。本文将深入浅出地探讨如何在PHP项目中优雅地处理异常,从而避免程序崩溃并提升用户体验。
|
6月前
|
PHP 开发工具 git
【Azure 应用服务】在 App Service for Windows 中自定义 PHP 版本的方法
【Azure 应用服务】在 App Service for Windows 中自定义 PHP 版本的方法
|
5月前
|
PHP 开发者
PHP中的魔法方法
本文将介绍PHP中的一些特殊方法,这些方法以双下划线(__)开头,被称为魔术方法或魔法方法。这些方法在特定情况下会自动调用,例如当尝试访问未定义的属性或调用未定义的方法时。本文将详细讲解几个常用的魔术方法,以及如何在实际应用中使用它们来增强PHP代码的可读性和健壮性。
53 0
|
6月前
|
Java 应用服务中间件 PHP
PHP——调用java文件中的方法
PHP——调用java文件中的方法
72 0
PHP——调用java文件中的方法
|
6月前
|
监控 安全 网络安全
PHP代码审计之简单思路方法
PHP代码审计之简单思路方法
175 1

热门文章

最新文章