#!/bin/bash
# 功能描述:LAMP自动安装脚本
# 初始化
if [ "$(cat /etc/system-release | awk '{print $(NF-1)}' | awk -F"." '{print $1}')" -ne 7 ]
then
echo "当前程序只支持CentOS 7系统!"
exit 1
fi
if [ "$(whoami)" != root ]
then
echo "当前用户为:$(whoami),请使用管理员身份运行"
exit 2
fi
ping -c1 mirrors.aliyun.com
if [ "$?" -ne 0 ]
then
echo "当前网络不通"
exit 2
fi
iptables -F
yum -y install wget net-tools
DBPASSWD=`date | md5sum | cut -b 1-6`
# 更改yum源
mv /etc/yum.repos.d/*.repo /tmp/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache
# 安装主程序
yum -y install httpd mariadb mariadb-server php php-mysql
# 安装所需插件
yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap libjpeg* gd
# 更改默认网站目录
mkdir /usr/local/wwwweb
chown apache. /usr/local/wwwweb
sed -i 's/\/var\/www\/html/\/usr\/local\/wwwweb/g' /etc/httpd/conf/httpd.conf
# 添加测试页面
cat > /usr/local/wwwweb/phpinfo.php <<EOF
<?php
phpinfo();
?>
EOF
# 启动程序并设置开机自启
systemctl start httpd.service
systemctl start mariadb.service
systemctl enable httpd.service
systemctl enable mariadb.service
# 更改MySQL密码
mysqladmin -uroot password $DBPASSWD
# 完成
echo "已完成安装LAMP安装,数据库密码为$DBPASSWD"