### 首先获取并解压PHP安装包
~~~
cd /usr/local/src/
#wget http://hk1.php.net/get/php-7.1.26.tar.gz/from/this/mirror
#wget http://php.net/get/php-7.1.26.tar.gz/from/a/mirror
wget http://hk2.php.net/get/php-7.1.26.tar.gz/from/this/mirror
tar zxvf mirror
cd php-7.1.26
@http://cn2.php.net是中国网站,mirror也是压缩包,下载后解压获得所有php文件
~~~
### 安装工具和相应扩展
~~~
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel re2c
~~~
### 开始编译PHP
> ./configure的作用是检测系统配置,生成makefile文件,以便你可以用make和make install来编译和安装程序
~~~
cd php-7.1.26
make clean
./configure \
--with-config-file-path=/etc/php \
--prefix=/usr/local/php \
--enable-fpm \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-opcache \
--with-mysqli \
--with-pdo-mysql \
--enable-bcmath \
--enable-mbstring \
--enable-sockets \
--with-gd \
--with-freetype-dir=/usr/include/freetype2 \
--with-openssl \
--with-curl \
--with-gettext
---------------分割线,使用上面的------------------------
--with-curl=/usr/local/curl \
--with-freetype-dir=/usr/include/freetype2 \
--with-curl=/usr/local/curl \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
~~~
### 没出现错误就可以开始编译了
~~~
make && make install
~~~
### php配置文件的路径已经指定到usr/local/etc
~~~
> 只需要复制源码中的
php.ini-development
> 或者
php.ini-production
到usr/local/etc目录下即可,vi打开需要的扩展包
cp php.ini-development /usr/local/php/etc/php.ini
~~~
### 环境变量
~~~
vi /root/.bash_profile
> 加上环境变量
:/usr/local/php/bin
source /root/.bash_profile
~~~