I've installed Wordpress under ArchLinux on my VPS, configured the SQL backend and edited /usr/share/webapps/wordpress/wp-config.php. Unfortunately on trying to access pages I'm getting...
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:...
Searching around this appears to happen under PHP when its attempting to use the mysql module rather than mysqli (found threads here and here).
I've enabled mysqli in /etc/php/php.ini
extension=mysqli
...and the module is loaded...
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]
Reading through /usr/share/webapps/wordpress/wp-includes/wp-db.php around the offending line (1645) it looks to me as though there are a series of if{} else{} statements starting on line 1589 which checks to see if use_mysqli is being used,this fails and as there is no mysql module in they was removed in PHP7 and mysqli should instead be used.
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- }
This fails because, looking further back through /usr/share/webapps/wordpress/wp-includes/wp-db.php I can see $is_mysql is set to null on line 564 and $use_mysqli is set to false which explains why the test to see if use_mysqli is being used fails and instead connect_mysql() is being attempted...
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;
Given mysql has been removed since PHP7 and is not a listed possible module in /etc/php/php.ini I'm surprised $use_mysqli = false on a fresh install. I've tried setting it to true and after restarting php-fpm.service now get another error and enter the if ( $this->$use_mysqli){...} section only to fail on the first call to $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:
I'm not adverse to modifying configuration but the impression I had from Arch Wiki : Wordpress article is that this level of tinkering is not required. Can anyone advise on where I might have gone wrong.
EDIT
mysqli section from 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 : Its suggested that php-fpm
wasn't loading the mysqli
module, I've now checked and it appears to...
$ 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]
You are right, meddling like this should not be necessary. A quick grep shows that
$use_mysqli
is set in line 621 inwp-db.php
:So, for some reason WordPress can't find the function
mysqli_connect()
.Please make sure that the
mysqli
module is loaded for the webserver. The commandphp -m
only confirms that it is loaded for the command line interface, which may use a different configuration file. You can create a php file withphpinfo()
to check this. Don't forget to restart your Apache after enabling the mysqli module in PHP.If it is loaded and you still encounter the error, you can set the variable
WP_USE_EXT_MYSQL
tofalse
to force WordPress to use mysqli. You only need to add this to your wp_config.php:I've resolved this and the underlying problem was the
password
for the backend mariadb/mysql.Wasn't at all clear from the logs which reported...
However, I started stripping things back and after checking
mariadb.service
was running tried connecting to it as thewp-user
with the existing password from the command line and this failed. Changing the password allowed me to connect at the command line and complete the configuration of/usr/share/webapps/wordpress/wp-config.php
. \o/