安装PHP5 PHP7

安装 PHP5 

PHP官网www.php.net
• 当前主流版本为5.6/7.1
• cd /usr/local/src/wget http://cn2.php.net/distributions/php-5.6.30.tar.gztar zxvf 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

• 问题1
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@centos7 php-5.6.30]# yum list |grep xml2
[root@centos7 php-5.6.30]# yum install -y libxml2-devel.x86_64 

• 问题2
configure: error: Cannot find OpenSSL's <evp.h>
[root@centos7 php-5.6.30]# yum install -y openssl-devel

• 问题3
configure: error: Please reinstall the BZip2 distribution
[root@centos7 php-5.6.30]# yum install -y bzip2-devel

• 问题4
configure: error: jpeglib.h not found.[root@centos7 php-5.6.30]# yum install -y libjpeg-devel

• 问题5
configure: error: png.h not found.
[root@centos7 php-5.6.30]# yum install -y libpng-devel

• 问题6
configure: error: freetype-config not found.
[root@centos7 php-5.6.30]# yum install -y freetype-devel

• 问题7
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
安装epel扩展源[root@centos7 php-5.6.30]# yum install -y epel-release
[root@centos7 php-5.6.30]# yum install -y libmcrypt-devel

• make && make install

• php二进制文件 /usr/local/php/bin/php

• 配置文件[root@centos7 php-5.6.30]# cp php.ini-production  /usr/local/php/etc/php.ini
• cp  php.ini-production  /usr/local/php/etc/php.ini
• php配置信息[root@centos7 php-5.6.30]# /usr/local/php/bin/php -i |less

 安装php7

• cd /usr/local/src/wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2tar jxvf 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 installls /usr/local/apache2.4/modules/libphp7.so
• 查看php加载的模块[root@centos7 php-7.1.6]# /usr/local/php7/bin/php -m
• cp php.ini-production  /usr/local/php7/etc/php.ini
• apacha使用哪一个PHP?
编辑配置文件: vim /usr/local/apache2.4/conf/httpd.conf
搜索php,不想用哪个php版本 注释掉即可。
原文地址:https://www.cnblogs.com/zhaocundang/p/8485364.html