WordPress本地开发环境:
本地开发环境可以应用于开发任何类型的应用程序,但有些特定的WordPress陷阱可能会阻碍您从本地到开发的过渡。
本地开发环境的目标是尽可能地模拟生产环境,并允许无缝过渡。
Matching URL如果您计划在生产中使用相同的数据库,那么将本地dev设置为与生产相同的域会容易得多。
打开主机文件:sudo nano/etc/hosts并添加127.0.0.1 your-domain.com
Move root to sites dir在sites目录下管理WordPress安装比在/Applications/Mamp/httdocs目录下要容易得多。
编辑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>
Edit your.conf files映射vhost并启用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>
Start your web server转到系统首选项->;共享并选中web共享框。wp-config.php将数据库主机位置映射到Mamp:
localhost:/Applications/MAMP/tmp/mysql/mysql.sock
Define local constants因此您可以在开发和生产之间使用相同的wp配置: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\' );
}
现在在本地配置中设置本地db常量。phpExtra Tip: 使用Mark Jaquith的Disable Plugins when doing dev 插件,定义在本地时要禁用的插件。将其放入wp content/mu插件中,并在文件底部定义要禁用的插件:
new CWS_Disable_Plugins_When_Local_Dev( array( \'vaultpress.php\' ) );
Install WordPress使用SVN管理安装要容易得多(您必须安装Subversion binaries 对于Mac优先)。准备生产时,使用phpmyadmin导出数据库并将文件移动到服务器。
mkdir /sites/domain-name
cd /sites/domain-name
svn co http://core.svn.wordpress.org/tags/3.2.1 .