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 /tmptar -zxvf php-5.4.13.tar.gzcd ./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 installcp ./php-5.4.13/libs/php.ini /usr/local/php/lib/php.inivi /usr/local/php/lib/php.ini //修改时区为 date.timezone=PRCcd /tmp
6.修改httpd.conf
//加载的模块修改为#LoadModule php5_module /usr/local/php5/lib/libphp5.soLoadModule 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.gztar -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 /tmpwget http://pecl.php.net/get/memcached-2.2.0.tgztar -zxvf memcached-2.2.0.tgzcd ./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
原文地址:https://www.cnblogs.com/wxdblog/p/8561146.html
时间: 2024-10-09 20:41:10