ubuntu server 10.10 安装配置 nginx + php-fpm + mysql

安装好 ubuntu server 10.10 并升级软件包后,接下来安装 nginx + php-fpm + mysql,10.10 中的 php 已经是自带 php-fpm 的 5.3.3,所以 php-fpm 理所当然成为 fastcgi 的首选。

安装 mysql:

sudo aptitude install mysql-server

使用官方 ppa 安装 nginx:

sudo aptitude install python-software-properties
sudo add-apt-repository ppa:nginx/stable
sudo aptitude update
sudo aptitude install nginx

安装 phpy + php-fpm + 其他模块:

sudo aptitude install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

配置 php:

sudo vi /etc/php5/fpm/php.ini

设置

cgi.fix_pathinfo=0

原因见这里。接下来修改 nginx 虚拟主机设置:

sudo rm -r /etc/nginx/sites-available
sudo rm /etc/nginx/sites/default
sudo vi /etc/nginx/sites/default

内容,我这里 IPv4 和 IPv6 用了两条独立的命令监听,原因见这里

server {
listen   [::]:80;
listen   80;
server_name  xxx.xxxxx.xxx;
root   /var/www/;

#access_log  /var/www/log/xxx-access.log;
#error_log   /var/www/logs/xxx-error.log;

location / {
index  index.php index.html index.htm;
}

#error_page  404  /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page   500 502 503 504  /50x.html;
#location = /50x.html {
#       root   /var/www/nginx-default;
#}

location ~ \.php$ {

fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
include        fastcgi_params;
}

location ~ /\.ht {
deny  all;
}
}

修改 fastcgi 参数,

sudo vi /etc/nginx/fastcgi_params

加入:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO          $fastcgi_script_name;
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;

重新启动 nginx 和 php-fpm,配置完成:

sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm reload

2013.3.24 更新

如果出现 502 Bad Gateway 错误的话,需要进行如下操作

sudo vi /etc/php5/fpm/pool.d/www.conf

找到 listen 字段,改成

listen = 127.0.0.1:9000

This entry was posted in 我的工作学习, 电脑相关 and tagged , , , , , . Bookmark the permalink.

15 Responses to ubuntu server 10.10 安装配置 nginx + php-fpm + mysql

  1. Pingback: Debian Lenny 安装 Nginx + PHP5 FastCGI 笔记 | gkp's post

  2. Jupiter says:

    你好,按照你的步骤安装php是出现如下提示:
    Errors were encountered while processing:
    php5-fpm
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    A package failed to install. Trying to recover:
    Setting up php5-fpm (5.3.3-1ubuntu9) …
    update-rc.d: warning: php5-fpm stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (none)
    * Starting PHP5 FPM…
    PHP Deprecated: Comments starting with ‘#’ are deprecated in /etc/php5/fpm/conf.d/ming.ini on line 1 in Unknown on line 0
    Oct 14 10:08:35.020844 [WARNING] [pool www] pm.start_servers is not set. It’s been set to 20.
    Oct 14 10:08:35.020990 [ERROR] [pool www] the chdir path ‘/var/www’ does not exist or is not a directory
    Oct 14 10:08:35.020997 [ERROR] failed to post process the configuration
    …fail!
    invoke-rc.d: initscript php5-fpm, action “start” failed.
    dpkg: error processing php5-fpm (–configure):
    subprocess installed post-installation script returned error exit status 255
    Errors were encountered while processing:
    php5-fpm
    然后使用sudo mkdir /var/www 解决了期中的一个问题,但另外的两个PHP Deprecated: Comments starting with ‘#’ are deprecated in /etc/php5/fpm/conf.d/ming.ini on line 1 in Unknown on line 0
    Oct 14 10:08:35.020844 [WARNING] [pool www] pm.start_servers is not set. It’s been set to 20.
    没有办法。请教如何可以解决?谢谢!

  3. gkp says:

    都没啥问题的,Deprecated: Comments starting with ‘#’ are deprecated in /etc/php5/fpm/conf.d/ming.ini on line 1 in Unknown on line 0,着个是是说配置文件里面用了#注释,不推荐这样

    Oct 14 10:08:35.020844 [WARNING] [pool www] pm.start_servers is not set. It’s been set to 20.
    着个是php-fpm.conf 里面没设置启动服务器数,用默认的20了

  4. lnginx says:

    请问一下:在ubunut 10.10下如何升级到最新版本的nginx? 目前的版本是0.8.52,我已经尝试过sudo apt-get update,然后是sudo apt-get upgrade,但是无法自动升级到 0.8.53。

    p.s.:如果能自动升级,现有的配置文件、目录会发生变化吗?谢谢!

  5. Pingback: 小就是美 » 最完整及全面的Nginx+php+mysql安装指引

  6. Pingback: PHPer 成长记! » Blog Archive » ubuntu server 10.10 安装配置 nginx + php-fpm + mysql

  7. Pingback: PHPer 成长记! » ubuntu server 10.10 安装配置 nginx + php-fpm + mysql

  8. isher says:

    博主,今天使用nginx+ fpm 和fcgi 搞了一天的时间,最后终于是找到了一个明确的文档了,就是你这篇

    感谢感谢

  9. Магсн says:

    访问不存在的php回返回No input file specified.
    而不是nginx的404
    有神马办法解决不?
    回复请发邮件。。

  10. Pingback: nginx 的安装和php-fpm的关联 | Steno Note

Leave a Reply

Your email address will not be published.