Centos 搭建高性能WEB服务 Nginx+PHP+MYSQL+Discuz论坛
Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。是一个高性能Web和反向代理服务器,它超越 Apache 的高性能和稳定性.
目前 Nginx 的开发版为 0.9.x,稳定版为 0.8.x,历史稳定版为 0.7.x,建议使用 0.8系列作为生产版本。
Nginx 0.8.x + PHP 5.2 可以承受3万以上的并发连接数,相当于同等环境下Apache的10倍
本章将介绍Nginx 0.8 + PHP 5.2 + MYSQL 5 + PHPMyadmin3.3 + Discuz_X1.5 搭建:LNMP+BBS
系统:Centos 5.5 (已装好MYSQL 5.0)
准备工具:
libiconv-1.13.tar.gz
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
mcrypt-2.6.8.tar.gz
mysql-5.1.34.tar.gz (扩展库)
php-5.2.9.tar.gz
php-5.2.9-fpm-0.5.10.diff.gz
nginx-0.8.tar.gz
phpMyAdmin-3.tar.gz
Discuz_X1.5
安装步骤
一、 编译安装PHP5.2.9所需的支持库
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make;make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make;make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make;make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make;make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
(以上这些小步骤就不截图了,安装PHP支持库很简单)
二、编译安装MySQL 5.1.34扩展库 (MYSQL安装步骤 可以在装系统时打勾MYSQL服务装好即可!节约时间!)
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
创建mysql用户和组,我这在装MYSQL时已经自动建了!提示用户存在!
解压MYSQL扩展库,配置
编译安装,需要的时间比较长
添加权限
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ../
三、编译安装PHP
tar zxvf php-5.2.9.tar.gz
gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1
进入PHP目录.指定编译选项安装
cd php-5.2.9/
./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
编译
make ZEND_EXTRA_LIBS='-liconv'
make install
复制php.ini-dist 到指定位置
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
四、修改php-fpm配置文件
删除默认文件,重新建个编辑
输入以下内容:
五、创建www用户和组
六、安装Nginx
七、修改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配置文件
输入以下内容,(自己看着改)
user www www;
worker_processes 8;
error_log /usr/local/webserver/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
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 sky.com;
index index.html index.htm index.php;
root /usr/local/webserver/htdocs/;
#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/webserver/logs/access.log access;
}
}
九、创建日至目录,并赋予权限
创建站点目录
十、配置开机自动启动Nginx + PHP
vi /etc/rc.local
在末尾增加以下内容:
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
十一、平滑启动nginx
十二、安装phpmyadmin
tar zxvf phpMyAdmin-3.tar.gz
修改配置文件
测试网页可以打开PHPmyadmin
创建个BBS数据库和数据库用户
十三、将Discuz论坛程序传到站点上
给站点赋予权限
好了,Discuz论坛就这样搭好了, Nginux 功能是很强的,本章介绍的是单站点,多站点的实现也差不多,修改nginx.conf就可以!