最新的CentOS6.5+Nginx1.4.5+PHP5.5.9线上环境搭建记实

注:本文很多源码包都源自sourceforge.net,我直接wget的时候不允许下载,URL都已经给出具体怎么下载合适,请读者自己做主!本文所有的软件包来源的URL均来官网

1、安装LNMP所依赖的软件包组件

yum -y install gcc gcc-c++ pcre-devel openssl-devel mysql-devel libxml2-devel patch bzip2 bzip2-devel curl-devel libjpeg libjpeg-devel libpng-devel libpng freetype freetype-devel openldap openldap-devel perl-CPAN bison ncurses-devel

2、下载安装libiconv

wget tar xf libiconv-1.14.tar.gzcd libiconv-1.14./configure –prefix=/usr/local/make && make install

3、下载安装libmcrypt(mhash,mcrypt,libmcrypt是我这边线上开发要用的扩展,读者可以自行选择是否安装)

wget cp /root/下载/libmcrypt-2.5.8.tar.gz . sourceforge好像不允许直接wget下载tar xf libmcrypt-2.5.8.tar.bz2cd libmcrypt-2.5.8./configuremake && make install/sbin/ldconfigcd libltdl/./configure –enable-ltdl-installmake &&make install

4、下载安装mhash

wget cp /root/下载/mhash-0.9.9.9.tar.gz .tar xf mhash-0.9.9.9.tar.bz2cd mhash-0.9.9.9./configuremake && make installln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

5、下载安装mcrypt

wget cp /root/下载/mcrypt-2.6.8.tar.gz .tar xf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8/sbin/ldconfig./configuremake && make install

6、添加Nginx运行所需的用户、组

groupadd -r nginxuseradd -r -g nginx nginx

7、下载解压Nginx

wget tar xf nginx-1.4.5.tar.gz

8、为了避免在http响应的时候会出现Nginx等的信息,我们在编译的时候可以稍作配置自定义一个信息!

cd nginx-1.4.5/src/http/vim ngx_http_header_filter_module.c修改以下两行:static char ngx_http_server_string[] = “Server: nginx” CRLF;static char ngx_http_server_full_string[] = “Server: ” NGINX_VER CRLF;修改为:static char ngx_http_server_string[] = “Server: XZWeb 1.0” CRLF;#XZWeb为想要显示的名称static char ngx_http_server_full_string[] = “Server: XZWeb 1.0” NGINX_VER CRLF;#XZWeb为想要显示的名称

9、编译安装Nginx

./configure \ –prefix=/usr \ –sbin-path=/usr/sbin/nginx \ –conf-path=/etc/nginx/nginx.conf \ –error-log-path=/var/log/nginx/error.log \ –http-log-path=/var/log/nginx/access.log \ –pid-path=/var/run/nginx/nginx.pid \ –lock-path=/var/lock/nginx.lock \ –user=nginx \ –group=nginx \ –with-http_ssl_module \ –with-http_flv_module \ –with-http_stub_status_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/ \ –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ –http-scgi-temp-path=/var/tmp/nginx/scgi \ –with-pcremake && make install

10、编写Nginx启动脚本

vim /etc/rc.d/init.d/nginx#!/bin/sh## nginx – this script starts and stops the nginx daemon## chkconfig: – 85 15# description: Nginx is an HTTP(S) server, HTTP(S) reverse \#proxy and IMAP/POP3 proxy server# processname: nginx# config:/etc/nginx/nginx.conf# config:/etc/sysconfig/nginx# pidfile:/var/run/nginx.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ “$NETWORKING” = “no” ] && exit 0nginx=”/usr/sbin/nginx”prog=$(basename $nginx)NGINX_CONF_FILE=”/etc/nginx/nginx.conf”[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() { # make required directories user=`nginx -V 2>&1 | grep “configure arguments:” | sed ‘s/[^*]*–user=\([^ ]*\).*/\1/g’ -` options=`$nginx -V 2>&1 | grep ‘configure arguments:’` for opt in $options; doif [ `echo $opt | grep ‘.*-temp-path’` ]; thenvalue=`echo $opt | cut -d “=” -f 2`if [ ! -d “$value” ]; then# echo “creating” $valuemkdir -p $value && chown -R $user $valuefifi done}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $”Starting $prog: “daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $”Stopping $prog: “killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {configtest || return $?stopsleep 1start}reload() {configtest || return $?echo -n $”Reloading $prog: “killproc $nginx -HUPRETVAL=$?echo}force_reload() {restart}configtest() { $nginx -t -c $NGINX_CONF_FILE}rh_status() {status $prog}rh_status_q() {rh_status >/dev/null 2>&1}case “$1” instart)rh_status_q && exit 0$1;;stop)rh_status_q || exit 0$1;;restart|configtest)$1;;reload)rh_status_q || exit 7$1;;force-reload)force_reload;;status)rh_status;;condrestart|try-restart)rh_status_q || exit 0;;*)echo $”Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}”exit 2esac

11、添加Nginx为系统服务并设置开机自启动

chmod +x /etc/rc.d/init.d/nginxchkconfig –add nginxchkconfig nginx on

12、修改Nginx配置文件,屏蔽http响应信息中的Nginx版本等信息

在http{}端添加server_tokens = off;

人只要不失去方向,就不会失去自己

最新的CentOS6.5+Nginx1.4.5+PHP5.5.9线上环境搭建记实

相关文章:

你感兴趣的文章:

标签云: