源码编译安装 PHP5.6.31 和 Nginx 1.12.0

来源:互联网 发布:淘宝店铺数据分析表格 编辑:程序博客网 时间:2024/06/03 22:43

前言

很久前麦葱写了篇 使用 yum 安装 PHP 和 Nginx 的文章,后来发现有点不方便进行自定义模块的安装,于是最近写了个 用源码编译的脚本,这样就方便多了。

使用

1、准备安装

先安装 epel-release 源,解决部分依赖包找不到的问题,接着使用最快的源地址生成缓存,然后安装依赖包:

yum install -y epel-release
yum makecache fast
yum install -y gcc gcc-c++ perl libpng-devel libjpeg-devel libwebp-devel libXpm-devel libtiff-devel libxml2-devel libcurl-devel libmcrypt-devel fontconfig-devel freetype-devel libzip-devel bzip2-devel gmp-devel readline-devel recode-devel GeoIP-devel bison re2c

2、安装 libiconv、pcre、zlib、libgd、openssl

为了让 PHP 和 Nginx 更高效的运行,完善的编译下去,这里指定安装了几个最新版的相关库。

下载并解压 libiconv

cd /tmp
curl -O –retry 3 https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar -zxf libiconv-1.15.tar.gz

编译

cd libiconv-1.15
./configure –prefix=/usr/local/libiconv
make -j && make install

增加到动态链接库:

echo ‘/usr/local/libiconv/lib’ >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig

下载并解压 pcre

cd /tmp
curl -O –retry 3 https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
tar -zxf pcre-8.40.tar.gz

编译

cd pcre-8.40
./configure –prefix=/usr/local/pcre
make -j && make install

增加到动态链接库

echo ‘/usr/local/pcre/lib’ >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig

下载并解压 zlib

cd /tmp
curl -O –retry 3 http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz

编译

cd zlib-1.2.11
./configure –prefix=/usr/local/zlib
make -j && make install

增加到动态链接库

echo ‘/usr/local/zlib/lib’ >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig

下载并解压 libgd

cd /tmp
curl -O –retry 3 -L https://github.com/libgd/libgd/releases/download/gd-2.2.4/libgd-2.2.4.tar.gz
tar -zxf libgd-2.2.4.tar.gz

编译

cd libgd-2.2.4
./configure \
–prefix=/usr/local/libgd \
–with-libiconv-prefix=/usr/local/libiconv \
–with-zlib=/usr/local/zlib \
–with-jpeg=/usr \
–with-png=/usr \
–with-webp=/usr \
–with-xpm=/usr \
–with-freetype=/usr \
–with-fontconfig=/usr \
–with-tiff=/usr
make -j && make install

增加到动态链接库

echo ‘/usr/local/libgd/lib’ >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig

下载并解压 openssl

cd /tmp
curl -O –retry 3 https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar -zxf openssl-1.0.2k.tar.gz

编译

cd openssl-1.0.2k
./config –prefix=/usr/local/openssl -fPIC
make -j && make install
3、安装 PHP

下载并解压 php

cd /tmp
curl -O –retry 3 http://cn2.php.net/distributions/php-7.1.5.tar.gz
tar -zxf php-7.1.5.tar.gz

编译

cd php-5.6.31

./configure \
–prefix=/usr/local/php56 \
–with-config-file-path=/etc/php56 \
–enable-inline-optimization \
–disable-debug \
–disable-rpath \
–enable-shared \
–enable-opcache \
–enable-fpm \
–with-mysql=mysqlnd \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-gettext \
–enable-mbstring \
–with-iconv \
–with-mcrypt \
–with-mhash \
–with-openssl \
–enable-bcmath \
–enable-soap \
–with-libxml-dir \
–enable-pcntl \
–enable-shmop \
–enable-sysvmsg \
–enable-sysvsem \
–enable-sysvshm \
–enable-sockets \
–with-curl \
–with-zlib \
–enable-zip \
–with-bz2 \
–with-gd \
–with-freetype-dir \
–with-jpeg-dir \
–with-png-dir \
–with-openssl=/usr/local/openssl \
–with-openssl-dir=/usr/local/openssl \
–with-pcre-regex=/usr/local/pcre \
–with-pcre-dir=/usr/local/pcre \
–with-zlib=/usr/local/zlib \
–with-zlib-dir=/usr/local/zlib \
–with-iconv-dir=/usr/local/libiconv \
make -j && make install

增加软链接

ln -sf /usr/local/php71/bin/php /usr/bin/php
ln -sf /usr/local/php71/bin/phpize /usr/bin/phpize
ln -sf /usr/local/php71/sbin/php-fpm /usr/bin/php-fpm

复制 php.ini

cp -v php.ini-production /etc/php71/php.ini
4、安装 Nginx

下载并解压 nginx

cd /tmp
curl -O –retry 3 http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxf nginx-1.12.0.tar.gz

创建缓存目录

mkdir -p /var/cache/nginx12

编译

cd nginx-1.12.0
./configure \
–prefix=/usr/local/nginx12 \
–conf-path=/etc/nginx12/nginx.conf \
–error-log-path=/var/log/nginx12/error.log \
–http-log-path=/var/log/nginx12/access.log \
–pid-path=/var/run/nginx12.pid \
–lock-path=/var/run/nginx12.lock \
–http-client-body-temp-path=/var/cache/nginx12/client_temp \
–http-proxy-temp-path=/var/cache/nginx12/proxy_temp \
–http-fastcgi-temp-path=/var/cache/nginx12/fastcgi_temp \
–http-uwsgi-temp-path=/var/cache/nginx12/uwsgi_temp \
–http-scgi-temp-path=/var/cache/nginx12/scgi_temp \
–user=www \
–group=www \
–with-threads \
–with-file-aio \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_realip_module \
–with-http_addition_module \
–with-http_geoip_module \
–with-http_sub_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_mp4_module \
–with-http_gunzip_module \
–with-http_gzip_static_module \
–with-http_auth_request_module \
–with-http_random_index_module \
–with-http_secure_link_module \
–with-http_degradation_module \
–with-http_slice_module \
–with-http_stub_status_module \
–with-mail \
–with-mail_ssl_module \
–with-stream \
–with-stream_ssl_module \
–with-stream_realip_module \
–with-stream_geoip_module \
–with-stream_ssl_preread_module \
–with-compat \
–with-pcre-jit \
–with-pcre=/usr/local/src/pcre-8.40 \
–with-zlib=/usr/local/src/zlib-1.2.11 \
–with-openssl=/usr/local/src/openssl-1.0.2k
make -j && make install

增加软链接

ln -sf /usr/local/nginx12/sbin/nginx /usr/bin/nginx
配置

PHP 的安装目录在 /usr/local/php56,配置目录在 /etc/php56

将 /etc/php56/php-fpm.conf.default 复制一份为 /etc/php56/php-fpm.conf 用着默认的 php-fpm 配置文件

如果要增加独立的站点配置,可以在 /etc/php56/php-fpm.d 中创建新的 .conf 为后缀的文件,可以参考 LNMP::php-fpm.d

Nginx 的安装目录在 /usr/local/nginx12,配置目录在 /etc/nginx12,Nginx 的配置可以参考 LNMP::nginx

原创粉丝点击