编译nginx前,我们需要先安装几个nginx依赖的基础库
安装pcre:
1、切换进编译目录:cd /usr/local/src
2、下载依赖库pcre:wget http://storage.liebian.me/private/linux/pcre-8.37.tar.gz
3、解压:tar xfz pcre-8.37.tar.gz
4、切换:cd pcre-8.37
5、配置:./configure
6、编译:make && make install
安装zlib:
1、切换进编译目录:cd /usr/local/src
2、下载依赖库:wget http://storage.liebian.me/private/linux/zlib-1.2.8.tar.gz
3、解压:tar xfz zlib-1.2.8.tar.gz
4、切换:cd zlib-1.2.8
5、配置:./configure
6、编译:make && make install
安装OpenSSL:
切换进编译目录:cd /usr/local/src
下载:wget http://storage.liebian.me/private/linux/openssl-1.0.2d.tar.gz
解压:tar xfz openssl-1.0.2d.tar.gz
(OpenSSL不用编译,但是编译nginx时,需要configure传路径进去)
编译nginx:
1、切换进编译目录:cd /usr/local/src
2、下载:wget http://storage.liebian.me/private/linux/nginx-1.9.5.tar.gz
3、解压:tar -zxvf nginx-1.9.5.tar.gz
4、切换进去:cd nginx-1.9.5
5、配置nginx编译命令:./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.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2d
6、编译安装:make && make install
7、启动nginx:/usr/local/nginx/nginx
然后,我们开始编译PHP,老样子,先编译依赖库
编译bzip2:
1、切换进编译目录:cd /usr/local/src
2、下载:wget http://storage.liebian.me/private/linux/bzip2-1.0.6.tar.gz
3、解压:tar xfz bzip2-1.0.6.tar.gz
4、切换:cd bzip2-1.0.6
5、编译安装:make && make install
其他依赖库:
CentOS:yum -y install libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel libmcrypt-devel
Debian: apt-get -y install libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libmysqlclient-dev postgresql-server-dev-9.1 libt1-dev libgd2-xpm-dev libgmp-dev libsasl2-dev libmhash-dev unixodbc-dev freetds-dev libpspell-dev libsnmp-dev libtidy-dev libxslt1-dev libmcrypt-dev
注:debian、ubuntu、openlogic等命令不尽相同,见招拆招,请熟练使用百度、谷歌。
开始编译php-fpm
1、切换进编译目录:cd /usr/local/src
2、下载:http://storage.liebian.me/private/linux/php-5.6.10.tar.gz (此地址已失效,请自行寻找有效地址)
3、解压:tar zvxf php-5.6.10.tar.gz
4、切换:cd php-5.6.10
5、配置:./configure --prefix=/usr/local/php --enable-fpm --enable-opcache --enable-ftp -enable-bcmath --enable-mbstring --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --with-pdo-mysql=mysqlnd --with-mcrypt --with-curl --with-bz2 --with-zlib --with-mhash --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir
6、编译安装:make all install
7、编译完安装完后就能在 /usr/local/php 看到了,然后启动 php-fpm 吧,命令:/usr/local/php/sbin/php-fpm
附:
配置nginx支持php:
命令:vi /etc/local/nginx/nginx.conf,在location的后面,加上
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}