安装PHP5:
安装PHP之前需要把 Apache 安装好才可以。
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz =PHP下载地址(如果失效,那么可以去r.aminglinux 下载最新版本,或者去官网找下载地址)
tar zxvf php-5.6.30.tar.gz = 解压下载包
cd php-5.6.30 = 进入php目录
./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,2,3,4,5,6,7)
make && make install = 继续安装
cp php.ini-production /usr/local/php/etc/php.ini =把production 拷贝到/usr/php/etc/下面
php主要目录 /usr/local/php/ 如果需要重新编译那么直接把主目录删除即可
/usr/local/php/bin/php -m 查看 php 加载的模块,php加载的全部是静态模块
告错1
configure: error: xml2-config not found. Please check your libxml2 installation.
提示:缺少xml2模块
解决方案:
yum list | grep -i xml2 找到 libxml2-devel (64位系统或者32位系统的i686) 然后安装
告错2
configure: error: Cannot find OpenSSL's <evp.h>
解决方案:
yum install openssl openssl-devel
告错3
configure: error: Please reinstall the BZip2 distribution
解决方案:
yum install -y bzip2-devel
告错4
configure: error: jpeglib.h not found.
解决方案:
yum install -y libjpeg-devel
告错5
configure: error: png.h not found.
解决方案:
yum install -y libpng-devel
告错6
configure: error: freetype-config not found.
解决方案:
yum install -y freetype-devel
告错7
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方案:
如果系统里面没有 epel-release 扩展源需要先安装扩展源在安装包
yum install -y libmcrypt-devel
安装PHP7:
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2 =下载PHP包
tar jxf php-7.1.6.tar.bz2 = 解压下载文件(bz2格式,可能会缺bzip2安装包下载一个即可)
cd php-7.1.6 =进入PHP7源码包目录
./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/libphp7.so =查看apache调用的是php5还是php7
cp php.ini-production /usr/local/php7/etc/php.ini =把production 拷贝到/usr/php7/etc/下面
/usr/local/php7/bin/php -m 查看php7加载的模块(和5加载的模块基本一致)
扩展
php中mysql,mysqli,mysqlnd,pdo到底是什么
查看编译参数