問題描述
WordPress 上的一切都是為生產伺服器準備的,很少提及開發的資訊。
我想在本地設定一個 WordPress 部落格,使其在播放之前的良好和準備。在設定本地 WordPress 開發環境時,是否有任何具體的指導。
在本地建立 wordpress 部落格最簡單的方法是什麼,我可以在某些時候轉移到即時伺服器?
問題編輯為 WordPress 答案指南。
最佳解決方案
WordPress 本地開發環境:
本地開發環境可能適用於開發任何型別的應用程式,但有一些特定的 WordPress 陷阱可能會阻礙您從本地轉換到開發。
本地開發環境的目標是儘可能模仿生產環境,並允許無縫過渡。
匹配 URL 如果您打算使用相同的資料庫進行生產,將本地開發人員設定為與生產相同的域更容易。
-
開啟您的主機檔案:sudo nano /etc /hosts 並新增
127.0.0.1 your-domain.com
將 root 移動到站點 dir 在/dir /applications /Mamp /httdocs 之外的站點管理您的 WordPress 安裝要容易得多。
編輯您的 vhost 檔案,將每個站點都對映到目錄位置:
/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/Users/your_name/Sites/domain"
ServerName domain.com #This should be the same as what was added to your host file
</VirtualHost>
編輯 your.conf 檔案對映您的 vhosts 並啟用內建 Apache Web 伺服器的 Mac 。
/etc/apache2/extra/httpd.conf
#Uncomment line 112:
LoadModule php5_module libexec/apache2/libphp5.so
#Change your directives line 247
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from ALL
</Directory>
#Map your vhost file line: 621
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
/etc/apache2/users/yourname.conf
<Directory "/Users/yourname/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from All
</Directory>
啟動 Web 伺服器轉到系統首選項 – > 共享和檢查網路共享框。
wp-config.php 將資料庫主機位置對映到 Mamp:
localhost:/Applications/MAMP/tmp/mysql/mysql.sock
定義區域性常數,以便您可以在開發和生產之間使用相同的 wp-config:
if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
include( dirname( __FILE__ ) . '/local-config.php' );
define( 'WP_LOCAL_DEV', true );
} else {
define( 'DB_NAME', 'production_db' );
define( 'DB_USER', 'production_user' );
define( 'DB_PASSWORD', 'production_password' );
define( 'DB_HOST', 'production_db_host' );
}
現在在 local-config.php 中設定本地資料庫常量
額外提示:使用 Mark Jaquith 的 Disable Plugins when doing dev 外掛來定義外掛在本地停用。將其放在 wp-content /mu-plugins 中,並定義要在檔案底部停用的外掛:
new CWS_Disable_Plugins_When_Local_Dev( array( 'vaultpress.php' ) );
安裝 WordPress 使用 SVN 管理安裝更為容易 (您必須首先為 Mac 安裝 Subversion binaries) 。
當您準備生產時,您可以使用 phpmyadmin 匯出資料庫,並將檔案移動到伺服器。
mkdir /sites/domain-name
cd /sites/domain-name
svn co http://core.svn.wordpress.org/tags/3.2.1 .
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。