wordpress 服务器

tech2023-01-23  54

wordpress 服务器

Like many web professionals, I’m so busy doing things for clients that it’s true to say that my own site often suffers thanks to a lack of time. One thing that I have been meaning to do for some time is move the site, which is a WordPress site, to another server, as I’m not overly happy with my current hosts.

像许多Web专业人员一样,我非常忙于为客户服务,可以说我自己的站点经常由于时间不足而受苦。 一段时间以来,我一直想做的一件事是将站点(一个WordPress站点)移至另一台服务器,因为我对当前的主机并不太满意。

However, it’s one of those things that I’ve put off doing because it does just seem like a lot of hassle, especially since my theme is bespoke and therefore any issues and it will take time to do again (yes, a simple backup will take care of this, I know).

但是,这是我推迟进行的事情之一,因为它确实看起来很麻烦,尤其是因为我的主题是定制的,因此任何问题都需要时间才能再次执行(是的,简单的备份会照顾这个,我知道)。

Bearing all of that in mind, I can imagine that many people have the same problem, or have no idea where to start, so here you will find instructions on how to carry this out, without losing theme elements or ending up with a site full of broken links.

牢记所有这些,我可以想象很多人有相同的问题,或者不知道从哪里开始,所以在这里您将找到有关如何执行此操作的说明,而又不会丢失主题元素或最终建立一个完整的网站断开的链接。

保持相同的URL (Keeping the same URL)

Firstly, it’s worth noting that if you haven’t really optimized the site and intend on keeping all of the URLs, and the domain name and the database is going to remain the same, then it’s a simple process.

首先,值得注意的是,如果您尚未真正优化站点并打算保留所有URL,并且域名和数据库将保持不变,那么这是一个简单的过程。

If this is the case, then you will just have to copy the files and database across to the new server. If you want to change the name or user of the database you will have to alter the edit.wp-config.php file to ensure that it has the right values. Locate the following in the root folder and alter accordingly.

如果是这种情况,那么您只需要将文件和数据库复制到新服务器上即可。 如果要更改数据库的名称或用户,则必须更改edit.wp-config.php文件以确保其值正确。 在根文件夹中找到以下内容,并进行相应更改。

define('DB_NAME', 'user_wrdp1'); /** MySQL database username */ define('DB_USER', 'user_wrdp1'); /** MySQL database password */ define('DB_PASSWORD', 'password');

If you’re changing server but keeping your domain name, then you will need to edit wp-config with your new database and user details and then just upload all of your files to the new server.

如果要更改服务器但保留域名,则需要使用新数据库和用户详细信息编辑wp-config,然后将所有文件上传到新服务器。

It’s pretty obvious too, but bears repeating, that you should make a full backup of the site, which should include the following:

这也很明显,但需要重复一遍,您应该对站点进行完整备份,其中应包括以下内容:

Plugins

外挂程式 Theme files

主题文件 Any uploads that you’ve made

您上传的所有内容 The database

数据库

To do this, you can use phpMyAdmin, which is an open source tool for managing MySQL databases and includes a wealth of useful tools. You can choose to export data in a number of formats, such as CSV, SQL, XML, PDF, ISO/IEC 26300 and others. Alternatively, you can use a plugin such as WP-DB-Backup.

为此,您可以使用phpMyAdmin ,它是一个用于管理MySQL数据库的开源工具,其中包含大量有用的工具。 您可以选择以多种格式导出数据,例如CSV,SQL,XML,PDF,ISO / IEC 26300等。 另外,您可以使用WP-DB-Backup之类的插件。

从本地上载到远程安装 (Uploading from local to a remote installation)

Once you’re fully backed up and ready to go, first of all you’ll need to disable Permalinks. This can be done in the “Permalinks” screen view which is in the “Settings” menu. Choose the default setting and hit save.

完全备份并准备就绪后,首先需要禁用永久链接。 这可以在“ 设置 ”菜单中的“固定链接”屏幕视图中完成。 选择默认设置,然后点击保存。

Then, if you haven’t already, backup the database, make a copy and rename it.

然后,如果尚未备份数据库,则进行复制并重命名。

在新服务器上安装WordPress (Installing WordPress on the new server)

Install WordPress as you normally would, either using FTP or through cPanel and then copy all of the files from your local wp-content file to the one on the server using FTP or SFTP. Next, you will need to edit the database in order to replace the local URL with the remote one.

使用FTP或通过cPanel正常安装WordPress,然后使用FTP或SFTP将所有文件从本地wp-content文件复制到服务器上的文件。 接下来,您将需要编辑数据库,以便用远程URL替换本地URL。

For this, use a search and replace utility, preferably not a text editor and change every instance of the local URL to the remote one. You can use SEARCH REPLACE DB for this, which should be installed in the root folder of your WP install for best results. In order to protect the script from abuse, it’s best to rename it before doing anything else.

