一、安装PHP5
1、官网:www.php.net 当前主流版本5.6/7.1
2、cd /usr/local/src
3、wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
4、解压:tar -jxvf php-5.6.32.tar.bz2
5、cd php-5.6.32/
6、 编译
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/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-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: freetype-config not found
解决方案:
centos: yum install freetype-devel
debian: apt-get install libfreetype6-dev
遇到错误2:configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解决方案: cenos: yum install libmcrypt libmcrypt-devel 遇到错误3:configure: error: Cannot find OpenSSL's <evp.h> 解决方案: yum install openssl openssl-devel
遇到错误4:configure: error: Please reinstall the BZip2 distribution 解决方案:yum install -y bzip2-devel
遇到错误5:configure: error: jpeglib.h not found. 解决方案:yum -y install libjpeg-devel
遇到错误6:configure: error: png.h not found 解决方案:yum install libpng-devel
遇到错误7: configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解决方案: yum -y install epel-release yum -y install php-mcrypt yum -y install libmcrypt-devel
有时候yum库估计有时候搜索不到libmcrypt. 因此源码安装是最实用的办法,最原生的东西.
遇到错误8:The output of /usr/local/apache/bin/apxs follows:./configure: line 6669: /usr/local/apache/bin/apxs: No such file or directoryconfigure: error: Aborting 解决方案: yum install -y perl* yum install -y httpd-devel find / -name apxs 得到的路径是:/usr/sbin/apxs 于是修改--with-apsx2=/usr/sbin/apxs指定到正确路径
7、echo $? 检查编译是否成功 8、make & make install /configure 后,直接make可能会出现libtool: link: `ext/date/php_date.lo' is not a valid libtool object 的错误 make clean 一下然后再make,即可。原因未知,可能是某些脚本执行顺序的问题? 9、查看/usr/local/php/及/usr/local/php/bin 目录 : ls /usr/local/php/ 它的核心位置:/bin 目录 ,查看大小 du -sh /usr/local/php/bin/bin/ 10、php和apache结合的扩展模块目录,就算你删除php目录,也没有关系,因为它们所要的就是libphp5.so这个模块,apache和php就是用这个文件 /usr/local/apache/modules/libphp5.so 11、php它所加载的模块有哪些:/usr/local/php/bin/php -m
12、cp php.ini-production /usr/local/php/etc/php.ini 这是配制文件所在的路径 /usr/local/php/bin/php -i |less 查php的一些信息,包括编译参数,及configuration file的路径。这个目录是空的,所以cp,cp完之后再用这条命令查看就有了
二、安装php7 1、cd /usr/local/src 2、wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2 3、解压 4、cd php-7.1.6 4、编译:
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache/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
6、make & makeinstall 7、查看apache加载了几个php ,/usr/local/apache/bin/apachectl -M 8、想用哪一个 就要去改配制文件:vim /usr/local/apache/conf/httpd.conf 查找到php5.so 或php7.so 不想用哪一个就注释掉哪一个