当前主流版本为5.6/7.1
下载php
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 // --with-apxs2 apache的一种工具,它可以自动的将扩展模块放到apache的modules目录下,并且在它的配置文件里加上一行 //--with-config-file-path 指定php配置文件的路径 //--with-mysql 指定mysql路径
编译安装
make && make install
安装报错:
错误1: configure: error: xml2-config not found. Please check your libxml2 installation. 解决办法: yum install -y libxml2-devel
错误2: checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution 解决办法: yum install -y bzip2-devel
错误3: configure: error: jpeglib.h not found. 解决办法: yum install -y libjpeg-turbo-devel
错误4: configure: error: png.h not found. 解决办法: yum install -y libpng libpng-devel
错误5: configure: error: freetype-config not found. 解决办法: yum install -y freetype freetype-devel
错误6: configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解决办法: yum install -y epel-release yum install -y libmcrypt libmcrypt-devel
拷贝配置文件
cp php.ini-production /usr/local/php/etc/php.ini
libphp5.so
du -sh /usr/local/apache2.4/modules/libphp5.so 37M /usr/local/apache2.4/modules/libphp5.so 这个就是我们想要的扩展模块,apache和php相结合是通过.so
查看加载的模块
/usr/local/php/bin/php -m