WordPress迁站

官方网站

Changing Your Domain Name and URLs

Moving a website and changing your domain name or URLs (i.e. from http://example.com/site to http://example.com, or http://example.com to http://example.net) requires the following steps – in sequence.

  1. Download your existing site files.
  2. Export your database – go in to MySQL and export the database.
  3. Move the backed up files and database into a new folder – somewhere safe – this is your site backup.
  4. Log in to the site you want to move and go to Settings > General, then change the URLs. (ie from http://example.com/ to http://example.net ) – save the settings and expect to see a 404 page.
  5. Download your site files again.
  6. Export the database again.
  7. Edit wp-config.php with the new server’s MySQL database name, user and password.
  8. Upload the files.
  9. Import the database on the new server.

When your domain name or URLs change there are additional concerns. The files and database can be moved, however references to the old domain name or location will remain in the database, and that can cause issues with links or theme display.

If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have four options:

  1. Use the Velvet Blues Update URLs plugin if you can access your WP Admin Dashboard.
  2. Use the Better Search Replace plugin if you can access your WP Admin Dashboard.
  3. Use WP-CLI’s search-replace if your hosting provider (or you) have installed WP-CLI.
  4. Use the Search and Replace for WordPress Databases Script to safely change all instances on your old domain or path to your new one. (** only use this option if you are comfortable with database administration ** )

Note: Search and Replace from Interconnectit is a 3rd party scrip

其中

1是备份整个html目录

zip -r ~/htmlBefore.zip /var/www/html

2是备份Mysql数据库(其实 第1,2步是一个完整的WordPress备份)

mysqldump -u root -p "DatebaseName">~/WordPressBefore.sql

4步重要就是在设置里更改两个url 注意更改后立马又404错误

5是再次备份整个html整个根目录

zip -r ~/htmlAfter.zip /var/www/html

6再次导出数据库

mysqldump -u root -p "DatebaseName">~/WordPressAfter.sql

7 将htmlAfter.zip复制并解压到新的服务器的html目录

a,文件传输

scp -P <target ssh port> ~/htmlAfter.zip root@<IP>:/root/
scp -P <target ssh port> ~/WordPressAfter.sql root@<IP>:/root/
scp -P <target ssh port> /etc/httpd/conf/httpd.conf root@<IP>:/root/

b,新的服务器安装Apache与mysql以及php

#Centos6
yum install httpd
yum install mysql mysql-server
yum install php php-mysql
chkconfig httpd on
chkconfig mysqld on
service httpd start
service mysqld start
#Centos7
yum install httpd
yum install php php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-zts php-mbstring
#Centos7 php74
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum install php php-mysql php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mbstring php-SimpleXML php-dom php-pecl-zip  php-fpm php-gmp php-bcmath
#Centos8 7.4
yum module list php
yum module enable php:7.4
yum install php-fpm php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-pdo php-common php-opcache 
php-mcrypt php-cli php-curl php-mbstring php-SimpleXML php-dom php-pecl-zip php-gmp php-bcmath php-zip php-gd php-mysqlnd
chown nginx:nginx /var/lib/php/session/
#Centos8 remi-7.4 //推荐
yum module list php 
yum module enable php:remi-7.4 
yum install php 
yum install php-mysqlnd php-zip php-process php-bcmath php-gmp php-intl
chown nginx:nginx /var/lib/php/session/
//Mysql
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm yum install mysql mysql-server mysql-libs mysql-server 
systemctl enable mysqld httpd 
systemctl start mysqld httpd
//其它工具
yum install wget lsof tar lrzsz
//关闭mail服务
systemctl disable postfix
//iptables
yum install iptables-services iptables
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT               #允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT    #允许已建立的或相关连的通行
iptables -A INPUT -p tcp --dport 22 -j ACCEPT    #允许访问22端口
iptables -A INPUT -j DROP      #禁止其他未允许的规则访问
iptables -A OUTPUT -j ACCEPT #允许所有本机向外的访问
iptables -A FORWARD -j DROP     #禁止其他未允许的规则访问
iptables -L -n  #查看规则
service iptables save
//nginx
yum install nginx

c,解压Zip文件到新的服务器html目录

unzip -d ~/ htmlAfter.zip
mv var/www/html/*  /var/www/html/
mv var/www/html/.* /var/www/html/
chown -R apache:apache /var/www/html/*

d,在新的服务器建立数据库(注意笔者新服务器的Wordpress数据库名字,密码,所有者,所有者密码跟旧的一样所以没有修改数据库配置文件)

mysql -u root -p //登录
#CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
CREATE DATABASE databasename;
GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"localhost" IDENTIFIED BY "password";
FLUSH PRIVILEGES;
use databasename;
source WordPressAfter.sql;
exit;

e,重启apache与mysql删除临时文件(可选)

service mysqld restart
service httpd restart
rm ~/*.zip
rm ~/*.sql
rm ~/httpd.conf

7, Use the Velvet Blues Update URLs plugin if you can access your WP Admin Dashboard

mysql数据库中多媒体的连接还是旧的链接,所以必须下载插件修改mysqld数据库

另外笔者发现上面这个插件并不能更新网站插件的设置,所以最后一步是查看你所安装插件是否引用了就的连接如果是侧手动修改过来

经过以上设置测试是否迁站成功的方法是关闭旧网站的http服务,然后在客户端浏览器输入新的服务器url看加载是否正常

8,VPS测试工具

wget -qO- --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash

9,关闭ipV6

 /etc/sysctl.conf 然后添加以下内容:
# 禁用整个系统所有接口的IPv6
net.ipv6.conf.all.disable_ipv6 = 1

10,SSHD仅仅监听ipV4

 /etc/ssh/sshd_config
AddressFamily
指定 sshd(8) 应当使用哪种地址族。取值范围是:"any"(默认)、"inet"(仅IPv4)、"inet6"(仅IPv6)。

11,CentOS安装 PHP7

 
Installing PHP 5.6 on CentOS 7
1. To install PHP 5.6, you have to install and enable EPEL and Remi repository to your CentOS 7 system using the commands below.

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2. Next, install yum-utils which is an assortment of utilities that integrate with yum to enhance its default features, giving it more advanced package management options and also making it easier to use.

A few of its important features include manipulating repositories, enabling or disabling packages on the go and lots more, without any manual configurations.

# yum install yum-utils
3. One of the most important program provided by yum-utils is yum-config-manager, which you can use to active Remi repository as the default repository for installing various PHP versions. For example, if you want to install PHP 5.5, PHP 5.6 or PHP 7.2 on CentOS 7, just enable it and install as shown.

# yum-config-manager --enable remi-php55   [Install PHP 5.5]
# yum-config-manager --enable remi-php56   [Install PHP 5.6]
# yum-config-manager --enable remi-php72   [Install PHP 7.2]
4. Now that you’ve enabled selected versions of PHP, you can install PHP (here, we have chosen to install PHP 5.6) with all needed modules as follows

# yum-config-manager --enable remi-php56   [Install PHP 5.6]
# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo

12,httpd 允许htaccess

 
httpd.conf

    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride ALL

    #
    # Controls who can get stuff from this server.
    #
    Require all granted

13,上传限制修改

 
①修改上传文件大小限制
修改Nginx的client_max_body_size 大小默认为1MB,可以在http,server,location处修改
修改php的上传文件大小限制,/etc/php/7.4/fpm/php.ini中字段upload_max_filesize = 20M,表示允许最大20MB
②上传文件类型
在wp-config.php 增加define('ALLOW_UNFILTERED_UPLOADS', true); 这样就允许所有格式上传了
或者使用插件
未经允许不得转载:Mr.Zhang » WordPress迁站

登录

找回密码

注册