CentOS 6.X安装LAMP最高版本环境

时间:2024-01-16 22:11:02
#------------CentOS .X安装LAMP最高版本环境------------------
#! /bin/sh
 
#安装Apache
yum install httpd -y
#.关闭selinux
cp -rp /etc/selinux/config /etc/selinux/config.bak
setenforce
sed -i '7s/enforcing/disabled/' /etc/selinux/config
#.显示selinux的状态 Permissive为关闭
getenforce which wget > /dev/null >&
if [ $? == ];then
echo "OK"
else
#echo "Failt"
yum install wget -y
fi #.判断系统的版本
if [ "$(uname -i)" = i386 ]; then
# 如果服务器是32位,那么运行如下命令
echo "开始下载第三方remi库 i386"
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-*.rpm epel-release-*.rpm
else
## 如果是64位的 那么运行以下命令
echo "下载第三方remi库 X64"
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
#.修改remi.repo的配置文件 如果只想升级到php5..x,那么就把[remi]部分的enabled改为1
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
 
#.查看系统是不是安装了php 卸载之前的php版本
yum list php
yum remove php* -y
#查看系统是不是安装了mysql 卸载之前的mysql版本
yum list mysql
yum remove mysql mysql-server -y
 
#. 安装最新的php和Mysql
echo "正在安装新版本的php和Mysql Please wait"
#.修改Apache配置文件 添加index.php首页
#.修改mysql的配置信息
sed -i '3a default-character-set = utf8' /etc/my.cnf
#.修改php.ini的配置 在946行下面添加时间
sed -i '946a date.timezone = PRC' /etc/php.ini
#.添加测试页 测试php版本
echo -e "<?php\nphpinfo();\n?> " > /var/www/html/phpinfo.php
#.重启Apache服务
service httpd restart
#12重启Mysql
chkconfig --add mysqld
mysql_install_db
service mysqld restart
#.防火墙开放80 3306端口
 
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
service iptables save
 
 
#.重启防火墙
service iptables restart
 
echo "如果Mysql启动不起来则执行mysql_install_db这个命令"
 
mysql_install_db
 
echo ----------------------------------------
 
echo "LAMP安装成功 PHP5.5+Mysql5.5+Apache2.4"
echo ----------------------------------------