“编辑wp-config.php”的版本间的差异

来自WordPress中文文档
跳转至: 导航搜索
(1个修订)
(moved 编辑wp-config.php to 编辑 wp-config.php: Standardize writing style -- adding a space between Chinese and English.)
第1行: 第1行:
{{Languages|
+
#REDIRECT [[编辑 wp-config.php]]
{{en|Editing wp-config.php}}
 
{{zh-cn|编辑wp-config.php}}
 
{{de|Wp-config.php}}
 
{{ja|wp-config.php の編集}}
 
{{ru|Редактирование wp-config.php}}
 
}}
 
 
 
{{WarningMsg
 
|在你编辑这个页面之前
 
|请不要把您自己服务器的配置信息复制到这个Codex页面上,因为那会使所有人都能轻易访问您的服务器。谢谢!}}
 
 
 
__TOC__
 
作为Wordpress安装的一部分,你必须修改ttwp-config.php/tt文件,配置Wordpress访问MySQL数据库所必需的信息。
 
 
 
ttwp-config.php/tt一开始是不存在于WordPress中的,你需要自己创建。你可以参照ttwp-config-sample.php/tt文件样本来进行创建。进阶设定及示例会在后文中说明。
 
 
 
要对ttwp-config.php/tt文件做修改,你需要如下信息:
 
 
 
; '''数据库名称''' : WordPress所使用的数据库名称
 
; '''数据库用户名''' : 访问数据库所需的用户名
 
; '''数据库密码''' : 用户名对应的用以访问数据库的密码
 
; '''数据库主机''' : 数据库服务器的主机名称
 
 
 
