wordpress_auto_install.sh
!/bin/bash
user=$(whoami)
function wordpress_auto_install () {
if [ $user == "root" ];then
echo "前提:调整系统配置,如关闭selinux、firewall等!"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
sleep 0.2
iptables -F
systemctl stop firewalld
systemctl disable firewalld
sleep 0.2
echo "安装lamp所需rpm包"
echo "Step1->lamp安装日志,请查看/$user/wordpress_auto_install.log"
/$user/wordpress_auto_install.log
echo "请确保本地yum源或网络yum源,二者之一必须可用!"
yum install httpd mariadb mariadb-libs mariadb-server mariadb-devel php php-mysql -y >> /$user/wordpress_auto_install.logecho $?
systemctl enable mariadb
systemctl enable httpd
systemctl restart mariadb
systemctl restart httpd
else
echo "您不是root管理员,没有权限操作!"
exit 3
fi
echo "Step2->mariadb数据库中针对wordpress创建数据库和用户"
mysql </dev/null
drop database wordpress_db;
END
mysql </dev/null
create database wordpress_db;
END
mysql </dev/null
grant all privileges on wordpress_db.* to 'wordpress_user'@'localhost' identified by '123456';
END
mysql </dev/null
flush privileges;
END
echo "Step3->将wordpress包拷贝至httpd的/var/www/html目录并解压"
cp /$user/wordpress-4.9.4-zh_CN.tar.gz /var/www/html/
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz -C /var/www/html/ >> /$user/wordpress_auto_install.log
rm -rf /var/www/html/wordpress-4.9.4-zh_CN.tar.gz
chown -R root:root /var/www/html/wordpress/
echo "Step4->更改wordpress配置文件指定数据库、用户名和密码"
cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
sed -i 's/database_name_here/wordpress_db/' /var/www/html/wordpress/wp-config.php
sed -i 's/username_here/wordpress_user/' /var/www/html/wordpress/wp-config.php
sed -i 's/password_here/123456/' /var/www/html/wordpress/wp-config.php
cat /var/www/html/wordpress/wp-config.php | grep -E "DB_NAME|DB_USER|DB_PASSWORD"
echo "Step5->配置httpd虚拟主机"
cat << END >> /etc/httpd/conf/httpd.conf
DocumentRoot /var/www/html/wordpress
END
sleep 0.2
systemctl restart httpd
echo "Step6->wordpress后台部署成功,请通过浏览器打开http://`ifconfig |grep -A 1 "ens[0-9]*" |tail -1 |awk '{print $2}'`:80完成接下的部署"
}
if [ $user != "root" ];then
echo "请以root管理员用户进行部署!"
exit 1
fi
ls /$user |grep -E "^wordpress-4.9.4-zh_CN.tar.gz$" &> /dev/null
if [ $? -eq 0 ];then
wordpress_auto_install
else
echo "请上传wordpress-4.9.4-zh_CN.tar.gz至/$user目录下!"
exit 2
fi