在Ubuntu上制作生产WordPress博客的备份副本

You’ve just thought of a great new layout for your blog… but making changes to your blog while visitors are accessing it is generally a bad idea, especially if you are running an ad-supported blog. This How-To shows you the list of steps you need to take to get a copy of your production WordPress blog copied down to your local Ubuntu machine. (Should work for any debian linux)

您刚刚想到了博客的全新布局……但是在访问者访问博客时对其进行更改通常是一个坏主意,特别是如果您运行的是受广告支持的博客。 本操作方法向您显示将生产WordPress博客副本复制到本地Ubuntu计算机所需采取的步骤列表。 (适用于任何debian linux)

First, we’ll need to make a copy of your current WordPress blog. I’m going to assume you have access to the console at your hosting provider, or they at least have some type of backup provided for you. If you get your backup files a different way you can skip that step.

首先,我们需要复制您当前的WordPress博客。 我假设您可以在托管服务提供商处访问控制台,或者他们至少为您提供了某种类型的备份。 如果您以其他方式获取备份文件,则可以跳过该步骤。

For a blog, we’ve got both the WordPress installation as well as the database, where the text of all your posts are actually stored. If you’ve uploaded images or files, they will be in your wordpress folder structure, so we really need both.

对于博客,我们既有WordPress安装程序,也有数据库,实际上所有帖子的文本都存储在该数据库中。 如果您已上传图像或文件,它们将位于您的wordpress文件夹结构中,因此我们确实需要两者。

1) Let’s get a backup of the database first. Connect to the server via SSH and run the following command:

1)首先让我们备份数据库。 通过SSH连接到服务器并运行以下命令:

mysqldump -uUSERNAME -pPASSWORD -hSERVER DATABASENAME > dbbackup.bak

mysqldump -uUSERNAME -pPASSWORD -hSERVER DATABASENAME> dbbackup.bak

Naturally you’ll want to substitute the uppercase text for the correct values on your installation.

自然,您将要用大写字母替换安装中的正确值。

2) Make a backup of the file structure:

2)备份文件结构:

tar -cf sitebackup.tar SITEROOTDIRECTORY

tar -cf sitebackup.tar SITEROOTDIRECTORY

You’ll want to substitute the uppercase text for the root directory of your site.

您需要将大写文本替换为网站的根目录。

3) Copy the files down to your local Ubuntu machine. This can be done via scp, ftp, or however you feel like it. I’ll leave that up to you.

3)将文件复制到本地Ubuntu计算机上。 可以通过scp,ftp来完成,也可以根据需要进行设置。 我留给你。

4) Make sure you have apache, php and mysql installed. If you don’t, you can consult the other how-to guides on this site, or just type in the following commands at a terminal prompt:

4)确保已安装apache,php和mysql。 如果不这样做,则可以查阅此站点上的其他方法指南,或者只是在终端提示符下键入以下命令:

sudo apt-get install apache2

须藤apt-get install apache2

sudo apt-get install php5

须藤apt-get install php5

sudo apt-get mysql-server

须藤apt-get mysql-server

sudo apt-get php5-mysql

须藤apt-get php5-mysql

sudo /etc/init.d/apache2 restart

sudo /etc/init.d/apache2重新启动

5) We need to create a database and import the original database that we backed up. Navigate to the folder that you downloaded the files to and run these commands:

5)我们需要创建一个数据库并导入我们备份的原始数据库。 导航到将文件下载到的文件夹,然后运行以下命令:

mysqladmin create DATABASENAME

mysqladmin创建DATABASENAME

mysql -uroot DATABASENAME < dbbackup.bak

mysql -uroot数据库名称<dbbackup.bak

6) Make our local webserver point to the copy of WordPress we got off the production server. First, we’ll want to extract the tar archive that we created. You can do that however you want, but I prefer the command line. There is a utility built into Ubuntu to allow you to do so graphically if that’s the way you like to do it.

6)使我们的本地网络服务器指向我们从生产服务器下的WordPress副本。 首先,我们要提取我们创建的tar存档。 您可以根据需要进行操作,但是我更喜欢命令行。 Ubuntu内置了一个实用程序,如果您愿意的话,可以通过图形方式进行操作。

tar xvf sitebackup.tar

焦油xvf sitebackup.tar

This will produce a directory structure similar to the one on the server you were on. We’re going to imagine that your site root directory is now in /home/username/wordpress/ for the purposes of this article. If you’ve extracted it elsewhere, then substitute accordingly. We need to add in the alias into apache, so open up the following file:

