ubuntu11更换php5.3为php5.2的方法

  由于Ubuntu11.10应用sudo apt-get 安装好的php版本是5.3.5,对很多网站源码系统或者需求Zend Optimizer 都还没有开始支持php5.3都是不兼容的,所以必须得降低PHP版本。

降级步骤:

  1、简单新建一个文件名(名称自定义)为php.sh的文件

  2、把以下代码拷贝进去,然后保存。

#!/bin/bash
# by Ruben Barkow (rubo77)

?p=9080474#post9080474
# OK, here's how to do the Apt magic to get PHP packages from the karmic repositories:

echo "Am I root? "
if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then
echo " NO!

Error: You must be root to run this script.
Enter
sudo su
"
exit 1
fi
echo " OK";


#install aptitude before, if you don`t have it:
apt-get install aptitude
# or if you prefer apt-get use:
# alias aptitude='apt-get'

# finish all apt-problems:
aptitude update
aptitude -f install
#apt-get -f install

# remove all your existing PHP packages. You can list them with dpkg -l| grep php
PHPLIST=$(for i in $(dpkg -l | grep php|awk '{ print $2 }' ); do echo $i; done)
echo these pachets will be removed: $PHPLIST
# you need not to purge, if you have upgraded from karmic:
aptitude remove $PHPLIST
# on a fresh install, you need purge:
# aptitude remove --purge $PHPLIST


#Create a file each in /etc/apt/preferences.d like this (call it for example /etc/apt/preferences.d/php5_2);
#
#Package: php5
#Pin: release a=karmic
#Pin-Priority: 991
#
#The big problem is that wildcards don't work, so you will need one such stanza for each PHP package you want to pull from karmic:

echo ''>/etc/apt/preferences.d/php5_2
for i in $PHPLIST ; do echo "Package: $i
Pin: release a=karmic
Pin-Priority: 991
">>/etc/apt/preferences.d/php5_2; done

# duplicate your existing sources.list replacing lucid with karmic and save it in sources.list.d:
#sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list

# better exactly only the needed sources, cause otherwise you can get a cachsize problem:
echo "# needed sources vor php5.2:
deb karmic main restricted
deb-src karmic main restricted

deb karmic-updates main restricted
deb-src karmic-updates main restricted

deb karmic universe
deb-src karmic universe
deb karmic-updates universe
deb-src karmic-updates universe

deb karmic multiverse
deb-src karmic multiverse
deb karmic-updates multiverse
deb-src karmic-updates multiverse

deb karmic-security main restricted
deb-src karmic-security main restricted
deb karmic-security universe
deb-src karmic-security universe
deb karmic-security multiverse
deb-src karmic-security multiverse
" > /etc/apt/sources.list.d/karmic.list

aptitude update

apache2ctl restart

echo install new from karmic:
aptitude -t karmic install $PHPLIST

# at the end retry the modul libapache2-mod-php5 in case it didn't work the first time:
aptitude -t karmic install libapache2-mod-php5

apache2ctl restart

  3、把php.sh文件上传到root权限目录下。权限改为777,呵呵,省事。。。

  4、在root权限下执行代码 sh php.sh

  5、哈哈,执行过程中会遇到选择[Y/N]步骤,直接Y回车就行

  6、执行完后直接 /etc/init.d/apache2 restart 重启apache2即可,再phpinfo()看看,版本就成功降级了,测试多次,都成功了

  若遇到不成功的可能是网页代码转换造成不完整,可以到CSDN下载一个现成的php.sh文件,地址:

感谢XYCMS企业建站的投稿

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/10912.html