1 #!/bin/bash 2 # 功能描述:LAMP自动安装脚本 3 4 # 初始化 5 if [ "$(cat /etc/system-release | awk '{print $(NF-1)}' | awk -F"." '{print $1}')" -ne 7 ] 6 then 7 echo "当前程序只支持CentOS 7系统!" 8 exit 1 9 fi 10 if [ "$(whoami)" != root ] 11 then 12 echo "当前用户为:$(whoami),请使用管理员身份运行" 13 exit 2 14 fi 15 ping -c1 mirrors.aliyun.com 16 if [ "$?" -ne 0 ] 17 then 18 echo "当前网络不通" 19 exit 2 20 fi 21 iptables -F 22 yum -y install wget net-tools 23 DBPASSWD=`date | md5sum | cut -b 1-6` 24 25 # 更改yum源 26 mv /etc/yum.repos.d/*.repo /tmp/ 27 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 28 sed -i '/aliyuncs/d' /etc/yum.repos.d/CentOS-Base.repo 29 yum clean all && yum makecache 30 31 # 安装主程序 32 yum -y install httpd mariadb mariadb-server php php-mysql 33 34 # 安装所需插件 35 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 36 37 # 更改默认网站目录 38 mkdir /usr/local/wwwweb 39 chown apache. /usr/local/wwwweb 40 sed -i 's/\/var\/www\/html/\/usr\/local\/wwwweb/g' /etc/httpd/conf/httpd.conf 41 42 # 添加测试页面 43 cat > /usr/local/wwwweb/phpinfo.php <<EOF 44 <?php 45 phpinfo(); 46 ?> 47 EOF 48 49 # 启动程序并设置开机自启 50 systemctl start httpd.service 51 systemctl start mariadb.service 52 systemctl enable httpd.service 53 systemctl enable mariadb.service 54 55 # 更改MySQL密码 56 mysqladmin -uroot password $DBPASSWD 57 58 # 完成 59 echo "已完成安装LAMP安装,数据库密码为$DBPASSWD"