作用: 自动安装WordPress站点
使用: 使用前修改相关变量,注意数据库密码设置(若之前没有安装mysql-server,则脚本无需修改,密码将被设置为"rootroot"; 默认下载指定版本的wordpress,可修改下载链接或安装完成后再升级。
演示:
代码专区:
#/bin/bash # LY # ------------------ # Copyright 2016.04.16 LingYi ([email protected]) QQ:1519952564 # "install wordpress service" DataBaseUser=‘root‘ DataBasePwd=‘‘ #the password will be DataBaseDefPwd=‘rootroot‘ DataBaseName=‘wordpress‘ WebRootPath=‘/var/www/html‘ echo -e "\033[1;32mInstall software ....\033[0m" yum install -y httpd mysql-server php php-mysql yum install -y php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc yum install -y wget unzip expect echo -ne "\033[1;32mSet httpd and mysql run on start-up ... \033[0m" if chkconfig httpd on && chkconfig mysqld on &>/dev/null; then echo -e "\033[1;32m [ OK ]\033[0m" else echo -e "\033[1;31m [ FAIL ]\033[0m" exit 10 fi echo -e "\033[1;32mGet wordpress ... \033[0m" if ! wget http://cn.wordpress.org/wordpress-3.9-zh_CN.zip; then echo -e "\033[1;31m Can not get wordpress !!!\033[0m" exit 11 fi echo -e "\033[1;32mUnzip wordpress ... \033[0m" if ! unzip wordpress-3.9-zh_CN.zip &>/dev/null; then echo -e "\033[1;31m Can not unzip wordpress !!!\033[0m" exit 12 fi echo -e "\033[1;32mModify wordpress configuration file ... \033[0m" sed -i "s/database_name_here/$DataBaseName/" wordpress/wp-config-sample.php sed -i "s/username_here/$DataBaseUser/" wordpress/wp-config-sample.php sed -i "s/password_here/${DataBasePwd:-$DataBaseDefPwd}/" wordpress/wp-config-sample.php mv wordpress/wp-config-sample.php wordpress/wp-config.php echo -e "\033[1;32mCoping wordpress files to web root directory ... \033[0m" if cp -a wordpress/* $WebRootPath; then rm -fr wordpress* else echo -e "\033[1;31m Copy files failed !!!\033[0m" fi if ! service httpd status &>/dev/null; then usermod -d $WebRootPath apache &>/dev/null else service httpd stop &>/dev/null && usermod -d $WebRootPath apache fi echo -e "\033[1;32mModify permissions of wordpress files ... \033[0m" if ! chown apache:apache -R $WebRootPath; then echo echo -e "\033[1;31m [ FAIL ]\033[0m" exit 12 fi echo -ne "\033[1;32mStarting http and mysql ... \033[0m" if service httpd start &>/dev/null && service mysqld start &>/dev/null; then echo -e "\033[1;32m [ OK ]\033[0m" else echo -e "\033[1;31m [ FAIL ]\033[0m" exit 13 fi echo -ne "\033[1;32mOperating mysql ... \033[0m" if [[ -z $DataBasePwd ]]; then DataBasePwd=$DataBaseDefPwd mysqladmin -u $DataBaseUser flush-privileges password "$DataBasePwd" &>/dev/null fi expect -c " spawn mysql -u $DataBaseUser -p"$DataBasePwd" expect { \"mysql>\" { send \"create database wordpress;\r\" send \"quit;\r\" interact } } " &>/dev/null if [[ $? -eq 0 ]]; then echo -e "\033[1;32m [ OK ]\033[0m" else echo -e "\033[1;31m [ FAIL ]\033[0m" fi
附件下载源码
时间: 2024-10-13 00:34:47