亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄
#複製 WordPress 似乎從來都不是一件容易的事
#WordPress 遷移的其他方法
規(guī)劃腳本
WordPress 網(wǎng)站的初始元件
腳本需要做什麼
克隆腳本的實(shí)作方法
準(zhǔn)備您的 DNS 設(shè)定
設(shè)定權(quán)限
設(shè)定預(yù)設(shè)值
請求設(shè)定
複製目錄樹
更新 WP-Config 檔案
複製資料庫
複製 Web 伺服器設(shè)定
精美印刷
首先直接登入路徑
切換網(wǎng)域
最終腳本
清理以進(jìn)行擴(kuò)展測試
更改 Wp-Config.php 中的安全密鑰
有疑問嗎?
相關(guān)鏈接
首頁 CMS教程 &#&按 在Linux中克隆WordPress

在Linux中克隆WordPress

Sep 03, 2023 am 08:25 AM
linux wordpress 複製

在Linux中克隆WordPress

#複製 WordPress 似乎從來都不是一件容易的事

我經(jīng)常喜歡基於現(xiàn)有網(wǎng)站作為模板啟動(dòng)新的 WordPress 網(wǎng)站。主題、外掛和設(shè)定的配置一開始就非常有用,這與您必須從頭開始重複所有內(nèi)容的全新安裝不同。

在建置用於在 Digital Ocean 轉(zhuǎn)售的應(yīng)用程式映像中,我詳細(xì)介紹了可安裝、預(yù)先設(shè)定和預(yù)先最佳化的 WordPress Droplet 的建置流程。本質(zhì)上,它是一個(gè)數(shù)位海洋圖像,可以在幾分鐘內(nèi)啟動(dòng)一個(gè)完全加載的 WordPress 網(wǎng)站。但是,更常見的是,我想將 WordPress 網(wǎng)站新增到我自己的現(xiàn)有伺服器之一。

有很多方法可以做到這一點(diǎn),但我經(jīng)常發(fā)現(xiàn)它們需要特定而詳細(xì)的方法,我似乎每次都必須重新學(xué)習(xí)。我決定是時(shí)候編寫一個(gè) Linux shell 腳本了,它可以在幾分鐘內(nèi)為我完成所有工作。

在本教程中,我將引導(dǎo)您完成我的研究和生成的 WordPress 克隆腳本。我希望你喜歡它——當(dāng)我完成它時(shí),我認(rèn)為它效果很好。

在我們開始之前,請記住,我確實(shí)嘗試參與下面的討論。如果您有問題或主題建議,請?jiān)谙旅姘l(fā)表評論或透過 Twitter @reifman 與我聯(lián)繫。您也可以直接寄電子郵件給我。我希望你們中的許多人會(huì)對這個(gè)腳本有更好的想法和改進(jìn)。我很高興收到您的來信。

#WordPress 遷移的其他方法

通常,您可以透過將現(xiàn)有網(wǎng)站遷移到新伺服器(本質(zhì)上是複製它)並在副本上進(jìn)行構(gòu)建,同時(shí)保持來源網(wǎng)站完好無損來啟動(dòng)新網(wǎng)站。有多種方法可以實(shí)現(xiàn)這一點(diǎn)。

在使用 WordPress 將 WordPress 遷移到新伺服器發(fā)布中,我寫了有關(guān)使用 Duplicator 外掛程式來執(zhí)行此操作的文章,但我發(fā)現(xiàn)該過程很麻煩。每次我需要移動(dòng)網(wǎng)站時(shí)重新熟悉複製器也很困難。

最近,我在使用 CodeGuard for Envato Tuts+ 備份和還原您的 WordPress 網(wǎng)站中寫了有關(guān)此內(nèi)容的文??章。這項(xiàng)服務(wù)使這個(gè)過程變得更加容易。很快,我們將發(fā)佈如何簡化管理多個(gè) WordPress 網(wǎng)站,其中描述了使用 ManageWP 的許多強(qiáng)大優(yōu)勢。它具有克隆功能,但需要 FTP — 出於安全原因,我避免在我的伺服器上執(zhí)行 FTP。

