centos安装wordpress配置脚本

当前使用的mysql版本为5.1.73,wordpress版本为4.9.8。

 

这个bash脚本会安装所有必要的包并配置相关信息,以及打开80端口以使外网能够访问。

其中,变量install_dir为安装路径,密码根据时间自动生成。

 

P.S.密码存放在/tmp/password

    如果想要访问服务器上wordpress上的文件,可以用FTP连接。FTP密码记录在password中。

    建议开始使用ssh连接到服务器后新建一个脚本文件并将内容复制过去。然后给执行权限并执行。

    结束后请通过 ip地址/wp-admin访问初始配置页面,在该页面创建完初始帐号后即可正常使用。

#/bin/sh
install_dir="/var/www/html"
#Creating Random WP Database Credenitals
db_name="wp`date +%s`"
db_user=$db_name
db_password=`date |md5sum |cut -c '1-12'`
sleep 1
mysqlrootpass=`date |md5sum |cut -c '1-12'`
sleep 1
ftp_password=`date |md5sum |cut -c '1-12'`

#### Install Packages for https and mysql
yum -y install httpd httpd-devel
yum -y install mysql mysql-server mysql-devel
yum -y install lynx vsftpd
##### Open firewall for http and SSL
iptables -F
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
#### Start http
/etc/init.d/httpd start
chkconfig httpd on

#### Start mysql and set root password
/etc/init.d/mysqld start
chkconfig mysqld on

/usr/bin/mysql -uroot -e "USE mysql;UPDATE user SET Password=PASSWORD('$mysqlrootpass') WHERE User='root';FLUSH PRIVILEGES;"

rm -rf /root/.my.cnf
touch /root/.my.cnf
chmod 640 /root/.my.cnf
echo "[client]">>/root/.my.cnf
echo "user=root">>/root/.my.cnf
echo "password="$mysqlrootpass>>/root/.my.cnf
####Install PHP
yum -y install php php-common php-mysql php-gd php-mbstring php-mcrypt php-xml php-devel

sed -i '0,/AllowOverride\ None/! {0,/AllowOverride\ None/ s/AllowOverride\ None/AllowOverride\ All/}' /etc/httpd/conf/httpd.conf #Allow htaccess usage

/etc/init.d/httpd restart

####Download and extract latest Wordpress Package
if test -f /tmp/latest.tar.gz
then
echo "WP is already downloaded."
else
echo "Downloading Wordpress"
cd /tmp/ && wget "http://wordpress.org/latest.tar.gz";
fi

/bin/tar -C $install_dir -zxf /tmp/latest.tar.gz --strip-components=1
chown apache $install_dir -R
#### Set FTP Credentials
echo $ftp_password | passwd apache --stdin
/etc/init.d/vsftpd start
chkconfig vsftpd on

#### Create WP-config and set DB credentials
/bin/mv $install_dir/wp-config-sample.php $install_dir/wp-config.php

/bin/sed -i "s/database_name_here/$db_name/g" $install_dir/wp-config.php
/bin/sed -i "s/username_here/$db_user/g" $install_dir/wp-config.php
/bin/sed -i "s/password_here/$db_password/g" $install_dir/wp-config.php

cat << EOF >> $install_dir/wp-config.php
define('FS_METHOD', 'ftpext');
define('FTP_BASE', '$install_dir');
define('FTP_USER', 'apache');
define('FTP_PASS', '$ftp_password');
define('FTP_HOST', '127.0.0.1');
define('FTP_SSL', false);
EOF

cat << EOF >> $install_dir/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
EOF

chown apache $install_dir -R

##### Set WP Salts
grep -A50 'table_prefix' $install_dir/wp-config.php > /tmp/wp-tmp-config
/bin/sed -i '/**#@/,/$p/d' $install_dir/wp-config.php
/usr/bin/lynx --dump -width 200 https://api.wordpress.org/secret-key/1.1/salt/ >> $install_dir/wp-config.php
/bin/cat /tmp/wp-tmp-config >> $install_dir/wp-config.php && rm /tmp/wp-tmp-config -f
/usr/bin/mysql -u root -e "CREATE DATABASE $db_name"
/usr/bin/mysql -u root -e "GRANT ALL PRIVILEGES ON $db_name.* to '"$db_user"'@'localhost' IDENTIFIED BY '"$db_password"';"

touch password
######Display generated passwords to log file.
echo "Database Name: " $db_name >>password
echo "Database User: " $db_user >>password
echo "Database Password: " $db_password >>password
echo "Mysql root password: " $mysqlrootpass >>password
echo "FTP Password: " $ftp_password >>password

cat password

原网址:https://www.vultr.com/docs/install-wordpress-with-apache-php-and-mysql-automated-startup-script 

-------------------------------------------------------------分割线------------------------------------------------------------

更新列表:

2018年 08月 13日

修改mysql配置中>为>>,以改正/root/.my.cnf文件信息的错误。

2018年 08月 21日

修复了一处小错误。

在centos 6 X64上进行了自动化测试,确定没有问题。

增加了附言。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值