将WordPress博客迁移到全新Aliyun服务器上

1. 配置系统和基础软件安装

配置Aliyun服务器时,选择64位的CentOS 6操作系统。再使用yum安装系统软件:

# yum install httpd mysql mysql-devel mysql-server php php-mysql iptables*

生成防火墙配置文件/etc/sysconfig/iptables,内容如下:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

重启防火墙

# /etc/init.d/iptables restart

初始化mysql数据库并启动mysql数据库

# /bin/cp /usr/share/mysql/my-large.cnf /etc/my.cnf
# /etc/init.d/mysqld start
# /usr/bin/mysql_secure_installation

修改httpd配置文件/etc/httpd/conf/httpd.conf,修改几处内容:

AddType text/html .shtml
AddType text/plain .sh
AddType text/plain .pl
AddType text/plain .py
AddHandler cgi-script .cgi
NameVirtualHost *:80

尾部添加:

<VirtualHost *:80>
    DocumentRoot /home/chenlianfu/wordpress
    ServerName www.chenlianfu.com
</VirtualHost>
<Directory "/home/chenlianfu/wordpress">
    AllowOverride None
    Options MultiViews FollowSymLinks ExecCGI
    Order allow,deny
    Allow from all
</Directory>

修改apache对用户chenlianfu家目录的访问权限

# chmod 750 /home/chenlianfu/
# usermod -aG chenlianfu apache

启动httpd服务

/etc/init.d/httpd start

2. 下载并安装WordPress

$ cd /home/chenlianfu/
$ wget https://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz
$ tar zxf wordpress-4.8.1-zh_CN.tar.gz

3. 迁移数据库

将原来wordpress的mysql数据库复制到/var/lib/mysql/目录下,即完成了数据的迁移。要注意修改文件权限:

# chown -R mysql:mysql /var/lib/mysql/wordpress_chenlianfu/
# chown -R apache:chenlianfu /home/chenlianfu/wordpress
# chmod 775 /home/chenlianfu/wordpress
# cd /home/chenlianfu/wordpress
# find ./ -perm 755 -exec chmod 775 {} \;
# find ./ -perm 644 -exec chmod 664 {} \;

再将域名解析指向Aliyun新服务器的IP后,输入www.chenlianfu.com网址,简单进行WordPress配置后则结束了。

4. 每天自动备份wordpress数据到邮箱