還有 Rachel McCollin 的 Envato Tuts+ 系列兩部分:行動(dòng) WordPress:簡介和行動(dòng) WordPress:使用外掛程式移動(dòng)您的網(wǎng)站。 WPBeginner 上有一個(gè)使用 BackupBuddy 的教學(xué)。最後,WPClone 不需要 FTP,但需要乾淨(jìng)的 WordPress 安裝才能建置。

您可以從所有這些教學(xué)和服務(wù)中學(xué)到很多東西,但我想看看是否可以建立命令列腳本,每次都能更快、更輕鬆地克隆 WordPress 網(wǎng)站。

規(guī)劃腳本

為了編寫本教程,我很大程度上依賴其他人早期的作品來快速了解 bash 腳本和 WordPress 網(wǎng)站操作的知識(shí)。我從來不認(rèn)為自己是專業(yè)的 Linux 系統(tǒng)管理員。最終,我決定在 Brian Gallagher 的 WordPress Bash 安裝腳本之上建立我的克隆腳本。

注意:這些是基於 Debian 的安裝腳本;其他版本的 Linux(例如 RedHat 和 CentOS)對於 Apache 和不同的實(shí)用程式有不同的路徑。

這是加拉格爾對其基本腳本的描述:

下載最新的 WP 版本,使用使用者提供的資料庫名稱、使用者名稱和密碼更新 wp-config,建立並 CHMOD 的上傳目錄,將所有檔案複製到執(zhí)行腳本的根目錄中,然後刪除自身!

這裡有很多組織良好的腳本,但我想製作一些可以克隆活動(dòng)網(wǎng)站的東西。讓我們回顧一下典型 WordPress 配置的架構(gòu)。

WordPress 網(wǎng)站的初始元件

典型的 WordPress 安裝有四個(gè)用於複製的主要元件:

  1. 網(wǎng)站的目錄樹
  2. 資料庫
  3. 網(wǎng)路伺服器配置,例如Apache 設(shè)定檔
  4. 域映射

我們還需要資訊、存取權(quán)限和安全設(shè)定:

  • 伺服器管理帳戶和密碼
  • MySql 伺服器使用者名稱和密碼
  • 網(wǎng)站的來源目錄
  • 網(wǎng)站的網(wǎng)頁伺服器設(shè)定檔
  • 資料庫名稱、使用者名稱和密碼

以下是我們需要為克隆網(wǎng)站指定的內(nèi)容:

  • 複製網(wǎng)站的目標(biāo)目錄
  • 克隆的資料庫名稱、使用者名稱和密碼
  • 複製網(wǎng)站的網(wǎng)頁伺服器設(shè)定檔

腳本需要做什麼

  • 透過設(shè)定變數(shù)或使用者輸入來取得所有設(shè)定。
  • 複製網(wǎng)站目錄並將其還原到目標(biāo)目錄。
  • 匯出來源資料庫並將其匯入目標(biāo)資料庫。
  • 確保這些目錄具有適當(dāng)?shù)臋?quán)限。

  • 複製伺服器設(shè)定檔並更新網(wǎng)域和目錄設(shè)定。
  • 重新載入網(wǎng)頁伺服器。

我們必須手動(dòng)更新新目標(biāo)網(wǎng)域的 DNS。我建議您在開始之前建立 DNS 記錄,以便在克隆您的網(wǎng)站後它們可以準(zhǔn)備就緒。沒有什麼比克隆網(wǎng)站而無法測試網(wǎng)域更好的了,因?yàn)槟诘却?DNS。

克隆腳本的實(shí)作方法

現(xiàn)在,我們準(zhǔn)備好逐步了解腳本的架構(gòu)是如何運(yùn)作的。再次,我首先利用了 Gallagher 的 WordPress 安裝腳本,並且您需要頂部的初始 bash 行:

#!/bin/bash -e
# Clone a WordPress site via Bash script
clear
echo "==================================================="
echo "Clone WordPress Script"
echo "==================================================="

準(zhǔn)備您的 DNS 設(shè)定

