安装Nginx并在其下安装PHP

zenwong 2010-02-16 10:08:24
原地址:http://doc.zenw.org/linux/ch02s02.html


文中应用了网络上的部分文章内容,如果有不正确的地方请指出,谢谢


Nginx
安装Nginx

首先要编译安装PHP和PHP-FPM,具体方法在下面,见:编译安装PHP(建议在安装Nginx前进行)

tar zxvf nginx-0.8.15.tar.gz
cd nginx-0.8.15/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install


在/usr/local/nginx/conf/目录中创建nginx.conf文件

#备份原来有的配置文件
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.BAK
vi /usr/local/nginx/conf/nginx.conf

内容如下

user www www;

worker_processes 8;

error_log /usr/local/nginx/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 wiki.zenw.org;
index index.html index.htm index.php;
root /web/htdocs/www;

#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 /usr/local/nginx/logs/access.log access;
}

server
{
listen 80;
server_name www.zenw.org;
index index.html index.htm index.php;
root /web/htdocs/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 /usr/local/nginx/logs/wwwlogs.log wwwlogs;
}

server
{
listen 80;
server_name blog.zenw.org;

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


在/usr/local/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;

启动Nginx

ulimit -SHn 65535
/usr/local/nginx/sbin/nginx


配置开机自动启动Nginx + PHP

vi /etc/rc.local

在末尾增加以下内容:

ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx

当然,你也可以使用lighttpd的spawn-fcgi来管理php-cgi(FastCGI)


编译安装PHP

(建议在安装Nginx前进行)

注:php-fpm可以在 http://php-fpm.org/download 下载


tar zxvf php-5.2.10.tar.gz

gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1

cd php-5.2.10/

./configure --prefix=/usr/local/webserver/php \
--with-config-file-path=/usr/local/webserver/php/etc \
--with-mysql=/usr/local/webserver/mysql \
--with-mysqli=/usr/local/webserver/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear

make ZEND_EXTRA_LIBS='-liconv'
make install

cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../

curl http://pear.php.net/go-pear | /usr/local/webserver/php/bin/php


更多内容可访问:
http://www.zenw.org
http://doc.zenw.org
http://doc.zenw.org/linux
http://doc.zenw.org/mysql
http://doc.zenw.org/developer
...全文
56 3 打赏 收藏 转发到动态 举报
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zenwong 2010-02-17
  • 打赏
  • 举报
回复
因为感觉CSDN的BBS分类不太准确,所以不知道我这种文章具体属于哪个版块,就多发了,见谅。
cs5276 2010-02-17
  • 打赏
  • 举报
回复
版主呢?

感谢分享。。
街头小贩 2010-02-17
  • 打赏
  • 举报
回复
新手学习
相关推荐

5,644

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告