#------------CentOS 5.X安装LAMP最高版本环境------------------
#! /bin/sh
#安装Apache
yum install httpd -y
#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
#查看系统是不是安装了mysql 卸载之前的mysql版本
yum list mysql
yum remove mysql mysql-server -y
#6. 安装最新的php和Mysql
echo "正在安装新版本的php和Mysql Please wait"
yum --enablerepo=remi install php mysql mysql-server 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.修改mysql的配置信息
sed -i '3a default-character-set = utf8' /etc/my.cnf
#9.修改php.ini的配置 在946行下面添加时间
sed -i '946a date.timezone = PRC' /etc/php.ini
#10.添加测试页 测试php版本
echo -e "<?php\nphpinfo();\n?> " > /var/www/html/phpinfo.php
#11.重启Apache服务
service httpd restart
#12重启Mysql
chkconfig --add mysqld
mysql_install_db
service mysqld restart
#13.防火墙开放80 3306端口
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
service iptables save
#12.重启防火墙
service iptables restart
echo ----------------------------------------
echo "LAMP安装成功 PHP5.5+Mysql5.5+Apache2.4"
echo ----------------------------------------