1. 将原来的 PHP 重命名一下
- cd /usr/local/bin/
- mv php php.2.9
2. 安装依赖
yum install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
报错, centos 版本太老了, 5.5,yum 源已经不可用了
3. 更换 yum 源, 参考 http://www.baddb.com/511.html
- // 通过修改 CentOS-Base.repo 文件中的源地址来处理
- vi /etc/yum.repos.d/CentOS-Base.repo
将原来的 baseurl 更改为新的, 最终将内容更改为:
- # CentOS-Base.repo
- #
- # The mirror system uses the connecting IP address of the client and the
- # update status of each mirror to pick mirrors that are updated to and
- # geographically close to the client. You should use this for CentOS updates
- # unless you are manually picking other mirrors.
- #
- # If the mirrorlist= does not work for you, as a fall back you can try the
- # remarked out baseurl= line instead.
- #
- #
- [base]
- name=CentOS-$releasever - Base
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
- #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
- baseurl=http://vault.centos.org/5.11/os/$basearch/
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
- #released updates
- [updates]
- name=CentOS-$releasever - Updates
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
- #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
- baseurl=http://vault.centos.org/5.11/updates/$basearch/
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
- #additional packages that may be useful
- [extras]
- name=CentOS-$releasever - Extras
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
- #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
- baseurl=http://vault.centos.org/5.11/extras/$basearch/
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
- #additional packages that extend functionality of existing packages
- [centosplus]
- name=CentOS-$releasever - Plus
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
- #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
- baseurl=http://vault.centos.org/5.11/centosplus/$basearch/
- gpgcheck=1
- enabled=0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
- #contrib - packages by Centos Users
- [contrib]
- name=CentOS-$releasever - Contrib
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
- #baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
- baseurl=http://vault.centos.org/5.11/contrib/$basearch/
- gpgcheck=1
- enabled=0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
4. 继续安装依赖
- yum install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
- yum install -y libc-client-devel
5. 进入你放 PHP 安装包的路径, 我的是在 tmp 下面
- cd /tmp
- tar -zxvf php-5.4.13.tar.gz
- cd ./php-5.4.13
- // 编译命令
- ./configure --prefix=/usr/local/php --with-apxs2=/tongfu.net/env/apache22/bin/apxs --with-zlib --with-kerberos --with-mysql --with-mysqli --with-pdo-mysql --enable-mbstring --with-curl --with-gd --with-imap=../imap-2007e --with-imap-ssl --with-png-dir=/usr/lib64 --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64
- // 安装
- make && make install
- cp ./php-5.4.13/libs/php.ini /usr/local/php/lib/php.ini
- vi /usr/local/php/lib/php.ini
- // 修改时区为
- date.timezone=PRC
- cd /tmp
6. 修改 httpd.conf
- // 加载的模块修改为
- #LoadModule php5_module /usr/local/php5/lib/libphp5.so
- LoadModule php5_module /usr/local/php/lib/libphp5.so
7. 查看扩展情况
- // 查看 PHP 安装的扩展情况
- /usr/local/php/bin/php -m
8. 发现没有 memcache,memcached,redis 扩展, 安装扩展
- /usr/local/php/bin/pecl install memcache
- /usr/local/php/bin/pecl install memcached-2.2.0
9. 安装 memcached 扩展失败, 缺少 libmemcached, 处理方法 (参考: https://www.cnblogs.com/dyllove98/archive/2014/11/27/4126840.html):
- wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
- tar -zxf libmemcached-1.0.18.tar.gz
- cd ./libmemcached-1.0.18
- // 编译安装
- ./configure --prefix=/usr/local/libmemcached --with-memcached // 注意:--with-memcached 这个选项一定要加上
- make && make install
10. 安装 memcached 扩展
- cd /tmp
- wget http://pecl.php.net/get/memcached-2.2.0.tgz
- tar -zxvf memcached-2.2.0.tgz
- cd ./memcached-2.2.0
- // 进入解包后的目录, 先使用 phpize 命令生成一个 configure 文件
- /usr/local/php/bin/phpize// 这个命令在编译安装 php 时会在安装目录下的 bin 目录下, 但是在 yum 安装的 php 中需要安装一个名叫 php-devel 的包才会有 (我在这里被坑过)
- ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached // 此处的 php-config 如果不知道在哪里的话可以用 find / -name php-config 命令找一下
- make && make install
11. 安装 redis 扩展
/usr/local/php/bin/pecl install redis
12. 将扩展加入 php.ini
- vi /usr/local/php/lib/php.ini
- // 加入
- extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525"
- extension = "memcache.so"
- extension = "memcached.so"
- extension = "redis.so"
13. 重启 apache
service httpd restart// 或者找到 apachectl restart
来源: http://www.bubuko.com/infodetail-2526466.html