为此,请使用搜索和替换实用程序,最好不要使用文本编辑器,然后将本地URL的每个实例更改为远程实例。 您可以为此使用SEARCH REPLACE DB ,该数据库应安装在WP安装的根文件夹中,以获得最佳效果。 为了防止脚本被滥用,最好在执行任何其他操作之前将其重命名。

For example, if you rename it newinstall.php, you will then go to http://yoursite.com/newinstall.php and follow the on-screen instructions to carry out search and replace. Once you’ve finished doing this, it’s important that you also delete the script in order to secure the DB.

例如,如果将其重命名为newinstall.php,则将转到http://yoursite.com/newinstall.php,并按照屏幕上的说明进行搜索和替换。 完成此操作后,还必须删除脚本以保护数据库,这一点很重要。

Save the database before continuing. If a new database has been created when you installed WP, then this will need to be deleted. You can do this by:

在继续之前,请保存数据库。 如果在安装WP时创建了新数据库,则将其删除。 您可以通过以下方式做到这一点:

Using phpMyAdmin, click on the “Structure” tab

使用phpMyAdmin,单击“ 结构 ”选项卡

Underneath the list of tables click on “Check All”

在表格列表下方,单击“ Check All ”

Choose “Drop” from the menu called “with selected”

从名为“ 选中 ”的菜单中选择“拖放 ”

Choose “Yes” when the message pops up asking if you want to drop all tables

当消息弹出询问您是否要删除所有表时,选择“ 是 ”

Re-enable your permalinks as you had them in the last installation

重新启用您的永久链接,就像您在上次安装中那样

You’re good to go.

你很好

从主机移到主机 (Moving from host to host)

If you’re moving the site to a new host, it’s exactly the same as when you upload from a local server, with one key difference being that you will have to download all of your files from the existing host using FTP.

如果要将站点移至新主机,则与从本地服务器上载时完全相同,主要区别在于必须使用FTP从现有主机下载所有文件。

变更网址 (Changing the URL)

If you need to change the URL of the site as it’s in a subdirectory or it’s a new domain name, you can do this by adding some lines to the functions.php file of the theme, as below.

如果您需要更改站点的URL,因为它位于子目录中或者是新域名,则可以通过在主题的functions.php文件中添加一些行来实现,如下所示。

update_option('siteurl','http://www.new-site-address.com');update_option('home','http://www.new-site-address.com');

Then, load the new files onto the site and it should work fine. Don’t attempt to just copy all of the files and database over, as this won’t work properly and you’ll end up with broken links.

然后,将新文件加载到站点上,它应该可以正常工作。 不要尝试仅复制所有文件和数据库,因为这将无法正常工作,并且您最终会遇到链接断开的情况。

Once you’ve then loaded the new files, test and delete the lines from the functions.php files, as your new settings will now be stored and saved in the database.

一旦您加载了新文件,请测试并删除functions.php文件中的行,因为新设置现在将被存储并保存在数据库中。

If you need to set up 301 redirects, which is important to both search engines and users, then you’ll need to connect to the old site and edit the .htaccess file. Locate the file and then paste this code at the top of the file:

如果您需要设置301重定向(这对搜索引擎和用户均很重要),则需要连接到旧站点并编辑.htaccess文件。 找到文件,然后将此代码粘贴到文件顶部:

1 #Options +FollowSymLinks 2 RewriteEngine on 3 RewriteRule ^(.*)$ http://yoursite.com $1 [R=301,L]

Once you’ve done this, go back to the new site and test to ensure that the changes have been made successfully. It’s also a good idea to submit the change of URL to Google via Webmaster Tools and you will also need to verify it.

完成此操作后,请返回新站点并进行测试以确保更改已成功完成。 通过网站站长工具将网址更改提交给Google也是一个好主意,您还需要进行验证。

Finally, once you’re confident that all is working well and you’ve checked and tested, remember to tell the site users about the change. You can do this in whatever way you think will be the most effective, by newsletter, blog post or on social media and if you still own the old domain, you can set up a temporary redirect to catch any that initially fall through the net.

最后,一旦您确信一切正常,并且已经进行了检查和测试,请记住将所做的更改告知站点用户。 您可以通过时事通讯,博客文章或社交媒体,以您认为最有效的任何方式进行此操作,如果您仍然拥有旧域名,则可以设置临时重定向以捕获最初落入网络的任何内容。

That’s it, all you need to do to change the location of your WP site, even if you’re using a new URL.

就是这样,即使您使用的是新的URL,也需要做所有更改WP网站的位置的操作。

翻译自: https://www.sitepoint.com/move-wordpress-new-server-without-losing-anything/

wordpress 服务器

最新回复(0)