在複製網(wǎng)站之前,您需要為克隆網(wǎng)站設(shè)定 DNS。您可以在此處閱讀有關(guān)新 WordPress 網(wǎng)站的 DNS 配置的資訊。我也對這個(gè) Envato Tuts+ 教程「學(xué)習(xí)和使用 DNS 記錄簡介」感到很興奮。

基本上,您需要建立一條 A 記錄或 CNAME,將所需的複製 URL 路由到我們正在複製的伺服器。

設(shè)定權(quán)限

在我的伺服器上,我正在建立一個(gè)名為clnewp.sh 的bash 腳本。它將需要可執(zhí)行權(quán)限:

chmod +x clonewp.sh

然後,一旦完成,您可以像這樣運(yùn)行它:

sudo bash clonewp.sh

我建議以 sudo 身分執(zhí)行腳本,這樣您就不會(huì)遇到檔案權(quán)限問題。

設(shè)定預(yù)設(shè)值

出於測試目的,我創(chuàng)建了使用預(yù)設(shè)設(shè)定預(yù)先載入腳本的功能。它幫助我反覆運(yùn)行測試,而不必一遍又一遍地輸入所有內(nèi)容。我還認(rèn)為這對於以後想要修改腳本或以其他方式使用它的人來說可能很有用。

