登录到php官网:https://www.php.net/downloads.php
点击右侧的Old archives链接
然后向下滚动找到php5.6.20下载
1.先安装依赖包
需要先安装httpd的一些开发库,包括手册,工具和开发库
yum install httpd httpd-manual httpd-tools httpd-devel
yum install -y gcc gcc-c++ libcurl-devel libxslt libxslt-devel libicu-devel make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
yum install -y ntp make freetype freetype-devel gd zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel imake autoconf automake screen sysstat
2.到rpm包下执行 rpm -ivh openssl-develxxxxxx.rpm --nodeps
3.执行 ln -s /usr/lib64/libssl.so /usr/lib/,否则会报Cannot find OpenSSL's <evp.h>错误
4.编译安装libmencrypt,libiconv,这两个库编译起来比较简单,./configure,make,make install,可以在configure阶段通过--prefix参数指定安装的目标路径,推荐全部安装到/usr下面,免去后续编译上的麻烦。
5.开始编译,进入到php5.6源代码根目录,这个编译生成选项开启了绝大部分的php扩展支持
./configure --prefix=/usr/local/php5620 --with-config-file-path=/usr/local/php5620/etc --with-xmlrpc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=www --enable-sockets --with-bz2 --enable-inline-optimization --enable-calendar --with-libxml-dir=/usr --with-freetype-dir --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-opcache --enable-mbstring --enable-soap --enable-zip --enable-bcmath --with-openssl --with-zlib --with-curl --with-gd --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --with-openssl --with-fpm-user=www56 --with-fpm-group=www56 --with-libdir=/lib/x86_64-linux-gnu/ --enable-ftp --with-gettext --with-xsl --enable-opcache --enable-fpm --with-xpm-dir=/usr --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --with-zlib-dir=/usr/lib --with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-mhash --with-apxs2=/usr/bin/apxs
这里面需要特别说明的是执行完上面的操作以后,执行make的时候会提示找不到 libiconv库或者提示重新安装libiconv这个库,实际上是生成的Makefile脚本本身有毛病,需要自行添加对于该库的引用
然后执行make
没有错误继续执行make install
php会被安装到目标路径/user/local/php5620当中
将源代码目录下面的php.ini-production拷贝到/usr/local/php5620/etc/php.ini
修改 apache的配置文件httpd.conf,这个文件一般默认在/etc/httpd/conf.d/当中
在其中加入LoadModulephp5_module modules/libphp5.so,正常情况下,我们编译安装php源代码的时候会自动将这行脚本插入进来,所以要看看是否是重复加入,否则,httpd服务启动的时候会报错
再在这个文件添加两行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到 DirectoryIndex index.html这行,再加入index.php索引文件
6.在http://pecl.php.net/package/redis下载4.3.0版本redis扩展源代码 ,对于大部分服务器都会采用redis作为缓存服务器,在此为php增加redis扩展模块
7.解压源代码
进入源代码根目录,执行/usr/local/php/bin/phpize 生成configure
8. ./configure --with-php-config=/usr/local/php/bin/php-config
然后执行
make
make install
9.执行完毕后得到一个新编译好的redis扩展库的路径,将这个扩展库配置到php.ini中去,只需要在文件末尾加上 extension="radis.so",确保该行前面没有分号“;”