这将产生与您所在服务器上的目录结构相似的目录结构。 我们将假设您的站点根目录现在位于/ home / username / wordpress /中。 如果您已将其提取到其他位置,请相应替换。 我们需要将别名添加到apache中,因此打开以下文件:

/etc/apache2/conf.d/alias

/etc/apache2/conf.d/alias

You’ll want to paste in these lines, and adjust the paths according to your system and the /directory you want the test blog to be available on.

您将需要粘贴这些行,并根据您的系统和您希望测试博客可用的/目录来调整路径。

Alias /wordpress /home/username/wordpress <Directory /home/username/wordpress> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>

别名/ wordpress / home /用户名/ wordpress <目录/ home /用户名/ wordpress>选项索引FollowSymLinks AllowOverride All顺序允许,拒绝所有</ Directory>

7) If you are using Permalinks, you’ll want to duplicate the same thing locally, and will need to enable mod_rewrite:

7)如果您使用的是永久链接,则需要在本地复制相同的内容,并且需要启用mod_rewrite:

ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

8) Now we’ll need to edit the wp-config file to point to the local database. If you’ve been following along, these settings should work for you once you substitute the database name.

8)现在,我们需要编辑wp-config文件以指向本地数据库。 如果您一直遵循这些原则,那么在替换数据库名称后,这些设置将对您有用。

// ** MySQL settings ** // define(‘WP_CACHE’, false); //Added by WP-Cache Manager define(‘DB_NAME’, ‘DATABASENAME’); // The name of the database define(‘DB_USER’, ‘root’); // Your MySQL username define(‘DB_PASSWORD’, ”); // …and password define(‘DB_HOST’, ‘localhost’); // …and the server MySQL is running on

// ** MySQL设置** // define('WP_CACHE',false); //由WP-Cache Manager添加define('DB_NAME','DATABASENAME'); //数据库名称define('DB_USER','root'); //您MySQL用户名define('DB_PASSWORD',''); //…和密码define('DB_HOST','localhost'); //…并且服务器MySQL正在运行

9) If you are using the using WP-Cache caching module, navigate to your blog root directory and run these commands:

9)如果您正在使用using WP-Cache缓存模块,请导航到您的博客根目录并运行以下命令:

rm wp-content/advanced-cache.php

rm wp-content / advanced-cache.php

ln -s wp-content/plugins/wp-cache/wp-cache-phase1.php wp-content/advanced-cache.php

ln -s wp-content / plugins / wp-cache / wp-cache-phase1.php wp-content / advanced-cache.php

rm wp-content/cache/*

rm wp-content / cache / *

chmod -R 777 *

chmod -R 777 *

10) One final thing left to do. The data in the database still has the wrong URL for your blog. The easiest way to fix this is by running a SQL statement against the database. Create a new text file named fixsettings.sql, copy the following lines into it, substituting your own IP address for localhost if you want other people to connect to you:

10)还有最后一件事要做。 数据库中的数据仍然具有您博客的错误URL。 解决此问题的最简单方法是对数据库运行SQL语句。 创建一个名为fixsettings.sql的新文本文件,将以下行复制到其中,如果您希望其他人连接到您,则将您自己的IP地址替换为localhost:

update wp_options set option_value=’http://localhost/wordpress/’ where option_id=1; update wp_options set option_value=’http://localhost/wordpress/’ where option_id=40;

更新wp_options设置option_value =' http:// localhost / wordpress /'其中option_id = 1; 更新wp_options设置option_value =' http:// localhost / wordpress /'其中option_id = 40;

Now we’ll import that into the database:

现在,我们将其导入数据库:

mysql -uroot < fixsettings.sql

mysql -uroot <fixsettings.sql

Note that you should keep that file around, because any time you want to update your local copy with the latest blog posts, all you have to do is import the database backup file, and then re-run this fixsettings.sql file to make it point locally again. Definitely makes things a lot simpler, and you can eventually schedule a cron job to backup your production blog and pull it into your local machine on a schedule.

请注意,您应该保留该文件,因为任何时候您都想使用最新的博客文章更新本地副本,您要做的就是导入数据库备份文件,然后重新运行该fixsettings.sql文件来制作该文件。再次指向本地。 绝对使事情变得简单得多,您最终可以安排cron作业来备份您的生产博客,并按计划将其拉入本地计算机。

Now you should be able to navigate to http://localhost/wordpress/wp-admin/ and login with your regular username. You’ve now got a development copy of your blog!

现在,您应该可以导航到http:// localhost / wordpress / wp-admin /并使用常规用户名登录。 现在,您已经获得了博客的开发副本!

翻译自: https://www.howtogeek.com/howto/ubuntu/make-a-backup-copy-of-your-production-wordpress-blog-on-ubuntu/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值