以下是所有預(yù)設(shè)設(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")

我知道這看起來很多,但我發(fā)現(xiàn)擁有一個(gè) MySQL 主用戶和密碼對於資料庫備份、資料庫建立和匯入很有用。然而,擁有特定於網(wǎng)站的資料庫使用者和密碼來設(shè)定目標(biāo)資料庫權(quán)限以及在 wp-config.php 檔案中搜尋和替換也很有用。它使最終的克隆過程非常無縫。

我使用 NOW 時(shí)間戳來確保我們建立的檔案是唯一的。

請求設(shè)定

以下程式碼向使用者顯示預(yù)設(shè)值,並允許他們接受它(按回車鍵)或替換它:

# 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ì)詢問他們是否願(yuàn)意開始:

echo "Clone now? (y/n)"
read -e run
if [ "$run" == n ] ; then
exit
else
echo "==================================================="
echo "WordPress Cloning is Beginning"
echo "==================================================="

複製目錄樹

現(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

我們也執(zhí)行 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 檔案

接下來,我們使用perl搜尋並用目標(biāo)資料庫資訊取代來源資料庫驗(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 "================================"

我也會(huì)將 RELOCATE 設(shè)定加入到檔案結(jié)尾。如果您願(yuàn)意,可以將其替換為靜態(tài) WP_HOMEWP_SITEURL 設(shè)定。

複製資料庫

接下來,我們轉(zhuǎn)儲(chǔ)資料庫,使用使用者提供的權(quán)限建立一個(gè)新資料庫,然後將資料庫匯入其中:

# 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 < $target_directory/clone_$NOW.sql
echo "================================"
echo "Database duplicated"
echo "================================"

我再次發(fā)現(xiàn),最好在這些活動(dòng)中使用主 MySQL 驗(yàn)證,同時(shí)根據(jù)來源網(wǎng)站和單一網(wǎng)站複製設(shè)定配置資料庫設(shè)定。

複製 Web 伺服器設(shè)定

最後,我們準(zhǔn)備好結(jié)束一切並按下啟動(dòng)按鈕。我很少看到此類腳本管理 Web 伺服器配置的額外步驟。所以我也想這麼做。

我將來源網(wǎng)站的 Apache .conf 檔案複製到複製的新 .conf 檔案中。我使用 perl 對域和目錄路徑進(jìn)行字串替換。然後,我使用 Apache 啟動(dòng)了該網(wǎng)站並重新載入了 Web 伺服器:

#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)站上,複製只需要 30 到 90 秒!

精美印刷

您還需要了解更多。

首先直接登入路徑

首先,要登入克隆的網(wǎng)站,您需要使用wp-login.php 路徑,而不是使用重定向到來源網(wǎng)站網(wǎng)址的wp-admin,例如http://clone.io/wp-login.php如下圖:

在Linux中克隆WordPress

切換網(wǎng)域

由於 WordPress 在資料庫中硬編碼了大部分來源域,我發(fā)現(xiàn)使用 wp-config.php 中的 RELOCATE 設(shè)定可以輕鬆透過常規(guī) > 設(shè)定進(jìn)行更新。您只需使用新的目標(biāo)網(wǎng)址儲(chǔ)存表單即可:

在Linux中克隆WordPress

儲(chǔ)存複製的目標(biāo) URL 後,您可以從 wp 中刪除 RELOCATE 設(shè)定-config.php 手動(dòng)。

但是,一位同事建議您可能需要使用 InterconnectIT 的 WordPress 數(shù)據(jù)庫搜索和替換等工具。 Envato Tuts+ 中的“跨主機(jī)、服務(wù)器和 URL 遷移 WordPress”中也對此進(jìn)行了記錄。

最終腳本

這是 wpclone.sh 的最終腳本 - 請隨意更改默認(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 < $target_directory/clone_$NOW.sql
echo "================================"
echo "Database duplicated"
echo "================================"
#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

如果您有建議和定制,請告訴我。在下面的評論中發(fā)表您的想法。

清理以進(jìn)行擴(kuò)展測試

以下行可能有助于您刪除和撤消克隆的測試站點(diǎn)。您可以根據(jù)您的需要對其進(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 中的安全密鑰

您還可以通過手動(dòng)替換目標(biāo)站點(diǎn)的 wp-config.php 中的身份驗(yàn)證密鑰和鹽來更好地保護(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[Sp&g.kJw,.)bR-9jz{uU&[R{[J]ITK8q>:!5@y:Q;c01dL ');
define('LOGGED_IN_KEY',    '1I%pW%UyjRMqy__Da)siA)+V]Ur$9uXPmxv|eBjM~-m&-<WEy&+XXb43uh8&aP+U');
define('NONCE_KEY',        'A9]+PFgvxYa^<B}_.F?9A,!&i-.b6E.I?&?U*)X.Vh+fq`SfE[XJG+MG|pg;y%Ah');
define('AUTH_SALT',        'gT (4]L{mm!|>9kC<%59rB7sbe1)jW0GCnfupJT+8z-z#%o@b|[QH=i@h|-/t!9S');
define('SECURE_AUTH_SALT', 'ON8K<,WSy8+F ~XaQpCwC8(a/{HksMh<T)QLD]s[-:yv+fx8!`<!*~mgB32X:w5k');
define('LOGGED_IN_SALT',   'vHJ%{=X6$ue>ZIo|%|cisp1R}9cJ< Rz-J;H|:O2A7$+*aGXMH!+KvD+tZ/I*U5$');
define('NONCE_SALT',       '[ytQ;C)BvgU!#>a,,g|)~EKBQUig7Uv.-8?q%lmFte,P>,]f#.}i`Wx8S+_S@&.(');
/**#@-*/

您只需訪問 https://api.wordpress.org/secret-key/1.1/salt/ 并將它們剪切并粘貼到您的 wp-config.php 文件中即可:

在Linux中克隆WordPress

現(xiàn)在,如果您是 Linux 腳本純粹主義者,我將允許您更新 Gallagher 的 WordPress Bash 安裝腳本。他的腳本復(fù)制了默認(rèn)的 WordPress wp-config.php,因此他可以使用可預(yù)測的源字符串來替換他的腳本生成的密鑰:

#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

我從未編寫過正則表達(dá)式來替換我們源站點(diǎn)的動(dòng)態(tài)預(yù)先存在的 wp-config.php 文件中的鍵值。如果您決定這樣做,請?jiān)谠u論中分享并提前致謝。

有疑問嗎?

我非常喜歡讓這個(gè)腳本工作?;蛘撸抑辽賾?yīng)該說我喜歡在完成后運(yùn)行它。我希望我很久以前就創(chuàng)建了它,因?yàn)樗浅S行Ш透咝АN铱梢钥寺⌒⌒?WordPress 網(wǎng)站,并在大約 60 秒內(nèi)讓它們在我的服務(wù)器上運(yùn)行。其他插件或復(fù)制選項(xiàng)都不是那么無縫。

如果您有任何疑問,請?jiān)谙旅姘l(fā)布?;蛘撸梢酝ㄟ^ Twitter @reifman 聯(lián)系我或直接給我發(fā)電子郵件。請查看我的 Envato Tuts+ 講師頁面,查看我編寫的其他教程,例如我的創(chuàng)業(yè)系列(使用 PHP 構(gòu)建您的創(chuàng)業(yè)公司)。

相關(guān)鏈接

  • WordPress Bash 安裝腳本,作者:Brian Gallagher
  • 移動(dòng) WordPress
  • 用于完整 WordPress 備份的 Shell 腳本,作者:Konstantin Kovshenin
  • CodeCanyon 上提供 WordPress 插件

以上是在Linux中克隆WordPress的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門話題

Laravel 教程
1597
29
PHP教程
1488
72
如何與Windows一起安裝Linux(雙啟動(dòng))? 如何與Windows一起安裝Linux(雙啟動(dòng))? Jun 18, 2025 am 12:19 AM

安裝Linux和Windows雙系統(tǒng)的關(guān)鍵是分區(qū)和啟動(dòng)設(shè)置。 1.準(zhǔn)備工作包括備份數(shù)據(jù)並壓縮現(xiàn)有分區(qū)騰出空間;2.使用Ventoy或Rufus製作Linux啟動(dòng)U盤,推薦Ubuntu;3.安裝時(shí)選擇“與其他系統(tǒng)並存”或手動(dòng)分區(qū)(/至少20GB,/home剩餘空間,swap可選);4.勾選安裝第三方驅(qū)動(dòng)以避免硬件問題;5.安裝後若未進(jìn)入Grub引導(dǎo)菜單,可用boot-repair修復(fù)引導(dǎo)或調(diào)整BIOS啟動(dòng)順序。只要步驟清晰、操作得當(dāng),整個(gè)過程並不復(fù)雜。

如何啟用EPEL(企業(yè)Linux的額外軟件包)存儲(chǔ)庫? 如何啟用EPEL(企業(yè)Linux的額外軟件包)存儲(chǔ)庫? Jun 17, 2025 am 09:15 AM

啟用EPEL倉庫的關(guān)鍵在於根據(jù)系統(tǒng)版本選擇正確的安裝方式。首先,確認(rèn)系統(tǒng)類型和版本,使用命令cat/etc/os-release獲取信息;其次,在CentOS/RockyLinux上通過dnfinstallepel-release啟用EPEL,8和9版本命令相同;第三,在RHEL上需手動(dòng)下載對應(yīng)版本的.repo文件並安裝;第四,遇到問題時(shí)可重新導(dǎo)入GPG密鑰,注意舊版本可能不被支持,也可考慮啟用epel-next獲取測試包。完成上述步驟後,使用dnfrepolist驗(yàn)證是否成功添加EPEL倉庫。

如何為初學(xué)者選擇Linux發(fā)行版? 如何為初學(xué)者選擇Linux發(fā)行版? Jun 19, 2025 am 12:09 AM

新手選擇Linux發(fā)行版應(yīng)先明確使用需求。 1.日常使用選Ubuntu或LinuxMint;編程開發(fā)適合Manjaro或Fedora;老舊設(shè)備用Lubuntu等輕量系統(tǒng);學(xué)習(xí)底層原理推薦CentOSStream或Debian。 2.穩(wěn)定性優(yōu)先考慮UbuntuLTS或Debian;追求新功能可選Arch或Manjaro。 3.社區(qū)支持方面,Ubuntu和LinuxMint資源豐富,Arch文檔偏技術(shù)向。 4.安裝難度上,Ubuntu、LinuxMint較簡單,Arch適合有基礎(chǔ)者。建議先試用再?zèng)Q定。

如何向Linux添加新磁盤 如何向Linux添加新磁盤 Jun 27, 2025 am 12:15 AM

添加新硬盤到Linux系統(tǒng)步驟如下:1.確認(rèn)硬盤被識(shí)別,使用lsblk或fdisk-l檢查;2.用fdisk或parted分區(qū),如fdisk/dev/sdb創(chuàng)建分區(qū)並保存;3.格式化分區(qū)為文件系統(tǒng),如mkfs.ext4/dev/sdb1;4.臨時(shí)掛載使用mount命令,如mount/dev/sdb1/mnt/data;5.修改/etc/fstab實(shí)現(xiàn)開機(jī)自動(dòng)掛載,需先測試掛載確保無誤。操作前務(wù)必確認(rèn)數(shù)據(jù)安全,避免硬件連接問題。

Linux中的系統(tǒng)日誌在哪裡? Linux中的系統(tǒng)日誌在哪裡? Jun 24, 2025 am 12:15 AM

Linux系統(tǒng)中的日誌通常存儲(chǔ)在/var/log目錄中,該目錄包含多種關(guān)鍵日誌文件,如syslog或messages(記錄系統(tǒng)日誌)、auth.log(記錄認(rèn)證事件)、kern.log(記錄內(nèi)核消息)、dpkg.log或yum.log(記錄軟件包操作)、boot.log(記錄啟動(dòng)信息);可通過cat、tail-f或journalctl等命令查看日誌內(nèi)容;應(yīng)用日誌也常位於/var/log下的子目錄,如Apache的apache2或httpd目錄、MySQL的日誌文件等;同時(shí)需注意日誌權(quán)限通常需要s

修復(fù)無法在Windows Google Chrome上傳文件 修復(fù)無法在Windows Google Chrome上傳文件 Jul 08, 2025 pm 02:33 PM

在GoogleChrome中上傳文件時(shí)遇到問題?這可能很煩人,對吧?無論您是將文檔附加到電子郵件、在社交媒體上共享圖像,還是提交工作或?qū)W校的重要文件,流暢的文件上傳過程都是至關(guān)重要的。因此,如果您的文件上傳在WindowsPC上的Chrome中持續(xù)失敗,可能會(huì)令人沮喪。如果您還沒有準(zhǔn)備好放棄您最喜歡的瀏覽器,這裡有一些提示修復(fù)無法在WindowsGoogleChrome上傳文件1.從通用修復(fù)開始在我們了解任何高級(jí)故障排除技巧之前,最好先嘗試下面提到的一些基本解決方案。排除互聯(lián)網(wǎng)連接問題:互聯(lián)網(wǎng)連

什麼是sudo命令,我什麼時(shí)候應(yīng)該使用它? 什麼是sudo命令,我什麼時(shí)候應(yīng)該使用它? Jul 02, 2025 am 12:20 AM

sudo代表“substituteuserdo”或“superuserdo”,允許用戶以其他用戶(通常是root)的權(quán)限運(yùn)行命令。其核心用途包括:1.執(zhí)行系統(tǒng)級(jí)操作如安裝軟件或編輯系統(tǒng)文件;2.訪問受保護(hù)目錄或日誌;3.管理服務(wù)如重啟nginx;4.修改全局設(shè)置如/etc/hosts。使用時(shí)系統(tǒng)會(huì)檢查/etc/sudoers配置並驗(yàn)證用戶密碼,提供臨時(shí)權(quán)限而非持續(xù)以root身份登錄,確保安全性。最佳實(shí)踐包括:僅必要時(shí)使用、避免盲目執(zhí)行網(wǎng)絡(luò)命令、用visudo編輯sudoers文件、連續(xù)操作可考慮

如何在Linux上管理組 如何在Linux上管理組 Jul 06, 2025 am 12:02 AM

管理Linux用戶組需掌握查看、創(chuàng)建、刪除、修改及用戶歸屬調(diào)整等操作。查看用戶組信息可用cat/etc/group或getentgroup,查看用戶所屬組用groups[用戶名]或id[用戶名];創(chuàng)建組使用groupadd,可加-g指定GID;刪除空組用groupdel;添加用戶到組用usermod-aG,修改主組用usermod-g;從組移除用戶可通過編輯/etc/group或使用vigr命令;修改組屬性用groupmod-n(改名)或groupmod-g(改GID),並記得更新相關(guān)文件權(quán)限。

See all articles