復(fù)制 WordPress 似乎從來(lái)都不是一件容易的事
我經(jīng)常喜歡基于現(xiàn)有網(wǎng)站作為模板啟動(dòng)一個(gè)新的 WordPress 網(wǎng)站。主題、插件和設(shè)置的配置一開(kāi)始就非常有用,這與您必須從頭開(kāi)始重復(fù)所有內(nèi)容的全新安裝不同。
在構(gòu)建用于在 Digital Ocean 轉(zhuǎn)售的應(yīng)用程序映像中,我詳細(xì)介紹了可安裝、預(yù)配置和預(yù)優(yōu)化的 WordPress Droplet 的構(gòu)建過(guò)程。本質(zhì)上,它是一個(gè)數(shù)字海洋圖像,可以在幾分鐘內(nèi)啟動(dòng)一個(gè)完全加載的 WordPress 網(wǎng)站。但是,更常見(jiàn)的是,我想將 WordPress 網(wǎng)站添加到我自己的現(xiàn)有服務(wù)器之一。
有很多方法可以做到這一點(diǎn),但我經(jīng)常發(fā)現(xiàn)它們需要特定而詳細(xì)的方法,我似乎每次都必須重新學(xué)習(xí)。我決定是時(shí)候編寫(xiě)一個(gè) linux shell 腳本了,它可以在幾分鐘內(nèi)為我完成所有工作。
在本教程中,我將引導(dǎo)您完成我的研究和生成的 WordPress 克隆腳本。我希望你喜歡它——當(dāng)我完成它時(shí),我認(rèn)為它效果很好。
在我們開(kāi)始之前,請(qǐng)記住,我確實(shí)嘗試參與下面的討論。如果您有問(wèn)題或主題建議,請(qǐng)?jiān)谙旅姘l(fā)表評(píng)論或通過(guò) Twitter @reifman 與我聯(lián)系。您也可以直接給我發(fā)電子郵件。我希望你們中的許多人會(huì)對(duì)這個(gè)腳本有更好的想法和改進(jìn)。我很高興收到您的來(lái)信。
WordPress 遷移的其他方法
通常,您可以通過(guò)將現(xiàn)有網(wǎng)站遷移到新服務(wù)器(本質(zhì)上是復(fù)制它)并在副本上進(jìn)行構(gòu)建,同時(shí)保持源網(wǎng)站完好無(wú)損來(lái)啟動(dòng)新網(wǎng)站。有多種方法可以實(shí)現(xiàn)這一點(diǎn)。
在使用 WordPress 將 WordPress 遷移到新服務(wù)器發(fā)布中,我寫(xiě)了有關(guān)使用 Duplicator 插件來(lái)執(zhí)行此操作的文章,但我發(fā)現(xiàn)該過(guò)程很麻煩。每次我需要移動(dòng)站點(diǎn)時(shí)重新熟悉復(fù)制器也很困難。
最近,我在使用 CodeGuard for Envato Tuts+ 備份和恢復(fù)您的 WordPress 網(wǎng)站中寫(xiě)了有關(guān)此內(nèi)容的文章。這項(xiàng)服務(wù)使這個(gè)過(guò)程變得更加容易。很快,我們將發(fā)布如何簡(jiǎn)化管理多個(gè) WordPress 網(wǎng)站,其中描述了使用 ManageWP 的許多強(qiáng)大優(yōu)勢(shì)。它具有克隆功能,但需要 FTP — 出于安全原因,我避免在我的服務(wù)器上運(yùn)行 FTP。
還有 Rachel McCollin 的 Envato Tuts+ 系列兩部分:移動(dòng) WordPress:簡(jiǎn)介和移動(dòng) WordPress:使用插件移動(dòng)您的網(wǎng)站。 WPBeginner 上有一個(gè)使用 BackupBuddy 的教程。最后,WPClone 不需要 FTP,但需要干凈的 WordPress 安裝才能構(gòu)建。
您可以從所有這些教程和服務(wù)中學(xué)到很多東西,但我想看看是否可以創(chuàng)建一個(gè)命令行腳本,每次都能更快、更輕松地克隆 WordPress 網(wǎng)站。
規(guī)劃腳本
為了編寫(xiě)本教程,我很大程度上依賴于其他人早期的作品來(lái)快速了解 bash 腳本和 WordPress 網(wǎng)站操作的知識(shí)。我從來(lái)不認(rèn)為自己是專業(yè)的 Linux 系統(tǒng)管理員。最終,我決定在 Brian Gallagher 的 WordPress Bash 安裝腳本之上構(gòu)建我的克隆腳本。
注意:這些是基于 debian 的安裝腳本;其他版本的 Linux(例如 RedHat 和 centos)對(duì)于 apache 和不同的實(shí)用程序有不同的路徑。
這是加拉格爾對(duì)其基本腳本的描述:
下載最新的 WP 版本,使用用戶提供的數(shù)據(jù)庫(kù)名稱、用戶名和密碼更新 wp-config,創(chuàng)建并 CHMOD 的上傳目錄,將所有文件復(fù)制到運(yùn)行腳本的根目錄中,然后刪除自身!
這里有很多組織良好的腳本,但我想制作一些可以克隆活動(dòng)站點(diǎn)的東西。讓我們回顧一下典型 WordPress 配置的架構(gòu)。
WordPress 網(wǎng)站的初始組件
典型的 WordPress 安裝有四個(gè)用于克隆的主要組件:
- 網(wǎng)站的目錄樹(shù)
- 數(shù)據(jù)庫(kù)
- 網(wǎng)絡(luò)服務(wù)器配置,例如Apache 配置文件
- 域映射
我們還需要信息、訪問(wèn)權(quán)限和安全設(shè)置:
- 服務(wù)器管理帳戶和密碼
- mysql 服務(wù)器用戶名和密碼
- 網(wǎng)站的源目錄
- 網(wǎng)站的網(wǎng)絡(luò)服務(wù)器配置文件
- 數(shù)據(jù)庫(kù)名稱、用戶名和密碼
以下是我們需要為克隆站點(diǎn)指定的內(nèi)容:
- 克隆網(wǎng)站的目標(biāo)目錄
- 克隆的數(shù)據(jù)庫(kù)名稱、用戶名和密碼
- 克隆網(wǎng)站的網(wǎng)絡(luò)服務(wù)器配置文件
腳本需要做什么
- 通過(guò)配置變量或用戶輸入獲取所有設(shè)置。
- 復(fù)制網(wǎng)站目錄并將其恢復(fù)到目標(biāo)目錄。
- 導(dǎo)出源數(shù)據(jù)庫(kù)并將其導(dǎo)入目標(biāo)數(shù)據(jù)庫(kù)。
- 確保這些目錄具有適當(dāng)?shù)臋?quán)限。
- 復(fù)制服務(wù)器配置文件并更新域和目錄設(shè)置。
- 重新加載網(wǎng)絡(luò)服務(wù)器。
我們必須手動(dòng)更新新目標(biāo)域的 DNS。我建議您在開(kāi)始之前創(chuàng)建 DNS 記錄,以便在克隆您的網(wǎng)站后它們可以準(zhǔn)備就緒。沒(méi)有什么比克隆站點(diǎn)而無(wú)法測(cè)試域名更好的了,因?yàn)槟诘却?DNS。
克隆腳本的實(shí)現(xiàn)方法
現(xiàn)在,我們準(zhǔn)備好逐步了解腳本的架構(gòu)是如何工作的。再次,我首先利用了 Gallagher 的 WordPress 安裝腳本,并且您需要頂部的初始 bash 行:
#!/bin/bash -e # Clone a WordPress site via Bash script clear echo "===================================================" echo "Clone WordPress Script" echo "==================================================="
準(zhǔn)備您的 DNS 設(shè)置
在復(fù)制站點(diǎn)之前,您需要為克隆站點(diǎn)配置 DNS。您可以在此處閱讀有關(guān)新 WordPress 站點(diǎn)的 DNS 配置的信息。我也對(duì)這個(gè) Envato Tuts+ 教程“學(xué)習(xí)和使用 DNS 記錄簡(jiǎn)介”感到很興奮。
基本上,您需要?jiǎng)?chuàng)建一條 A 記錄或 CNAME,將所需的克隆 URL 路由到我們正在復(fù)制的服務(wù)器。
設(shè)置權(quán)限
在我的服務(wù)器上,我正在創(chuàng)建一個(gè)名為clnewp.sh 的bash 腳本。它將需要可執(zhí)行權(quán)限:
chmod +x clonewp.sh
然后,一旦完成,您可以像這樣運(yùn)行它:
sudo bash clonewp.sh
我建議以 sudo 身份運(yùn)行腳本,這樣您就不會(huì)遇到文件權(quán)限問(wèn)題。
設(shè)置默認(rèn)值
出于測(cè)試目的,我創(chuàng)建了使用默認(rèn)設(shè)置預(yù)加載腳本的功能。它幫助我反復(fù)運(yùn)行測(cè)試,而不必一遍又一遍地輸入所有內(nèi)容。我還認(rèn)為這對(duì)于以后想要修改腳本或以其他方式使用它的人來(lái)說(shuō)可能很有用。
以下是所有默認(rèn)設(shè)置:
# Set Default Settings (helpful for testing) default_mysql_user=$"root-admin" default_mysql_pass=$"super-strong-password" default_source_domain=$"gardening.io" default_target_domain=$"cycling.io" default_source_directory=$"/var/www/gardening" default_target_directory=$"/var/www/cycling" default_apache_directory=$"/etc/apache2/sites-available" default_source_conf=$"gardening.conf" default_target_conf=$"cycling.conf" default_source_dbname=$"gardening" default_source_dbuser=$"user_for_garden" default_source_dbpass=$"pwd_garden" default_target_dbname=$"cycling" default_target_dbuser=$"user_for_cycling" default_target_dbpass=$"pwd_cycling" NOW=$(date +"%Y-%m-%d-%H%M")
我知道這看起來(lái)很多,但我發(fā)現(xiàn)擁有一個(gè) MySQL 主用戶和密碼對(duì)于數(shù)據(jù)庫(kù)備份、數(shù)據(jù)庫(kù)創(chuàng)建和導(dǎo)入很有用。然而,擁有特定于站點(diǎn)的數(shù)據(jù)庫(kù)用戶和密碼來(lái)設(shè)置目標(biāo)數(shù)據(jù)庫(kù)權(quán)限以及在 wp-config.php 文件中搜索和替換也很有用。它使最終的克隆過(guò)程非常無(wú)縫。
我使用 NOW 時(shí)間戳來(lái)確保我們創(chuàng)建的檔案是唯一的。
請(qǐng)求設(shè)置
以下代碼向用戶顯示默認(rèn)值,并允許他們接受它(按回車鍵)或替換它:
# Request Source Settings read -p "Source Domain (e.g. "$default_source_domain"): " source_domain source_domain=${source_domain:-$default_source_domain} echo $source_domain read -p "Source Directory (no trailing slash e.g. "$default_source_directory"): " source_directory source_directory=${source_directory:-$default_source_directory} echo $source_directory read -p "Source Database Name (e.g. "$default_source_dbname"): " source_dbname source_dbname=${source_dbname:-$default_source_dbname} echo $source_dbname read -p "Source Database User (e.g. "$default_source_dbuser"): " source_dbuser source_dbuser=${source_dbuser:-$default_source_dbuser} echo $source_dbuser read -p "Source Database Pass (e.g. "$default_source_dbpass"): " source_dbpass source_dbpass=${source_dbpass:-$default_source_dbpass} echo $source_dbpass # Request Source Settings read -p "Source Conf File (e.g. "$default_source_conf"): " source_conf source_conf=${source_conf:-$default_source_conf} echo $source_conf # Request Target Settings read -p "Target Domain (e.g. "$default_target_domain"): " target_domain target_domain=${target_domain:-$default_target_domain} echo $target_domain read -p "Target Directory (no trailing slash e.g. "$default_target_directory"): " target_directory target_directory=${target_directory:-$default_target_directory} echo $target_directory read -p "Target Database Name (e.g. "$default_target_dbname"): " target_dbname target_dbname=${target_dbname:-$default_target_dbname} echo $target_dbname read -p "Target Database User (e.g. "$default_target_dbuser"): " target_dbuser target_dbuser=${target_dbuser:-$default_target_dbuser} echo $target_dbuser read -p "Target Database Pass (e.g. "$default_target_dbpass"): " target_dbpass target_dbpass=${target_dbpass:-$default_target_dbpass} echo $target_dbpass read -p "Target Conf File (e.g. "$default_target_conf"): " target_conf target_conf=${target_conf:-$default_target_conf} echo $target_conf
一旦我們收集了用戶的所有設(shè)置,我們就會(huì)詢問(wèn)他們是否愿意開(kāi)始:
echo "Clone now? (y/n)" read -e run if [ "$run" == n ] ; then exit else echo "===================================================" echo "WordPress Cloning is Beginning" echo "==================================================="
復(fù)制目錄樹(shù)
現(xiàn)在事情進(jìn)展得更快了。我們創(chuàng)建源站點(diǎn)的 tarball,創(chuàng)建目標(biāo)目錄并在那里提取 tarball:
#backup source_directory cd $source_directory # add -v option to these if you want to see verbose file listings tar -czf source_clone_$NOW.tar.gz . #unzip clone in target directory mkdir -p $target_directory tar -xzf source_clone_$NOW.tar.gz -C $target_directory #remove tarball of source rm source_clone_$NOW.tar.gz cd $target_directory
我們還運(yùn)行 WordPress 的標(biāo)準(zhǔn)文件權(quán)限,以確保一切設(shè)置正確且安全:
# Reset Directory Permissions find $target_directory -type d -exec chmod 755 {} ; find $target_directory -type f -exec chmod 644 {} ;
更新 WP-Config 文件
接下來(lái),我們使用perl搜索并用目標(biāo)數(shù)據(jù)庫(kù)信息替換源數(shù)據(jù)庫(kù)身份驗(yàn)證:
#set database details with perl find and replace perl -pi -e "s/$source_dbname/$target_dbname/g" wp-config.php perl -pi -e "s/$source_dbuser/$target_dbuser/g" wp-config.php perl -pi -e "s/$source_dbpass/$target_dbpass/g" wp-config.php echo "define('RELOCATE',true);" | tee -a wp-config.php #echo "define('WP_HOME','http://$target_domain');" | tee -a wp-config.php #echo "define('WP_SITEURL','http://$target_domain');" | tee -a wp-config.php echo "================================" echo "Directory duplicated" echo "================================"
我還將 RELOCATE 設(shè)置添加到文件末尾。如果您愿意,可以將其替換為靜態(tài) WP_HOME 和 WP_SITEURL 設(shè)置。
復(fù)制數(shù)據(jù)庫(kù)
接下來(lái),我們轉(zhuǎn)儲(chǔ)數(shù)據(jù)庫(kù),使用用戶提供的權(quán)限創(chuàng)建一個(gè)新數(shù)據(jù)庫(kù),然后將數(shù)據(jù)庫(kù)導(dǎo)入其中:
# Begin Database Duplication # Export the database mysqldump -u$mysql_user -p$mysql_pass $source_dbname > $target_directory/clone_$NOW.sql # Create the target database and permissions mysql -u$mysql_user -p$mysql_pass -e "create database $target_dbname; GRANT ALL PRIVILEGES ON $target_dbname.* TO '$target_dbuser'@'localhost' IDENTIFIED BY '$target_dbpass'" # Import the source database into the target mysql -u$mysql_user -p$mysql_pass $target_dbname <p>我再次發(fā)現(xiàn),最好在這些活動(dòng)中使用主 MySQL 身份驗(yàn)證,同時(shí)根據(jù)源站點(diǎn)和單站點(diǎn)克隆設(shè)置配置數(shù)據(jù)庫(kù)設(shè)置。</p> <h3>復(fù)制 Web 服務(wù)器配置</h3> <p>最后,我們準(zhǔn)備好結(jié)束一切并按下啟動(dòng)按鈕。我很少看到此類腳本管理 Web 服務(wù)器配置的額外步驟。所以我也想這么做。</p> <p>我將源站點(diǎn)的 Apache .conf 文件復(fù)制到克隆的新 .conf 文件中。我使用 perl 對(duì)域和目錄路徑進(jìn)行字符串替換。然后,我使用 Apache 激活了該站點(diǎn)并重新加載了 Web 服務(wù)器:</p> <pre class="brush:shell;toolbal:false;">#Activate Web Configuration cp $default_apache_directory/$source_conf $default_apache_directory/$target_conf #set database details with perl find and replace perl -pi -e "s/$source_domain/$target_domain/g" $default_apache_directory/$target_conf perl -pi -e "s|${source_directory}|${target_directory}|g" $default_apache_directory/$target_conf a2ensite $target_conf service apache2 reload echo "================================" echo "Web configuration added" echo "================================" echo "Clone is complete." echo "Test at http://"$target_domain echo "================================" fi
而且,就是這樣。以下是腳本在現(xiàn)實(shí)生活中的運(yùn)行情況:
=================================================== Clone WordPress Script =================================================== MySQL Master Username (e.g. root-admin): harry_potter harry_potter MySQL Master Password (e.g. super-strong-password): voldemoort~jenny7! voldemoort~jenny7! Source Domain (e.g. gardening.io): gardening.io Source Directory (no trailing slash e.g. /var/www/gardening): /var/www/gardening Source Database Name (e.g. gardening): database_gardening database_gardening Source Database User (e.g. user_for_garden): hermione hermione Source Database Pass (e.g. pwd_garden): !987654321abcdefgh# !987654321abcdefgh# Source Conf File (e.g. gardening.conf): gardening.conf gardening.conf Target Domain (e.g. cycling.io): cycling.io Target Directory (no trailing slash e.g. /var/www/cycling): /var/www/cycling /var/www/cycling Target Database Name (e.g. cycling): database_cycling database_cycling Target Database User (e.g. user_for_cycling): hedwig hedwig Target Database Pass (e.g. pwd_cycling): pwd_for_cycling_not_hogwartz Target Conf File (e.g. cycling.conf): 0007b-cycling.conf 0007b-cycling.conf Clone now? (y/n) y =================================================== WordPress Cloning is Beginning =================================================== tar: .: file changed as we read it define('RELOCATE',true); ================================ Directory duplicated ================================ ================================ Database duplicated ================================ Enabling site 0007b-cycling. To activate the new configuration, you need to run: service apache2 reload * Reloading web server apache2 * ================================ Web configuration added ================================ Clone is complete. Test at http://cycling.io ================================
在我的小型 WordPress 網(wǎng)站上,復(fù)制只需要 30 到 90 秒!
精美印刷
您還需要了解更多事情。
首先直接登錄路徑
首先,要登錄克隆的網(wǎng)站,您需要使用 wp-login.php 路徑,而不是使用重定向到源網(wǎng)站網(wǎng)址的 wp-admin,例如http://clone.io/wp-login.php如下圖:
切換域名
由于 WordPress 在數(shù)據(jù)庫(kù)中硬編碼了大部分源域,我發(fā)現(xiàn)使用 wp-config.php 中的 RELOCATE 設(shè)置可以輕松通過(guò)常規(guī) > 設(shè)置進(jìn)行更新。您只需使用新的目標(biāo)網(wǎng)址保存表單即可:
保存克隆的目標(biāo) URL 后,您可以從 wp 中刪除 RELOCATE 設(shè)置-config.php 手動(dòng)。
但是,一位同事建議您可能需要使用 InterconnectIT 的 WordPress 數(shù)據(jù)庫(kù)搜索和替換等工具。 Envato Tuts+ 中的“跨主機(jī)、服務(wù)器和 URL 遷移 WordPress”中也對(duì)此進(jìn)行了記錄。
最終腳本
這是 wpclone.sh 的最終腳本 – 請(qǐng)隨意更改默認(rèn)值:
#!/bin/bash -e # Clone a WordPress site via Bash script clear echo "===================================================" echo "Clone WordPress Script" echo "===================================================" # Set Default Settings (helpful for testing) default_mysql_user=$"root-admin" default_mysql_pass=$"super-strong-password" default_source_domain=$"gardening.io" default_target_domain=$"cycling.io" default_source_directory=$"/var/www/gardening" default_target_directory=$"/var/www/cycling" default_apache_directory=$"/etc/apache2/sites-available" default_source_conf=$"gardening.conf" default_target_conf=$"cycling.conf" default_source_dbname=$"gardening" default_source_dbuser=$"user_for_garden" default_source_dbpass=$"pwd_garden" default_target_dbname=$"cycling" default_target_dbuser=$"user_for_cycling" default_target_dbpass=$"pwd_cycling" NOW=$(date +"%Y-%m-%d-%H%M") #Request MySQL Admin read -p "MySQL Master Username (e.g. "$default_mysql_user"): " mysql_user mysql_user=${mysql_user:-$default_mysql_user} echo $mysql_user read -p "MySQL Master Password (e.g. "$default_mysql_pass"): " mysql_pass mysql_pass=${mysql_pass:-$default_mysql_pass} echo $mysql_pass # Request Source Settings read -p "Source Domain (e.g. "$default_source_domain"): " source_domain source_domain=${source_domain:-$default_source_domain} echo $source_domain read -p "Source Directory (no trailing slash e.g. "$default_source_directory"): " source_directory source_directory=${source_directory:-$default_source_directory} echo $source_directory read -p "Source Database Name (e.g. "$default_source_dbname"): " source_dbname source_dbname=${source_dbname:-$default_source_dbname} echo $source_dbname read -p "Source Database User (e.g. "$default_source_dbuser"): " source_dbuser source_dbuser=${source_dbuser:-$default_source_dbuser} echo $source_dbuser read -p "Source Database Pass (e.g. "$default_source_dbpass"): " source_dbpass source_dbpass=${source_dbpass:-$default_source_dbpass} echo $source_dbpass # Request Source Settings read -p "Source Conf File (e.g. "$default_source_conf"): " source_conf source_conf=${source_conf:-$default_source_conf} echo $source_conf # Request Target Settings read -p "Target Domain (e.g. "$default_target_domain"): " target_domain target_domain=${target_domain:-$default_target_domain} echo $target_domain read -p "Target Directory (no trailing slash e.g. "$default_target_directory"): " target_directory target_directory=${target_directory:-$default_target_directory} echo $target_directory read -p "Target Database Name (e.g. "$default_target_dbname"): " target_dbname target_dbname=${target_dbname:-$default_target_dbname} echo $target_dbname read -p "Target Database User (e.g. "$default_target_dbuser"): " target_dbuser target_dbuser=${target_dbuser:-$default_target_dbuser} echo $target_dbuser read -p "Target Database Pass (e.g. "$default_target_dbpass"): " target_dbpass target_dbpass=${target_dbpass:-$default_target_dbpass} echo $target_dbpass read -p "Target Conf File (e.g. "$default_target_conf"): " target_conf target_conf=${target_conf:-$default_target_conf} echo $target_conf echo "Clone now? (y/n)" read -e run if [ "$run" == n ] ; then exit else echo "===================================================" echo "WordPress Cloning is Beginning" echo "===================================================" #backup source_directory cd $source_directory # add -v option to these if you want to see verbose file listings tar -czf source_clone_$NOW.tar.gz . #unzip clone in target directory mkdir -p $target_directory tar -xzf source_clone_$NOW.tar.gz -C $target_directory #remove tarball of source rm source_clone_$NOW.tar.gz cd $target_directory # Reset Directory Permissions find $target_directory -type d -exec chmod 755 {} ; find $target_directory -type f -exec chmod 644 {} ; #set database details with perl find and replace perl -pi -e "s/$source_dbname/$target_dbname/g" wp-config.php perl -pi -e "s/$source_dbuser/$target_dbuser/g" wp-config.php perl -pi -e "s/$source_dbpass/$target_dbpass/g" wp-config.php echo "define('RELOCATE',true);" | tee -a wp-config.php #echo "define('WP_HOME','http://$target_domain');" | tee -a wp-config.php #echo "define('WP_SITEURL','http://$target_domain');" | tee -a wp-config.php echo "================================" echo "Directory duplicated" echo "================================" # Begin Database Duplication # Export the database mysqldump -u$mysql_user -p$mysql_pass $source_dbname > $target_directory/clone_$NOW.sql # Create the target database and permissions mysql -u$mysql_user -p$mysql_pass -e "create database $target_dbname; GRANT ALL PRIVILEGES ON $target_dbname.* TO '$target_dbuser'@'localhost' IDENTIFIED BY '$target_dbpass'" # Import the source database into the target mysql -u$mysql_user -p$mysql_pass $target_dbname如果您有建議和定制,請(qǐng)告訴我。在下面的評(píng)論中發(fā)表您的想法。
清理以進(jìn)行擴(kuò)展測(cè)試
以下行可能有助于您刪除和撤消克隆的測(cè)試站點(diǎn)。您可以根據(jù)您的需要對(duì)其進(jìn)行自定義:
sudo rm -ifr /var/www/clone sudo a2dissite clone.conf sudo service apache2 reload sudo rm /etc/apache2/sites-available/clone.conf mysql -u root -p -e "drop database clone;"
更改 Wp-Config.php 中的安全密鑰
您還可以通過(guò)手動(dòng)替換目標(biāo)站點(diǎn)的 wp-config.php 中的身份驗(yàn)證密鑰和鹽來(lái)更好地保護(hù)您的新 WordPress 站點(diǎn):
/**#@+ * Authentication Unique Keys and Salts. * * Change these to different unique phrases! * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. * * @since 2.6.0 */ define('AUTH_KEY', '+9%S?YVnr%5Vr!Et4J,@9/Z^.kT_Lu~5SGwr9=|Y &D-ARSWf$mF#J_3U:/iE>-R'); define('SECURE_AUTH_KEY', 'e3Wr7%Aa7H1,f<sr>:!5@y:Q;c01dL '); define('LOGGED_IN_KEY', '1I%pW%UyjRMqy__Da)siA)+V]Ur$9uXPmxv|eBjM~-m&-<wey define>9kCZIo|%|cisp1R}9cJa,,g|)~EKBQUig7Uv.-8?q%lmFte,P>,]f#.}i`Wx8S+_S@&.('); /**#@-*/ </wey></sr>
您只需訪問(wèn) https://api.wordpress.org/secret-key/1.1/salt/ 并將它們剪切并粘貼到您的 wp-config.php 文件中即可:
現(xiàn)在,如果您是 Linux 腳本純粹主義者,我將允許您更新 Gallagher 的 WordPress Bash 安裝腳本。他的腳本復(fù)制了默認(rèn)的 WordPress wp-config.php,因此他可以使用可預(yù)測(cè)的源字符串來(lái)替換他的腳本生成的密鑰:
#set WP salts perl -i -pe' BEGIN { @chars = ("a" .. "z", "A" .. "Z", 0 .. 9); push @chars, split //, "!@#$%^&*()-_ []{}~`+=,.;:/?|"; sub salt { join "", map $chars[ rand @chars ], 1 .. 64 } } s/put your unique phrase here/salt()/ge ' wp-config.php
我從未編寫(xiě)過(guò)正則表達(dá)式來(lái)替換我們?cè)凑军c(diǎn)的動(dòng)態(tài)預(yù)先存在的 wp-config.php 文件中的鍵值。如果您決定這樣做,請(qǐng)?jiān)谠u(píng)論中分享并提前致謝。
有疑問(wèn)嗎?
我非常喜歡讓這個(gè)腳本工作。或者,我至少應(yīng)該說(shuō)我喜歡在完成后運(yùn)行它。我希望我很久以前就創(chuàng)建了它,因?yàn)樗浅S行Ш透咝АN铱梢钥寺⌒⌒?WordPress 網(wǎng)站,并在大約 60 秒內(nèi)讓它們?cè)谖业姆?wù)器上運(yùn)行。其他插件或復(fù)制選項(xiàng)都不是那么無(wú)縫。
如果您有任何疑問(wèn),請(qǐng)?jiān)谙旅姘l(fā)布。或者,您可以通過(guò) Twitter @reifman 聯(lián)系我或直接給我發(fā)電子郵件。請(qǐng)查看我的 Envato Tuts+ 講師頁(yè)面,查看我編寫(xiě)的其他教程,例如我的創(chuàng)業(yè)系列(使用 PHP 構(gòu)建您的創(chuàng)業(yè)公司)。
相關(guān)鏈接
- WordPress Bash 安裝腳本,作者:Brian Gallagher
- 移動(dòng) WordPress
- 用于完整 WordPress 備份的 Shell 腳本,作者:Konstantin Kovshenin
- CodeCanyon 上提供 WordPress 插件