源码编译安装Nginx与PHP

做为PHP的服务器环境很多人选择LAMP,但是在性能上还是LNMP略胜一筹!所以本站的环境是选择了LNMP(Linux+Nginx+PHP),于是就开始源码编译安装Nginx与PHP

一、安装必要的类库和软件

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩


		root@Toka:~# 先安装必要用到的软件
		root@Toka:~# apt-get install vim build-essential libtool
		root@Toka:~# 下载pcre, 并解压
		root@Toka:~# cd /usr/local/src
		root@Toka:~# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
		root@Toka:~# tar -zxvf pcre-8.40.tar.gz
		root@Toka:~# 下载zlib,并解压
		root@Toka:~# wget http://zlib.net/zlib-1.2.11.tar.gz
		root@Toka:~# tar -zxvf zlib-1.2.11.tar.gz
		root@Toka:~# 下载openssl,并解压
		root@Toka:~# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
		root@Toka:~# tar -zxvf openssl-1.0.1c.tar.gz
		root@Toka:~# 
		

pcre和zlib与openssl这个也只解压就好,不要编译安装,编译Nginx时会自动安装

二、源码编译安装Nginx

首先从nginx.org官网最新版本,stable(稳定版)、mainline 版,随意选择,我这里选择的是mainline版本


		root@Toka:~# wget http://nginx.org/download/nginx-1.13.6.tar.gz
		root@Toka:~# tar -zxvf nginx-1.13.6.tar.gz
		root@Toka:~# cd nginx-1.13.6/
		root@Toka:~# #====================下面这两个扩展主要是为了可以代理www.google.com才加的========================
		root@Toka:~# apt install git
		root@Toka:~# cd /usr/local/src/
		root@Toka:~# git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
		root@Toka:~# git clone https://github.com/cuber/ngx_http_google_filter_module
		root@Toka:~# #====================下面两个 -add-module 分别对应上面这两个 ========================
		root@Toka:~# ./configure --sbin-path=/usr/local/nginx/nginx \
		 --conf-path=/usr/local/nginx/nginx.conf \
		 --pid-path=/usr/local/nginx/nginx.pid \
		 --with-http_ssl_module \
		 --with-pcre=/usr/local/src/pcre-8.40 \
		 --with-zlib=/usr/local/src/zlib-1.2.11 \
		 --with-openssl=/usr/local/src/openssl-1.1.0c \
		 --with-http_v2_module \
		 --add-module=/usr/local/src/ngx_http_substitutions_filter_module \
		 --add-module=/usr/local/src/ngx_http_google_filter_module
		root@Toka:~# make  
		sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
		        -e "s|%%PID_PATH%%|/usr/local/nginx/nginx.pid|" \
		        -e "s|%%CONF_PATH%%|/usr/local/nginx/nginx.conf|" \
		        -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
		        < man/nginx.8 > objs/nginx.8
		make[1]: Leaving directory '/root/soft/nginx-1.13.6'
		root@Toka:~# make install
		make -f objs/Makefile install
		make[1]: Entering directory '/root/soft/nginx-1.13.6'
		test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
		test -d '/usr/local/nginx' \
		        || mkdir -p '/usr/local/nginx'
		test ! -f '/usr/local/nginx/nginx' \
		        || mv '/usr/local/nginx/nginx' \
		                '/usr/local/nginx/nginx.old'
		cp objs/nginx '/usr/local/nginx/nginx'
		test -d '/usr/local/nginx' \
		        || mkdir -p '/usr/local/nginx'
		cp conf/koi-win '/usr/local/nginx'
		cp conf/koi-utf '/usr/local/nginx'
		cp conf/win-utf '/usr/local/nginx'
		test -f '/usr/local/nginx/mime.types' \
		        || cp conf/mime.types '/usr/local/nginx'
		cp conf/mime.types '/usr/local/nginx/mime.types.default'
		test -f '/usr/local/nginx/fastcgi_params' \
		        || cp conf/fastcgi_params '/usr/local/nginx'
		cp conf/fastcgi_params \
		        '/usr/local/nginx/fastcgi_params.default'
		test -f '/usr/local/nginx/fastcgi.conf' \
		        || cp conf/fastcgi.conf '/usr/local/nginx'
		cp conf/fastcgi.conf '/usr/local/nginx/fastcgi.conf.default'
		test -f '/usr/local/nginx/uwsgi_params' \
		        || cp conf/uwsgi_params '/usr/local/nginx'
		cp conf/uwsgi_params \
		        '/usr/local/nginx/uwsgi_params.default'
		test -f '/usr/local/nginx/scgi_params' \
		        || cp conf/scgi_params '/usr/local/nginx'
		cp conf/scgi_params \
		        '/usr/local/nginx/scgi_params.default'
		test -f '/usr/local/nginx/nginx.conf' \
		        || cp conf/nginx.conf '/usr/local/nginx/nginx.conf'
		cp conf/nginx.conf '/usr/local/nginx/nginx.conf.default'
		test -d '/usr/local/nginx' \
		        || mkdir -p '/usr/local/nginx'
		test -d '/usr/local/nginx/logs' \
		        || mkdir -p '/usr/local/nginx/logs'
		test -d '/usr/local/nginx/html' \
		        || cp -R html '/usr/local/nginx'
		test -d '/usr/local/nginx/logs' \
		        || mkdir -p '/usr/local/nginx/logs'
		make[1]: Leaving directory '/root/soft/nginx-1.13.6'
		root@Toka:~# 到此nginx安装完成!!
		
三、源码编译安装PHP
请稍等,正在整理…………
三、配置Nginx与PHP