如果你的主机供应商已为你安装好了WordPress的话,可以找他们要相关信息。如果你是自己弄的[[Glossary#Web server|服务器]](web server)或主机帐号的话,就需要[[Installing_WordPress#Step_2:_Create_the_Database_and_a_User|创建数据库及用户]]来获取以上这些信息了。
 
 
 
== 配置数据库设定 ==
 
 
 
'''重要''':千万''不要''使用如Microsoft Word类型的文字处理程序来编辑WordPress文件!
 
 
 
在WordPress目录的基础目录下找到{{Trac|wp-config-sample.php}}文件,并使用[[Glossary#Text_editor|文本编辑器]](text editor)打开。
 
 
 
{{Note|从2.6版开始,[[#Moving wp-content|wp-config.php可被直接移至]]WordPress应用程序目录的上级目录中。}}
 
 
 
=== tt默认的wp-config-sample.php/tt ===
 
这是默认的{{Trac|wp-config-sample.php}}文件,你需要将该文件中的默认数值替换为你的数据库设定。
 
 
 
{{Template:SampleConnection}}
 
 
 
{{Note|Text inside tt/* *//tt are ''[http://www.php.net/manual/en/language.basic-syntax.comments.php comments]'', for information purposes only.}}
 
{{Note|编辑这个页面时,请不要使用您自己服务器的配置。}}
 
 
 
 
 
==== 设定数据库名称 ====
 
 
 
将ttputyourdbnamehere/tt替换为你的数据库名称,比如:''MyDatabaseName''
 
 
 
{{Template:SampleDBName}}
 
 
 
==== 设定数据库用户名 ====
 
 
 
将ttusernamehere/tt替换为你的用户名,比如:''MyUserName''。
 
 
 
{{Template:SampleDBUser}}
 
 
 
==== 设定数据库密码 ====
 
 
 
将ttyourpasswordhere/tt替换为你的密码,比如:''MyPassWord''。
 
 
 
{{Template:SampleDBPassword}}
 
 
 
==== 设定数据库主机 ====
 
 
 
将ttlocalhost/tt替换为你的数据库主机,比如:''MyDatabaseHost''。
 
 
 
{{Template:SampleDBHost}}
 
 
 
{{Note|基本上说来你是无需修改此项的。如果你'''不'''确定的话,可以使用默认值tt'localhost'/tt进行安装,然后看看是否可行。如果没有成功,请联系你的网络主机供应商。}}
 
 
 
=== 可能的DB_HOST值 ===
 
 
 
不同的主机供应商会对mysql使用不同的网络设定。如果在下表左侧能找到你的主机供应商的话,那么右侧就是DB_HOST较准确的值了。你可以联系相关技术支持和/或查找你所使用的主机供应商的在线资料进行进一步确认。
 
 
 
{| style=width:95%; margin:0 auto; border=0 cellpadding=2
 
|- align=center bgcolor=#999 style=color:#fff border=1
 
! '''Hosting Company''' !! '''DB_HOST Value Guess'''
 
|-
 
|'''1and1''' ||  '''ttdb12345678/tt'''
 
|-
 
|'''AN Hosting''' || '''ttlocalhost/tt'''
 
|-
 
|'''A Small Orange''' || '''ttlocalhost/tt'''
 
|-
 
|'''BlueHost''' || '''ttlocalhost/tt'''
 
|-
 
|'''DreamHost''' || '''ttmysql.example.com/tt'''
 
|-
 
|'''GoDaddy''' || '''tth41mysql52.secureserver.net/tt'''
 
|-
 
|'''HostGator''' || '''ttlocalhost/tt'''
 
|-
 
|'''HostICan''' || '''ttlocalhost/tt'''
 
|-
 
|'''ICDSoft''' || '''ttlocalhost:/tmp/mysql5.sock/tt'''
 
|-
 
|'''LaughingSquid''' || '''ttlocalhost/tt'''
 
|-
 
|'''MediaTemple GridServer''' || '''ttinternal-db.s44441.gridserver.com/tt'''
 
|-
 
|'''one.com''' || '''ttlocalhost/tt'''
 
|-
 
|'''pair Networks''' || '''ttdbnnnx.pair.com/tt'''
 
|-
 
|'''Yahoo''' || '''ttmysql/tt'''
 
|-
 
|'''Hosts with cPanel''' || '''ttlocalhost/tt'''
 
|-
 
|'''Hosts with Plesk''' || '''ttlocalhost/tt'''
 
|-
 
|'''Hosts with DirectAdmin''' || '''ttlocalhost/tt'''
 
|-
 
|'''Tophost.it''' || '''ttsql.your-domain-name.it/tt'''
 
|}
 
br
 
br
 
 
 
=== MySQL备用端口 ===
 
 
 
如果你的主机为数据库使用备用端口的话,就需要修改ttwp-config.php/tt中的'''DB_HOST'''值以反映出主机备用端口设置。
 
 
 
对localhost
 
  define('DB_HOST', 'localhost:'''3307'''');
 
 
 
其他
 
define('DB_HOST', 'mysql.example.com:'''4454'''');
 
 
 
=== 数据库字符集 ===
 
 
 
WordPress [[Version 2.2|2.2版]]中,'''DB_CHARSET'''可用,以允许数据库[[Glossary#Character Set|字符集]]的标识(如TIS620 Thai,tis620)在定义MySQL数据库表时被使用。
 
 
 
在你尚未完全理解修改'''utf8'''([[Wikipedia:Unicode|Unicode]] [[Wikipedia:UTF-8|UTF-8]]) 默认值所带来的后果之前,不应做任何修改。请注意UTF-8支持着诸多欧洲语言,因此将[[#Database collation|DB_COLLATE]]为'''utf8'''的设置放着别动,而应为你的语言使用合适的DB_COLLATE值。
 
 
 
此例表明WordPress默认值的utf8:
 
 
 
define('DB_CHARSET', 'utf8');
 
 
 
{{WarningMsg|对于执行新安装的用户|一般说来不应修改DB_CHARSET的默认值。如果你的博客需要使用不同的字符集,请阅读[http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html 字符集和排序MySQL支持]以明确有效的DB_CHARSET值。}}
 
 
 
{{WarningMsg| 对于执行升级的用户(尤其是对那些2.2之前的博客系统)|如果wp-config.php文件中不存在DB_CHARSET和DB_COLLATE的话,'''请勿'''向ttwp-config.php/tt添加定义,除非你已阅读并理解数据库[[Converting Database Character Sets|字符集转换]]。对于已存在的博客,向ttwp-config.php/tt文件添加DB_CHARSET和DB_COLLATE会出不少问题。}}
 
 
 
=== 数据库排序 ===
 
 
 
WordPress[[Version 2.2|2.2版]]中,'''DB_COLLATE'''可用,以允许数据库[[Glossary#Collation|排序]](即字符集的排序次序)。大多数情况下,此值应留空(null),这样数据库排序才能被MySQL字段分配,这是基于DB_CHARSET所指定的数据库字符集之上的。将'''DB_COLLATE'''设为[http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html UTF-8字符集]中定义的某个UTF-8值。
 
 
 
WordPress的默认DB_COLLATE值:
 
 
 
define('DB_COLLATE', '');
 
 
 
UTF-8 Unicode一般排序
 
 
 
define('DB_COLLATE', 'utf8_general_ci');
 
 
 
UTF-8 Unicode 土耳其语排序
 
 
 
define('DB_COLLATE', 'utf8_turkish_ci');
 
 
 
{{WarningMsg|对于执行新安装的用户|一般不应修改DB_COLLATE的默认值。将其留空(null)能保证在数据库表格被创建时,排序能自动为MySQL所分派。}}
 
 
 
{{WarningMsg|对于执行升级的用户(尤其是对那些2.2之前的博客系统)|如果wp-config.php文件中不存在DB_CHARSET和DB_COLLATE的话,请勿向wp-config.php添加定义,除非你已阅读并理解数据库字符集转换。而你还可能需要升级WordPress。}}
 
!--
 
*'''Further warning for those upgrading to WP 2.3.x''': You cannot upgrade from a pre-2.3 version of WordPress with these lines in your wp-config.php file. The upgrade to 2.3.x moves data from the wp_categories table to the wp_terms table, and deletes the former. This cannot happen if the DB_COLLATE and DB_CHARSET lines are included. More info [http://wordpress.org/support/topic/150460 in the forums] and [http://www.webbleyou.com/2008-02-25-wordpress-23x-upgrade-error-tables-wp_terms-and-wp_term_taxonomy-dont-exist/ this blog post].
 
--
 
 
 
=== 安全密钥 ===
 
 
 
从[[Version 2.6|2.6版]]开始,存在3种安全密钥,'''AUTH_KEY''','''SECURE_AUTH_KEY'''和'''LOGGED_IN_KEY''',它们能够保证用户cookies中的信息得到更好的加密。在[[Version 2.7|2.7版]]中引入了第四种密钥,'''NONCE_KEY'''。
 
 
 
你无需记住这些密钥,只要保证它们越长越复杂越好,你可以使用[https://api.wordpress.org/secret-key/1.1/ 在线密钥生成器]。
 
 
 
示例:
 
 
 
define('AUTH_KEY', ':dr+%/5V4sAUG-gg%aS*v;xGhd%{YKC^Z7KKGh jk[.Nf$y7iGKdJ3c*[Kr5Bg');
 
define('SECURE_AUTH_KEY', 'TufWOuA _.t#+hA?^|3RfGTm@*+S=8\\'+\}]m#+}V)p:Qi?jXLq,h\\`39m_(');
 
define('LOGGED_IN_KEY', 'S~AACm4h1;T^\qW3_8Zv!Ji=y|)~5i63JI |Al[(YS2V^$T])=8Xh2a:b:}U_E');
 
define('NONCE_KEY', 'k1+EOc-w?hG8j846L9v\6C89NH?ui{*3\\(t09mumL/fFP_!K$JCEkLuy ={x{0');
 
 
 
'''密钥'''是一种加入到密码中的''干扰信息'',用于提高您站点以及帐号的安全性。
 
 
 
简单来说,密钥就是一种用于增加密码强度、抗暴力破解的安全机制。例如 password 或 test 这类的密码很容易会被猜解出来。但像 88a7da62429ba6ad3cb3c76a09641fc 这种没有规律的密码,则需要很多年的时间才能猜测出来。
 
 
 
更多关于密钥和密码安全的技术细节,可参见以下资源列表:
 
 
 
* [http://boren.nu/archives/2008/07/14/ssl-and-cookies-in-wordpress-26/ Ryan Boren - SSL and Cookies in WordPress 2.6]
 
* [http://wordpress.org/support/topic/170987 WordPress Support Forum - HOWTO: Set up secret keys in WordPress 2.6+]
 
* [http://en.wikipedia.org/wiki/Password_cracking Wikipedia's explanation of Password Cracking]
 
* [http://www.blogherald.com/2007/05/08/protect-your-blog-with-a-solid-password/ Lorelle VanFossen - Protect Your Blog With a Solid Password]
 
* [http://security.yahoo.com/article.html?aid=2006102509 Yahoo's Security Password Tips]
 
* [http://uk.security.yahoo.com/protect-your-privacy/choose-password.html Yahoo Security - How to Choose a Password]
 
* [http://lifehacker.com/software/passwords/get-high-security-passwords-from-perfect-passwords-138100.php LifeHacker - Get high security passwords from Perfect Passwords]
 
 
 
== 高级选项 ==
 
以下的部分可能包含高级的或者不成熟的信息,在正式使用前,请先确保你已经执行[[WordPress Backups|常规备份]]并且了解如何恢复系统。
 
 
 
 
 
=== 数据库表格前缀 ===
 
 
 
'''tt$table_prefix/tt'''是被放在你的数据库表格前面部分的设定值, 数据库前缀的设置对提高你的站点安全以及在同一数据库中安装多个WordPress站点都非常有用,通过改变默认值“wp_” 为随机独一的值,可减轻站点受攻击的可能性,总体上提高你的网站安全性。
 
 
 
// You can have multiple installations in one database if you give each a unique prefix
 
$table_prefix  = 'r235_';  // Only numbers, letters, and underscores please!
 
 
 
在同一个数据库上安装第二个博客的时候,可以通过指定不同的前缀来安装。
 
$table_prefix  = 'y77_';  // Only numbers, letters, and underscores please!
 
 
 
=== WordPress地址(URL) ===
 
'''WP_SITEURL''', defined since WordPress [[Version 2.2|Version 2.2]], allows the WordPress address (URL) to be defined.  The valued defined is the address where your WordPress core files reside.  It should include the nowikihttp:///nowiki part too.  Do not put a slash '''/''' at the end.  Setting this value in ttwp-config.php/tt overrides the [[Database_Description#Table:_wp_options|wp_options table]] value for '''siteurl''' and disables the WordPress address (URL) field in the [[Administration_Panels|Administration]]  [[Administration_Panels#General|Settings]]  [[Settings_General_SubPanel|General]] panel.
 
 
 
{{Note|It won't change the Database value though, and the url will revert to the old database value if this line is removed from wp-config. [[Changing The Site URL#Relocate method|Use the '''RELOCATE''' constant]] to change the siteurl value in the database.}}
 
 
 
If WordPress is installed into a directory called wordpress for the [http://en.wikipedia.org/wiki/Domain_name_system domain] nowikiexample.com/nowiki, define WP_SITEURL like this:
 
 
 
define('WP_SITEURL', 'http://example.com/wordpress');
 
 
 
Dynamically set WP_SITEURL based on $_SERVER['HTTP_HOST']
 
 
 
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpressp');
 
 
 
{{Note|A safer alternative for some installations would be to use the server-generated SERVER_NAME instead of the php/user-generated HTTP_HOST which is created dynamically by php based on the value of the HTTP HOST Header in the request, thus possibly allowing for file inclusion vulnerabilities.  SERVER_NAME is set by the server configuration and is static.}}
 
 
 
Dynamically set WP_SITEURL based on $_SERVER['SERVER_NAME']
 
 
 
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/path/to/wordpressp');
 
 
 
===博客地址(URL)===
 
'''WP_HOME''' is another ttwp-config.php/tt option added in WordPress [[Version 2.2|Version 2.2]]. Similar to WP_SITEURL, WP_HOME ''overrides the [[Database_Description#Table:_wp_options|wp_options table]] value for ''home'' but does not change it permanently.'' '''home''' is the address you want people to type in their browser to reach your WordPress blog. It should include the nowikihttp:///nowiki part and should not have a slash '''/''' at the end.
 
 
 
define('WP_HOME', 'http://example.com/wordpress');
 
 
 
If you are using the technique described in [[Giving_WordPress_Its_Own_Directory|Giving WordPress Its Own Directory]] then follow the example below.  Remember, you will also be placing an ttindex.php/tt in your web-root directory if you use a setting like this.
 
 
 
define('WP_HOME', 'http://example.com');
 
 
 
Dynamically set WP_HOME based on $_SERVER['HTTP_HOST']
 
 
 
define('WP_HOME',    'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpress');
 
 
 
=== 迁移目录wp-content ===
 
Since [[Version 2.6]], you can move the ttwp-content/tt directory, which holds your themes, plugins, and uploads, outside of the WordPress application directory.
 
 
 
Set varWP_CONTENT_DIR/var to the full '''local path''' of this directory (no trailing slash), e.g.
 
 
 
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );
 
 
 
Set varWP_CONTENT_URL/var to the full '''URI''' of this directory (no trailing slash), e.g.
 
 
 
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
 
 
 
''Optional''br/
 
Set varWP_PLUGIN_DIR/var to the full '''local path''' of this directory (no trailing slash), e.g.
 
 
 
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );
 
 
 
Set varWP_PLUGIN_URL/var to the full '''URI''' of this directory (no trailing slash), e.g.
 
 
 
define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');
 
 
 
If you have compability issues with plugins
 
Set varPLUGINDIR/var to the full '''local path''' of this directory (no trailing slash), e.g.
 
 
 
define( 'PLUGINDIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );
 
 
 
===Modify AutoSave Interval===
 
When editing a post, WordPress uses Ajax to auto-save revisions to the post as you edit.  You may want to increase this setting for longer delays in between auto-saves, or decrease the setting to make sure you never lose changes.  The default is 60 seconds.
 
 
 
define('AUTOSAVE_INTERVAL', 160 );  // seconds
 
 
 
 
 
===Post Revisions===
 
WordPress, by default, will save copies of each edit made to a post or page, allowing the possibility of reverting to a previous version of that post or page.  The saving of revisions can be disabled, or a maximum number of revisions per post or page can be specified.
 
 
 
 
 
====Disable Post Revisions====
 
If you do '''not''' set this value, WordPress defaults ttWP_POST_REVISIONS/tt to ''true'' (enable post revisions). If you want to disable the awesome revisions feature, use this setting:
 
 
 
define('WP_POST_REVISIONS', false );
 
 
 
 
 
====Specify the Number of Post Revisions====
 
If you want to specify a maximum number of revisions, change ''false'' to an integer/number (''e.g.'', tt3/tt or tt5/tt).
 
 
 
define('WP_POST_REVISIONS', 3);
 
 
 
 
 
===Set Cookie Domain===
 
The domain set in the cookies for WordPress can be specified for those with unusual domain setups.  One reason is if [http://www.askapache.com/htaccess/apache-speed-subdomains.html subdomains are used to serve static content]. To prevent WordPress cookies from being sent with each request to static content on your subdomain you can set the cookie domain to your non-static domain only.
 
 
 
define('COOKIE_DOMAIN', 'www.askapache.com');
 
 
 
 
 
=== Debug ===
 
The ttWP_DEBUG/tt option, added in WordPress [[Version 2.3.1|Version 2.3.1]], controls the display of some errors and warnings. If this setting is absent from ttwp-config.php/tt, then the value is assumed to be varfalse/var.
 
 
 
{{Note|The vartrue/var and varfalse/var values in the example are not set in apostrophes (') because they are boolean values.}}
 
 
 
define('WP_DEBUG', true);
 
define('WP_DEBUG', false);
 
 
 
Additionally, if you are planning on modifying some of WordPress' built-in JavaScript, you should enable the following option:
 
 
 
define('SCRIPT_DEBUG', true);
 
 
 
This will allow you to edit the emscriptname/em.dev.js files in the wp-includes/js and wp-admin/js directories.
 
 
 
[http://trac.wordpress.org/ticket/5473 In Wordpress versions since 2.3.2, database errors are printed only if WP_DEBUG is set to vartrue/var]. In earlier versions, database errors were always printed. (Database errors are handled by the wpdb class and are not affected by [http://www.php.net/errorfunc PHP's error settings].)
 
 
 
In WordPress version 2.5, setting WP_DEBUG to vartrue/var also raises the [http://www.php.net/error-reporting error reporting level] to E_ALL and activates warnings when deprecated functions or files are used; otherwise, WordPress sets the error reporting level to ttE_ALL ^ E_NOTICE ^ E_USER_NOTICE/tt.
 
 
 
=== Disable Javascript Concatenation ===
 
 
 
To result in a faster administration area, all Javascript files are [http://en.wikipedia.org/wiki/Concatenation concatenated] into one URL. If Javascript is failing to work in your administration area, you can try disabling this feature:
 
 
 
define('CONCATENATE_SCRIPTS', false);
 
 
 
=== Configure Error Log ===
 
Because ttwp-config.php/tt is loaded for every page view not loaded from a cache file, it is an excellent location to set php ini settings that control your php installation.  This is useful if you don't have access to a php.ini file, or if you just want to change some settings on the fly.
 
 
 
Here is an example that turns php error_logging on and logs them to a specific file.  If ttWP_DEBUG/tt is defined to true, the errors will also be saved to this file.  Just place this above any ''require_once'' or ''include'' commands.
 
 
 
@ini_set('log_errors','On');
 
@ini_set('display_errors','Off');
 
@ini_set('error_log','/home/example.com/logs/php_error.log');
 
/* That's all, stop editing! Happy blogging. */
 
 
 
 
 
===Increasing memory allocated to PHP===
 
Also released with [[Version 2.5]], the '''WP_MEMORY_LIMIT''' option allows you to specify the maximum amount of memory that can be consumed by PHP.  This setting may be necessary in the event you receive a message such as Allowed memory size of xxxxxx bytes exhausted. 
 
 
 
This setting increases PHP Memory only for WordPress, not other applications.  By default, WordPress will attempt to increase memory allocated to PHP to 32MB (code is at beginning of ''wp-settings.php''), so the setting in ''wp-config.php'' should reflect something higher than 32MB.
 
 
 
Please note, this setting may not work if your host does not allow for increasing the PHP memory limit--in that event, contact your host to increase the PHP memory limit. Also, note that many hosts set the PHP limit at 8MB.   
 
 
 
Increase PHP Memory to 64MB
 
 
 
define('WP_MEMORY_LIMIT', '64M');
 
 
 
Increase PHP Memory to 96MB
 
 
 
define('WP_MEMORY_LIMIT', '96M');
 
 
 
 
 
===Cache===
 
The '''WP_CACHE''' setting, if true, includes the ttwp-content/advanced-cache.php/tt script, when executing ttwp-settings.php/tt.
 
 
 
define('WP_CACHE', true);
 
 
 
 
 
=== Custom User and Usermeta Tables ===
 
'''CUSTOM_USER_TABLE''' and '''CUSTOM_USER_META_TABLE''' are used to designated that the user and usermeta tables normally utilized by WordPress are not used, instead these values/tables are used to store your user information.
 
 
 
define('CUSTOM_USER_TABLE', $table_prefix.'my_users');
 
define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');
 
 
 
 
 
=== Language and Language Directory ===
 
'''WPLANG''' defines the name of the language translation (.mo) file.  '''LANGDIR''' defines what directory the WPLANG .mo file resides.  If LANGDIR is not defined WordPress looks first to wp-content/languages and then wp-includes/languages for the .mo defined by WPLANG file.
 
 
 
define('WPLANG', 'de_DE');
 
define('LANGDIR', 'mylanguagedirectory');
 
 
 
 
 
=== Save queries for analysis ===
 
The '''SAVEQUERIES''' definition saves the database queries to a array and that array can be displayed to help analyze those queries.  The information saves each query, what function called it, and how long that query took to execute. 
 
 
 
{{Note|This will have a performance impact on your site, so make sure to turn this off when you aren't debugging.}}
 
 
 
First, put this in wp-config.php:
 
 
define('SAVEQUERIES', true);
 
 
 
Then in the footer of your theme put this:
 
pre
 
?php
 
if (current_user_can('administrator')){
 
    global $wpdb;
 
    echo lt;pregt;;
 
    print_r($wpdb-queries);
 
    echo lt;/pregt;;
 
}
 
?
 
/pre
 
 
 
=== Override of default file permissions ===
 
The '''FS_CHMOD_DIR''' and '''FS_CHMOD_FILE''' define statements allow override of default file permissions.  These two variables were developed in response to the problem of the core update function failing with hosts (e.g.  some Italian hosts) running under suexec.  If a host uses restrictive file permissions (e.g. 400) for all user files, and refuses to access files which have group or world permissions set, these definitions could solve the problem.  Note that the ''''0755'''' is an octal value and is not delineated with single quotes (').  See Also: [[Changing File Permissions]]
 
 
 
define('FS_CHMOD_DIR', (0755  ~ umask()));
 
define('FS_CHMOD_FILE', (0644  ~ umask()));
 
 
 
===FTP/SSH Constants===
 
To enable SSH2 as an upgrade option you will need to install the pecl SSH2 extension.  To install this library you will need to issue a command similar to the following or talk to your web hosting provider to get this installed:
 
 
 
pre
 
pecl install ssh2
 
/pre
 
 
 
After installing the pecl ssh2 extension you will need to modify your php configuration to automatically load this extension.
 
 
 
pecl is provided by the pear package in most linux distributions.  To install pecl in Redhat/Fedora/CentOS:
 
 
 
pre
 
yum -y install php-pear
 
/pre
 
 
 
To install pecl in Debian/Ubuntu:
 
 
 
pre
 
apt-get install php-pear
 
/pre
 
 
 
These methods for the WordPress core, plugin, and theme upgrades try to determine the WordPress path, as reported by PHP, but symlink trickery can sometimes 'muck this up' so if you know the paths to the various folders on the server, as seen via your FTP user, you can manually define them in the wp-config.php file. 
 
 
 
The following are valid constants for FTP/SSH updates:
 
 
 
*'''FS_METHOD''' forces the filesystem method. It should only be direct, ssh, ftpext, or ftpsockets.
 
*'''FTP_BASE''' is the full path to the base folder of the WordPress installation.
 
*'''FTP_CONTENT_DIR''' is the full path to the wp-content folder of the WordPress installation.
 
*'''FTP_PLUGIN_DIR''' is the full path to the plugins folder of the WordPress installation.
 
*'''FTP_PUBKEY''' is the full path to your SSH public key.
 
*'''FTP_PRIKEY''' is the full path to your SSH private key.
 
*'''FTP_USER''' is either user FTP or SSH username.  Most likely these are the same, but use the appropriate one for the type of update you wish to do.
 
*'''FTP_PASS''' is the password for the username entered for '''FTP_USER'''.  If you are using SSH public key authentication this can be omitted.
 
*'''FTP_HOST''' is the hostname:port combination for your SSH/FTP server.  The standard FTP port is 21 and the standard SSH port is 22.
 
*'''FTP_SSL''' TRUE for SLL-connection.
 
 
 
pre
 
define('FS_METHOD', 'ftpext');
 
define('FTP_BASE', '/path/to/wordpress/');
 
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
 
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
 
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
 
define('FTP_PRIKEY', '/home/username/.ssh/id_rsa');
 
define('FTP_USER', 'username');
 
define('FTP_PASS', 'password');
 
define('FTP_HOST', 'ftp.example.org:21');
 
define('FTP_SSL', false);
 
/pre
 
 
 
It is recommended to use a private key that is not pass phrase protected.  There have been numerous reports that pass phrase protected private keys do not work properly.  If you decide to try a pass phrase protected private key you will need to enter the pass phrase for the private key as FTP_PASS.
 
 
 
If you're still not clear on how to use SSH for upgrading or installing WordPress/plugins, [http://www.firesidemedia.net/dev/wordpress-install-upgrade-ssh/ read through this tutorial].
 
 
 
===Alternative Cron===
 
Use this, for example, if scheduled posts are not getting published.  According to [http://wordpress.org/support/topic/296236?replies=13#post-1175405 Otto's forum explanation], this alternate method uses a redirection approach, which makes the users browser get a redirect when the cron needs to run, so that they come back to the site immediately while cron continues to run in the connection they just dropped. This method is a bit iffy sometimes, which is why it's not the default.
 
 
 
define('ALTERNATE_WP_CRON', true);
 
 
 
 
 
===Additional Defined Constants===
 
Here are additional constants that can be defined, but probably shouldn't be.  The Cookie definitions are particularly useful if you have an unusual domain setup.
 
 
 
pre
 
define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
 
define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
 
define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
 
define('PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL)  );
 
define('TEMPLATEPATH', get_template_directory());
 
define('STYLESHEETPATH', get_stylesheet_directory());
 
define('DISABLE_WP_CRON', true);
 
/pre
 
 
 
=== Empty Trash ===
 
Added with [[Version 2.9]], this constant controls the number of days before WordPress permanently deletes posts, pages, attachments, and comments, from the trash bin.  The default is 30 days:
 
 
 
define('EMPTY_TRASH_DAYS', 30 );  // 30 days
 
 
 
To disable trash set the number of days to zero.  Note that WordPress will not ask for confirmation when someone clicks on Delete Permanently.
 
 
 
define('EMPTY_TRASH_DAYS', 0 );  // zero days
 
 
 
=== Automatic Database Optimizing ===
 
Added with [[Version 2.9]], there is automatic database optimization support, which you can enable by adding the following define to your wp-config.php file '''only when the feature is required'''
 
 
 
  define('WP_ALLOW_REPAIR', true);
 
 
 
The script can be found at tt{$your_site}/wp-admin/maint/repair.php/tt
 
 
 
'''Please Note:''' That this define '''enables''' the functionality, '''The user does not need to be logged in to access this functionality when this define is set.''' This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt.
 
 
 
=== View All Defined Constants ===
 
Php has a function that returns an array of all the currently defined constants with their values. 
 
 
 
  print_r(@get_defined_constants());
 
 
 
== Double Check Before Saving ==
 
'''''Be sure to check for leading and/or trailing spaces around any of the above values you entered, and DON'T delete the single quotes!'''''
 
 
 
Before you save the file, be sure to '''double-check''' that you have not accidentally deleted any of the single quotes around the parameter values. Be sure there is nothing after the closing PHP tag in the file. The last thing in the file should be '''?''' and nothing else. No spaces.
 
 
 
To save the file, choose '''File  Save As  wp-config.php''' and save the file in the root of your WordPress install. Upload the file to your web server and you're ready to install WordPress!
 
 
 
== See Also ==
 
*[[WordPress Backups]]
 
*[[Installing Multiple Blogs|Installing Multiple Blogs requires special wp-config.php]]
 
*[[Upgrading_WordPress_Extended|Troubleshooting Installations]]
 
*[[Administration_Over_SSL|Securing your Installation]]
 
 
 
==译者信息==
 
本文档由[http://codex.wordpress.org/User:Themedaily ThemeDaily]翻译br /
 
译者博客:[http://themedaily.com Free Wordpress Themes]br /
 
E-Mail:admin@themedaily.com
 
 
 
[[Category:Getting Started]]
 
[[Category:Advanced Topics]]
 
[[Category:Installation]]
 
[[Category:UI Link]]
 
[[Category:Error handling]]
 

2011年2月26日 (六) 07:26的版本

重定向至: