我已经在我的 VPS 上的 ArchLinux 下安装了 Wordpress,配置了 SQL 后端并编辑了 /usr/share/webapps/wordpress/wp-config.php。不幸的是,在尝试访问我得到的页面时...
2019/06/14 06:44:12 [error] 20812#20812: *394 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /usr/share/webapps/wordpress/wp-includes/wp-db.php:1645
Stack trace:
#0 /usr/share/webapps/wordpress/wp-includes/wp-db.php(639): wpdb->db_connect()
#1 /usr/share/webapps/wordpress/wp-includes/load.php(427): wpdb->__construct('wp-user', 'pc&0wC<k%:o<AuI...', 'wordpress', 'localhost')
#2 /usr/share/webapps/wordpress/wp-settings.php(120): require_wp_db()
#3 /usr/share/webapps/wordpress/wp-config.php(90): require_once('/usr/share/weba...')
#4 /usr/share/webapps/wordpress/wp-load.php(37): require_once('/usr/share/weba...')
#5 /usr/share/webapps/wordpress/wp-blog-header.php(13): require_once('/usr/share/weba...')
#6 /usr/share/webapps/wordpress/index.php(17): require('/usr/share/weba...')
#7 {main}
thrown in /usr/share/webapps/wordpress/wp-includes/wp-db.php on line 1645" while reading response header from upstream, client:...
当 PHP 尝试使用 mysql 模块而不是 mysqli (在此处和此处找到线程)时,搜索似乎发生在 PHP 下。
我在 /etc/php/php.ini 中启用了 mysqli
extension=mysqli
...并且模块已加载...
php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
hash
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
阅读 /usr/share/webapps/wordpress/wp-includes/wp-db.php 围绕有问题的行(1645),在我看来,好像有一系列从第 1589 行开始的 if{} else{} 语句检查是否正在使用 use_mysqli,这失败了,因为没有 mysql 模块,它们在 PHP7 中被删除,应该使用 mysqli。
grep '\$this->use_mysqli' /usr/share/webapps/wordpress/wp-includes/wp-db.php -A100 -n | grep 1589 -A100
1589: if ( $this->use_mysqli ) {
1590- $this->dbh = mysqli_init();
1591-
1592- $host = $this->dbhost;
1593- $port = null;
1594- $socket = null;
1595- $is_ipv6 = false;
1596-
1597- if ( $host_data = $this->parse_db_host( $this->dbhost ) ) {
1598- list( $host, $port, $socket, $is_ipv6 ) = $host_data;
1599- }
1600-
1601- /*
1602- * If using the `mysqlnd` library, the IPv6 address needs to be
1603- * enclosed in square brackets, whereas it doesn't while using the
1604- * `libmysqlclient` library.
1605- * @see https://bugs.php.net/bug.php?id=67563
1606- */
1607- if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
1608- $host = "[$host]";
1609- }
1610-
1611- if ( WP_DEBUG ) {
1612- mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
1613- } else {
1614- @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
1615- }
1616-
1617- if ( $this->dbh->connect_errno ) {
1618- $this->dbh = null;
1619-
1620- /*
1621- * It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
1622- * - We haven't previously connected, and
1623- * - WP_USE_EXT_MYSQL isn't set to false, and
1624- * - ext/mysql is loaded.
1625- */
1626- $attempt_fallback = true;
1627-
1628- if ( $this->has_connected ) {
1629- $attempt_fallback = false;
1630- } elseif ( defined( 'WP_USE_EXT_MYSQL' ) && ! WP_USE_EXT_MYSQL ) {
1631- $attempt_fallback = false;
1632- } elseif ( ! function_exists( 'mysql_connect' ) ) {
1633- $attempt_fallback = false;
1634- }
1635-
1636- if ( $attempt_fallback ) {
1637: $this->use_mysqli = false;
1638- return $this->db_connect( $allow_bail );
1639- }
1640- }
1641- } else {
1642- if ( WP_DEBUG ) {
1643- $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
1644- } else {
1645- $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
1646- }
1647- }
这失败了,因为通过 /usr/share/webapps/wordpress/wp-includes/wp-db.php 我可以看到 $is_mysql 在第 564 行设置为 null 并且 $use_mysqli 设置为 false 这解释了为什么测试查看是否使用 use_mysqli 失败,而是尝试使用 connect_mysql()...
grep 'public \$is_mysql = null' /usr/share/webapps/wordpress/wp-includes/wp-db.php -A30 -n
564: public $is_mysql = null;
565-
566- /**
567- * A list of incompatible SQL modes.
568- *
569- * @since 3.9.0
570- * @var array
571- */
572- protected $incompatible_modes = array(
573- 'NO_ZERO_DATE',
574- 'ONLY_FULL_GROUP_BY',
575- 'STRICT_TRANS_TABLES',
576- 'STRICT_ALL_TABLES',
577- 'TRADITIONAL',
578- );
579-
580- /**
581- * Whether to use mysqli over mysql.
582- *
583- * @since 3.9.0
584- * @var bool
585- */
586- private $use_mysqli = false;
鉴于 mysql 自 PHP7 以来已被删除并且不是 /etc/php/php.ini 中列出的可能模块,我很惊讶 $use_mysqli = false 在全新安装时。我尝试将其设置为 true 并在重新启动 php-fpm.service 后出现另一个错误并输入 if ( $this->$use_mysqli){...} 部分,但在第一次调用 $this-> 时失败dbh = mysqli_init()...
2019/06/14 07:10:25 [error] 1439#1439: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function mysqli_init() in /usr/share/webapps/wordpress/wp-includes/wp-db.php:1591
Stack trace:
#0 /usr/share/webapps/wordpress/wp-includes/wp-db.php(640): wpdb->db_connect()
#1 /usr/share/webapps/wordpress/wp-includes/load.php(427): wpdb->__construct('wp-user', 'pc&0wC<k%:o<AuI...', 'wordpress', 'localhost')
#2 /usr/share/webapps/wordpress/wp-settings.php(120): require_wp_db()
#3 /usr/share/webapps/wordpress/wp-config.php(90): require_once('/usr/share/weba...')
#4 /usr/share/webapps/wordpress/wp-load.php(37): require_once('/usr/share/weba...')
#5 /usr/share/webapps/wordpress/wp-blog-header.php(13): require_once('/usr/share/weba...')
#6 /usr/share/webapps/wordpress/index.php(17): require('/usr/share/weba...')
#7 {main}
thrown in /usr/share/webapps/wordpress/wp-includes/wp-db.php on line 1591" while reading response header from upstream, client:
我并不反对修改配置,但我从Arch Wiki 的印象:Wordpress文章是不需要这种级别的修补。任何人都可以就我可能出错的地方提出建议。
编辑
mysqli部分来自phpinfo()
mysqli
MysqlI Support enabled
Client API library version mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $
Active Persistent Links 0
Inactive Persistent Links 0
Active Links 0
Directive Local Value Master Value
mysqli.allow_local_infile Off Off
mysqli.allow_persistent On On
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket /run/mysqld/mysqld.sock /run/mysqld/mysqld.sock
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.max_persistent Unlimited Unlimited
mysqli.reconnect Off Off
mysqli.rollback_on_cached_plink Off Off
EDIT2:它建议php-fpm
没有加载mysqli
模块,我现在检查了一下,它似乎......
$ php-fpm -m
[PHP Modules]
cgi-fcgi
Core
ctype
curl
date
dom
fileinfo
filter
hash
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
你是对的,这样的干涉应该是不必要的。快速 grep 显示
$use_mysqli
在第 621 行中设置wp-db.php
:所以,由于某种原因,WordPress 找不到该功能
mysqli_connect()
。请确保
mysqli
为网络服务器加载了该模块。该命令php -m
仅确认它是为命令行界面加载的,它可能使用不同的配置文件。您可以创建一个 php 文件phpinfo()
来检查这一点。在 PHP 中启用 mysqli 模块后不要忘记重新启动 Apache。如果加载后仍然遇到错误,可以将变量
WP_USE_EXT_MYSQL
设置false
为强制 WordPress 使用 mysqli。您只需要将其添加到您的 wp_config.php 中:我已经解决了这个问题,根本问题是
password
后端 mariadb/mysql。从报告的日志中根本不清楚......
但是,我开始剥离东西,并在检查
mariadb.service
运行后尝试wp-user
使用命令行中的现有密码连接到它,但失败了。更改密码允许我在命令行连接并完成/usr/share/webapps/wordpress/wp-config.php
. \o/