wordpress_auto_install.sh
#!/bin/bashuser=$(whoami)function wordpress_auto_install () {
if [ $user == "root" ];thenecho "前提:调整系统配置,如关闭selinux、firewall等!"sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configsleep 0.2iptables -Fsystemctl stop firewalldsystemctl disable firewalldsleep 0.2echo "安装lamp所需rpm包"echo "Step1->lamp安装日志,请查看/$user/wordpress_auto_install.log"
> /$user/wordpress_auto_install.logecho "请确保本地yum源或网络yum源,二者之一必须可用!"yum install httpd mariadb mariadb-libs mariadb-server mariadb-devel php php-mysql -y >> /$user/wordpress_auto_install.log
# echo $?systemctl enable mariadbsystemctl enable httpdsystemctl restart mariadbsystemctl restart httpd
elseecho "您不是root管理员,没有权限操作!"exit 3
fiecho "Step2->mariadb数据库中针对wordpress创建数据库和用户"mysql <<END 2>/dev/nulldrop database wordpress_db;
ENDmysql <<END 2>/dev/nullcreate database wordpress_db;
ENDmysql <<END 2>/dev/nullgrant all privileges on wordpress_db.* to 'wordpress_user'@'localhost' identified by '123456';
ENDmysql <<END 2>/dev/nullflush privileges;
ENDecho "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.logrm -rf /var/www/html/wordpress-4.9.4-zh_CN.tar.gzchown -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.phpsed -i 's/database_name_here/wordpress_db/' /var/www/html/wordpress/wp-config.phpsed -i 's/username_here/wordpress_user/' /var/www/html/wordpress/wp-config.phpsed -i 's/password_here/123456/' /var/www/html/wordpress/wp-config.phpcat /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
<VirtualHost *:80>DocumentRoot /var/www/html/wordpress
</VirtualHost>
ENDsleep 0.2systemctl restart httpdecho "Step6->wordpress后台部署成功,请通过浏览器打开http://`ifconfig |grep -A 1 "ens[0-9]*" |tail -1 |awk '{print $2}'`:80完成接下的部署"
}if [ $user != "root" ];thenecho "请以root管理员用户进行部署!"exit 1
fils /$user |grep -E "^wordpress-4.9.4-zh_CN.tar.gz$" &> /dev/null
if [ $? -eq 0 ];thenwordpress_auto_install
elseecho "请上传wordpress-4.9.4-zh_CN.tar.gz至/$user目录下!"exit 2
fi
登录验证(http://192.168.10.208/wp-admin/):
脚本中所用wordpress-4.9.4-zh_CN.tar.gz,如果需要,请留言。
谢谢!