#-----------------------------CentOS 5.x版本升级PHP------------------
#! /bin/sh
#1.关闭selinux
cp -rp /etc/selinux/config /etc/selinux/config.bak
setenforce 0
sed -i '7s/enforcing/disabled/' /etc/selinux/config
#2.显示selinux的状态 Permissive为关闭
getenforce
#3.判断系统的版本
if [ "$(uname -i)" = i386 ]; then
# 如果服务器是32位,那么运行如下命令
echo "开始下载第三方remi库 i386"
wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
else
## 如果是64位的 那么运行以下命令
echo "下载第三方remi库 X64"
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
fi
#4.修改remi.repo的配置文件 如果只想升级到php5.4.x,那么就把[remi]部分的enabled改为1
#如果想升级到php5.5.x,那么就把[remi]和[remi-php55]部分的enabled都改为1
cp -rp /etc/yum.repos.d/remi.repo /etc/yum.repos.d/remi.repo.bak
sed -i '9s/enabled=0/enabled=1/' /etc/yum.repos.d/remi.repo
sed -i '18s/enabled=0/enabled=1/' /etc/yum.repos.d/remi.repo
sed -i '7s/^#//' /etc/yum.repos.d/remi.repo
sed -i '8s/^/#&/' /etc/yum.repos.d/remi.repo
sed -i '15s/^#//' /etc/yum.repos.d/remi.repo
sed -i '16s/^/#&/' /etc/yum.repos.d/remi.repo
#修改下面epel.repo的配置文件信息 不然会报错
cp -rp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
sed -i '3s/^#//' /etc/yum.repos.d/epel.repo
sed -i '12s/^#//' /etc/yum.repos.d/epel.repo
sed -i '21s/^#//' /etc/yum.repos.d/epel.repo
sed -i '4s/^/#&/' /etc/yum.repos.d/epel.repo
sed -i '13s/^/#&/' /etc/yum.repos.d/epel.repo
sed -i '22s/^/#&/' /etc/yum.repos.d/epel.repo
#5.查看系统是不是安装了php 卸载之前的php版本
yum list php
yum remove php* -y
#6. 安装最新的php
echo "正在安装新版本的php Please wait"
yum --enablerepo=remi install php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt --skip-broken -y
#7.修改Apache配置文件 添加index.php首页
sed -i '402s/DirectoryIndex index.html index.html.var/DirectoryIndex index.html index.php index.html.var/' /etc/httpd/conf/httpd.conf
#8.修改php.ini的配置
#在946行下面添加时间
sed -i '946a date.timezone = PRC' /etc/php.ini
#9.添加测试页 测试php版本
echo -e "<?php
phpinfo();
?> " > /var/www/html/phpinfo.php
#10.重启Apache服务
service httpd restart
#11.防火墙开放80端口
sed -i '10a -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT ' /etc/sysconfig/iptables
#12.重启防火墙
service iptables restart
yum list php
echo -----------------
echo "PHP版本升级成功"
echo -----------------