Debian/Ubuntu里安装Nginx+PHP(spawn-fcgi)+MySQL

123 篇文章 0 订阅

作者:

转自:http://www.ha97.com/965.html


在服务器上一直用的都是CentOS系统,我这次试了下Debian。其实在国外,Debian在服务器领域的使用率占Linux的40%多。

下面是Debian里安装nginx+php(spawn-fcgi)+mysql的记录与总结:

1. 首先是添加源地址,因为我要安装最新稳定版的软件,Debian默认的软件版本比较老。

vim /etc/apt/sources.list

增加下面的行:

deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

(下面安装的过程中会提示“软件不能通过验证”之类的,因为不是官方的源,才会这样提示。按y确认就可以!)

2. 接着,更新系统软件包。

apt-get update
apt-get dist-upgrade(不想更新内核的用apt-get upgrade)

3. 接着是PHP5,根据自己的需要选择安装PHP5的扩展。

apt-get install php5-common php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-apc

4. 下面是安装mysql5.1,安装过程会需要你输入root密码的

apt-get install mysql-server-5.1
/etc/init.d/mysql start
/etc/init.d/mysql stop

5. 安装nginx及其依赖软件包:

apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev build-essential nginx

源里的nginx版本是0.6.32,有点老,可以去nginx官方下载最新的稳定版源码包编译安装,方法如下:

wget http://nginx.org/download/nginx-0.8.37.tar.gz
tar zxvf nginx-0.8.37.tar.gz
cd nginx-0.8.37/
./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-http_ssl_module
make
make install
cd ../

6. 最后安装spawn-fcgi,用来启动PHP的FastCGI模式

wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -zxf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure –bindir=/usr/bin –libdir=/usr/lib –prefix=/etc
make&&make install

7. 启动方法:

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 8 -u www -g www -f “/usr/bin/php5-cgi -d /var/www”
/usr/local/nginx/sbin/nginx

配置开机自动启动Nginx+PHP:vim /etc/rc.local 在末尾增加以上内容即可。

nginx配置文件请参考:(里面的目录路径请根据实际情况修改。

user www www;worker_processes 8;

error_log /var/www//logs/nginx_error.log crit;

pid /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events
{
use epoll;
worker_connections 65535;
}

http
{
include mime.types;
default_type application/octet-stream;

#charset gb2312;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;

server
{
listen 80;
server_name blog.ha97.com;
index index.html index.htm index.php;
root /var/www/nginx-default/blog;

#limit_conn crawler 20;

location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 1h;
}

log_format access ’$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /var/www/logs/access.log access;
}

server
{
listen 80;
server_name www.ha97.com;
index index.html index.htm index.php;
root /var/www/nginx-default/www;

location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

log_format wwwlogs ’$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /var/www/logs/wwwlogs.log wwwlogs;
}

server
{
listen 80;
server_name status.ha97.com;

location / {
stub_status on;
access_log off;
}
}
}

nginx.conf配置文件的目录中创建fcgi.conf文件,输入以下内容:

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;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_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

Ubuntu源于Debian,以上配置在Ubuntu上也基本适用。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值