PHP官网www.php.net
当前主流版本为5.6/7.1

cd /usr/local/src/ 
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-5.6.30.tar.gz
cd php-5.6.30
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif 

下面开始漫长的排错过程
Linux学习总结(三十二)lamp之php安装
yum provides xml2-config
yum install -y libxml2-devel
Linux学习总结(三十二)lamp之php安装
yum list |grep -i openssl
yum install -y openssl openssl-devel
Linux学习总结(三十二)lamp之php安装
yum install -y bzip2-devel
Linux学习总结(三十二)lamp之php安装
yum install -y libjpeg-devel
Linux学习总结(三十二)lamp之php安装
yum install -y libpng-devel
Linux学习总结(三十二)lamp之php安装
yum install -y freetype-devel
Linux学习总结(三十二)lamp之php安装
yum install -y epel-release
yum install -y libmcrypt-devel
继续./configure ...
make && make install
cp php.ini-production /usr/local/php/etc/php.ini //拷贝配置文件
安装完成后我们找下看是否生成了我们要的php模块libphp5.so
ls /usr/local/apache2.4/modules/libphp5.so 可以找到
du -sh !$ 查看下它的大小 ,发现36M左右
至此说明我们php安装成功了
php7 安装
方法跟php5相同,就是./configure 时改下安装路径,和配置文件路径

cd /usr/local/src/ 
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar zxf php-7.1.6.tar.bz2
cd php-7.1.6
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc  --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
make && make install

ls /usr/local/apache2.4/modules/libphp*

Linux学习总结(三十二)lamp之php安装
cp php.ini-production /usr/local/php7/etc/php.ini
最后我们把要下载的包总结下:

 yum install -y libxml2-devel
 yum install -y openssl openssl-devel
 yum install -y bzip2-devel
 yum install -y libjpeg-devel
 yum install -y libpng-devel
 yum install -y freetype-devel
 yum install -y epel-release
 yum install -y libmcrypt-devel