在Ubuntu/Debian上快速安装PHP-fpm 5.3和Nginx

寻常白昼 2010-03-26

今天又搞了VPS玩,可惜的是他们并不提供archlinux的系统,没办法只好选择Debian了,但是lenny中的PHP版本都太老了些,更不可能包含fpm了,也不想再浪费时间自己编译了,于是google一把后找到了一个提供PHP-fpm 5.3的源,而且常用的模块都有提供,所以就直接安装了,简单记录下安装过程。

1、安装Nginx
Nginx版本不需要太新,用官方源里的就很好,起码够稳定

sudo apt-get install nginx简单编辑下它的默认配置,一会儿来测试能否与PHP正常的工作

sudo vim /etc/nginx/sites-available/default改完后它看起来差不多是这个样子

server {
    listen   80;
    server_name  localhost;
    access_log  /var/log/nginx/localhost.access.log;
 
## Default location
    location / {
        root   /var/www;
        index  index.php;
    }
 
## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        off;
      expires           30d;
      root /var/www;
    }
 
## Parse all .php file in the /var/www directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        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;
    }
 
## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}
2、准备工作
如果用的是Ubuntu系统的话需要手动安装两个包、Debian则不需要

cd /tmp
wget http://us.archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb53_1.6.dfsg.4~beta1-5ubuntu2_i386.deb
wget http://us.archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu38_3.8-6ubuntu0.2_i386.deb
sudo dpkg -i *.deb如果用的amd64的系统请将以上两个包中的i386改为amd64
3、添加非官方源,安装PHP-fpm

sudo echo "deb http://php53.dotdeb.org stable all" >> /etc/apt/sources.list更新源

sudo apt-get update安装PHP环境

sudo apt-get install php5-cli php5-common php5-suhosin上面安装的是CLI的PHP,接下来安装CGI、fpm

sudo apt-get install php5-fpm php5-cgi需要其他的模块或者扩展可以自行安装,这里列举下这个源里提供的所有模块与扩展

php5-curl_5.3.2-0.dotdeb.1_i386.deb
php5-dbg_5.3.2-0.dotdeb.1_i386.deb
php5-dev_5.3.2-0.dotdeb.1_i386.deb
php5-enchant_5.3.2-0.dotdeb.1_i386.deb
php5-fpm_5.3.2-0.dotdeb.1_i386.deb
php5-gd_5.3.2-0.dotdeb.1_i386.deb
php5-gmp_5.3.2-0.dotdeb.1_i386.deb
php5-imap_5.3.2-0.dotdeb.1_i386.deb
php5-interbase_5.3.2-0.dotdeb.1_i386.deb
php5-ldap_5.3.2-0.dotdeb.1_i386.deb
php5-mcrypt_5.3.2-0.dotdeb.1_i386.deb
php5-mysql_5.3.2-0.dotdeb.1_i386.deb
php5-odbc_5.3.2-0.dotdeb.1_i386.deb
php5-pgsql_5.3.2-0.dotdeb.1_i386.deb
php5-pspell_5.3.2-0.dotdeb.1_i386.deb
php5-recode_5.3.2-0.dotdeb.1_i386.deb
php5-snmp_5.3.2-0.dotdeb.1_i386.deb
php5-sqlite_5.3.2-0.dotdeb.1_i386.deb
php5-sybase_5.3.2-0.dotdeb.1_i386.deb
php5-tidy_5.3.2-0.dotdeb.1_i386.deb
php5-xmlrpc_5.3.2-0.dotdeb.1_i386.deb
php5-xsl_5.3.2-0.dotdeb.1_i386.deb
php5_5.3.2-0.dotdeb.1_all.deb
php5-apc_5.3.2-0.dotdeb.1_i386.deb
php5-ffmpeg_5.3.2-0.dotdeb.1_i386.deb
php5-geoip_5.3.2-0.dotdeb.1_i386.deb
php5-http_5.3.2-0.dotdeb.1_i386.deb
php5-imagick_5.3.2-0.dotdeb.1_i386.deb
php5-memcache_5.3.2-0.dotdeb.1_i386.deb
php5-spplus_5.3.2-0.dotdeb.1_i386.deb
php5-ssh2_5.3.2-0.dotdeb.1_i386.deb
php5-suhosin_5.3.2-0.dotdeb.1_i386.deb
php5-xcache_5.3.2-0.dotdeb.1_i386.deb
php5-xdebug_5.3.2-0.dotdeb.1_i386.deb

4、测试运行
启动Nginx与PHP-Fpm

sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart接下来在/var/www/下建立个index.php文件,然后写入PHP的测试函数

<?php phpinfo(); ?>然后访问,出现PHP环境信息则表示运行正常
查看错误信息

sudo tail /var/log/nginx/error.log

相关推荐

林悠居 / 0评论 2020-05-19
84931231 / 0评论 2020-05-14