Monthly Archives: January 2018

WordPress迁移笔记

最开始的时候,我的这个网站是建在实验室的Amazon EC2上面的。

后来因为临近毕业,不再用实验室租的服务器了,就在RamNode上面重新部署了一遍Wordpress,同时架了一个shadowsocks在上面。

但是ss用的人好多,不知道为什么突然有一天就被封掉了,3.6刀一个月的稳定VPS就这么没了。

最近找到一个叫做VirMach的VPS在打折,算上打折码35刀一年,试用了一下还比较稳定。于是又要把Wordpress搬到这个网站上面来。搬来搬去挺麻烦的,网上的教程不是很具体,或者因为一些版本的原因不是非常贴合。摸索了一会终于解决了这些问题,现在记录一下运行的步骤,万一以后又要转移的时候可以拿出来看看。

总体上来说,包括三个步骤:
Part I:  迁移数据库
参考链接:
RamNode上面登录mysql:
root@www:/usr/local/bin# mysql -uroot -ptsinghua
然后检查有多少个数据库:
mysql> show databases;
好多啊
| Database           |
+——————–+
| information_schema |
| lzq_wordpress      |
| mysql              |
| performance_schema |
| sys                |
| wordpress_db
这里看了一下wp-config.php文件,貌似用到的其实也就只有wordpress_db这个数据库
所以只dump出这个数据库
root@www:/home/lzq/wordpress# mysqldump -uroot -pwordpress_db > wordpress_db.sql
密码好像是tsinghua
另外可以通过wget传输放在共享目录里面的数据,这样会更快一点
root@shaojuanzi:/home# wget www.lzq8272587.cn/photo/wordpress_db.sql
在另一个主机上面再导入数据库
创建一个相同名字的数据库
mysql> create database wordpress_db;
然后再插入数据
root@shaojuanzi:/home/lzq# mysql -uroot -p wordpress_db < ../wordpress_db.sql
记得在配置文件里面修改密码
root@shaojuanzi:/home/lzq/wordpress# vim wp-config.php
Part II: 迁移网站
把之前的整个网站打包
root@shaojuanzi:/home/lzq/wordpress# vim wp-config.php
放到web文件夹里面去,然后用wget下载
在/etc/apache2/apache2.conf这个文件里面加入下面的内容,设置网站的默认主页为我们自己的
<Directory /home/lzq/wordpress/photo>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
<Directory /home/lzq/wordpress>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
然后注意到,现在这个conf文件只是include了另一个配置文件,所以要找到
site-available/000-default文件
修改成以下的内容
root@www:/home/lzq/wordpress/photo# cat /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request’s Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /home/lzq/wordpress
<Directory /home/lzq/wordpress/photo>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
<Directory /home/lzq/wordpress>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
        # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with “a2disconf”.
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
这样就可以了!!
Part III:重启
root@shaojuanzi:/etc/apache2/sites-available# /etc/init.d/mysql start
root@shaojuanzi:/etc/apache2# /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.
哎呀妈呀终于算是成功的把网站迁移过去了。
千万千万不要再被封掉了!