给服务器安装php版本,线上服务器PHP版本编译安装升级全记录

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值