分类: 系统运维
2014-08-14 14:44:57
nginx 优点太多了google会有一大堆 这里就不罗嗦了,下面主要讲的lnmp安装整合等等,软件都是目前比较新的稳定版本!整个安装过程将整理成安装脚本。
nginx 需要一些第三方库的支持,比如gzip模块 需要zlib库,还有我们最常用的rewrite模块需要pcre库,根据需要需先安装这些库。
nginx 与 pcre 关系: rewrite(需要) <--- 正则表达式(需要) <--- pcre 库 (Perl Compatible Regular Expressions)
————————————————————————————
后续文章
nginx_笔记分享_4_从301重定向开始(rewrite)
————————————————————————————
环境
系 统 centos 5.5 64bit
软件包(主要)
nginx-1.0.5.tar.gz
mysql-5.1.56.tar.gz
php-5.3.6.tar.gz
一 nginx 部分
#首先安装pcre,因为nginx 依赖于 pcre
tar zxf pcre-8.12.tar.gz
cd pcre-8.12
./configure --prefix=/urs/local/pcre && make && make install
cd ../
#安装openssl,openssl不需要安装,解包移到/urs/local/下即可(可选)
tar zxf openssl-1.0.0d.tar.gz
mv openssl-1.0.0d /urs/local/openssl
#安装nginx,注意pcre是源码包目录,而不是安装过的pcre目录,我安装时出错了
useradd nginx -s /sbin/nologin #添加nginx用户和组
tar -zxf nginx-1.0.5.tar.gz
cd nginx*/
./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.12/ --with-openssl=/usr/local/openssl/ \
--with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --user=nginx --group=nginx
make && make install
cd ../
二 mysql 部分
./mysql_server.sh #下载mysq安装脚本
三 php 部分
#安装 freetype
tar xzf freetype-2.3.5.tar.gz
cd freetype*/
./configure --prefix=/usr/local/freetype
make && make install && make clean
cd ../
#安装 curl
tar curl-7.19.2.tar.gz
cd curl*/
./configure --prefix=/usr/local/curl
make && make install
cd ../
#安装 libiconv
tar xzf libiconv-1.13.1.gz
cd libiconv*/
./configure --prefix=/usr/local/libiconv
make && make install
cd ../
#安装 libpng
tar xzf libpng-1.2.29.tar.gz
cd libpng*/
./configure --prefix=/usr/local/libpng
make && make install
cd ../
#安装 jpeg
tar xzf jpegsrc.v6b.tar.gz
cd jpeg*/
./configure --prefix=/usr/local/libjpeg
sed -i 's/CFLAGS\= -O2 -I\$(srcdir)/CFLAGS\= -O3 -I\$(srcdir) -fPIC/g' Makefile
mkdir -p /usr/local/libjpeg/include
mkdir -p /usr/local/libjpeg/lib
mkdir -p /usr/local/libjpeg/bin
mkdir -p /usr/local/libjpeg/man/man1
make && make install-lib && make install
cd ../
#最后安装php5.3.6 (已经包含了 php-fpm)
tar zxf php-5.3.6.tar.gz
cd php*/
./configure --prefix=/usr/local/php --with-config-file-path=/etc/ --with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-curl=/usr/local/curl \
--with-libxml-dir=/usr/include/libxml2 --with-gd --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr/local/libpng \
--with-bz2 --with-freetype-dir=/usr/local/freetype --with-iconv-dir=/usr/local/libiconv \
--with-zlib-dir --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-exif \
--enable-dba --disable-ipv6 --disable-cgi --enable-bcmath --enable-sockets --enable-mbstring --enable-fpm
make && make install
cd ../
拷贝配置文件
! grep 'php' /etc/profile && echo "export
PATH=\$PATH:/usr/local/php/bin" >> /etc/profile && source
/etc/profile
! grep 'php-fpm' /etc/profile && echo "export
PATH=\$PATH:/usr/local/php/sbin" >> /etc/profile && source
/etc/profile
cp php*/php.ini-development /etc/php.ini
cp php*/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod 755 /etc/init.d/php-fpm
sed -i 's/;pm.start_servers = 20/pm.start_servers = 20/' /usr/local/php/etc/php-fpm.conf.default
sed -i 's/;pm.min_spare_servers = 5/pm.min_spare_servers = 5/' /usr/local/php/etc/php-fpm.conf.default
sed -i 's/;pm.max_spare_servers = 35/pm.max_spare_servers = 35/' /usr/local/php/etc/php-fpm.conf.default
sed -i 's/;pm.max_requests = 500/pm.max_requests = 500/' /usr/local/php/etc/php-fpm.conf.default
cp /usr/local/php/etc/php-fpm.conf.default" /usr/local/php/etc/php-fpm.conf"
四 nginx 与 php 整合
编辑 /usr/local/nginx/conf/nginx.conf
类似下面
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
五 常用的基础命令
[root@slave logs]# nginx -h
nginx: nginx version: nginx/1.0.5
nginx: Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help #使用帮助
-v : show version and exit #版本号
-V : show version and configure options then exit #显示configure 的配置参数
-t : test configuration and exit #测试配置文件是否正确
...........
测试 nginx /usr/local/nginx/sbin/nginx -t
启动 nginx /usr/local/nginx/sbin/nginx
关闭 nginx /usr/local/nginx/sbin/nginx -s stop
重载 nginx /usr/local/nginx/sbin/nginx -s reload
[root@slave logs]# /etc/init.d/php-fpm
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload} #启动|关闭|强制退出|重启|重载配置文件
启动 php-fpm /etc/init.d/php-fpm start
关闭 php-fpm /etc/init.d/php-fpm stop
重启 php-fpm /etc/init.d/php-fpm restart
设置开机启动
echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local
chkconfig php-fpm on