wp-cli:无法在 MAMP 上 运行 phpunit
wp-cli: unable to run phpunit on MAMP
我正在关注 plugin test setup/install instructions。我得到 wp scaffold plugin-tests my-plugin
到 运行。但是在下一步,当我尝试 运行 bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
时,出现以下错误:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (61)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
我的本地 Wordpress 站点是 运行 MAMP(正在运行)。我不确定这是否与安装脚本相关,因为我认为它正在为 运行 测试创建一个临时数据库...如果它使用内置 OSX [=64= 是否重要] 或 MAMP 的 MySQL?
这是 wp --info
的输出
$ ./vendor/wp-cli/wp-cli/bin/wp --info
PHP binary: /Applications/MAMP/bin/php/php5.6.10/bin/php
PHP version: 5.6.10
php.ini used: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
WP-CLI root dir: /Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/wp-cli/wp-cli
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.19.2
更新 2
我发现原来 MySQL 没有安装...这就是我无法连接的原因!但现在是。我 运行 安装脚本,这有效...
$ ./vendor/wp-cli/wp-cli/bin/wp db tables
wp_users
wp_usermeta
wp_posts
wp_comments
wp_links
wp_options
wp_postmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
但是当我 运行 phpunit
我得到这个:
$ phpunit
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
我的部分问题是我不清楚 wp-cli 是否应该 运行 完全基于原生 (cli) PHP/Mysql 或 MAMP 的 PHP/Mysql,或者两者的某种结合。
更新 4
我很确定最后一个问题是需要在 MAMP 中安装 phpunit,但我 运行 从 OSX...
中安装它
$which phpunit
/usr/bin/phpunit
在this gist中提到。
更新 6
原来你不能再使用 pear 安装 phpunit。所以我将它添加为 require-dev 下的作曲家依赖项,但是当我 运行 那个版本时,我得到了同样的错误!
$ ./vendor/phpunit/phpunit/phpunit
PHP Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
我什至将它添加到我的路径中以确保...
$ which phpunit
/Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/phpunit/phpunit/phpunit
更新 7
阅读 this 博客 post 底部的评论后,我发现安装脚本引用了 mysqladmin
的 OSX 版本。我不确定这是否重要,但我在路径中添加了 MAMPs 版本,并重新 运行 安装脚本。无论如何,它似乎都会在 /tmp/
中安装 Wordpress 文件。当我 运行 phpunit
时出现同样的错误
通常,如果您 ftp 或远程登录到本地主机,您将获得 conection refused
,如果您想修复错误,请将 httpd.conf
更改为 ServerName localhost
此外,如果您想进行远程登录,请尝试启用远程登录,方法是转到
System Preferences -> Sharing -> Remote Login box (check it)
.
对于MySQL问题
确保'skip-networking'在配置文件中被注释掉(在本例中/opt/local/etc/mysql55/my.conf
)或者启动mysql服务器时,它不以'–skip-networking'开头
在跳过网络模式下,mysql 实例根本不“监听 TCP/IP 连接。所有与 mysqld 的交互都必须使用命名管道或共享内存(在 Windows 上)或 Unix 套接字文件(在 Unix 上)” from MySql Docs
希望对您有所帮助。
如果您使用的是 MAMP,问题可能与您的 MySQL 服务器设置有关。确保选中 MAMP 设置中的 Allow network access
选项:
更新 1
在您的根目录中创建 phpinfo.php
文件(对于 MAMP,通常是 /Applications/MAMP/htdocs
)。粘贴以下内容:
<?php phpinfo() ?>
然后检查Loaded Configuration File
属性。在终端中使用 nano
或其他文本编辑器打开它。然后找到并将这3个属性pdo_mysql.default_socket
、mysql.default_socket
、mysqli.default_socket
更改为您的套接字文件。
引用自http://maccrazy.com/lion-upgrade-killed-my-php-site-and-how-i-fixed-it
我终于 phpunit
到 运行!!
我无法在任何地方找到此记录...
在安装过程中的某个时刻,Wordpress 核心文件安装在 /tmp/wordpress/
中。 That Wordpress 安装有自己的 wp-config.php
文件,该文件的值不正确。当我更正这些值以匹配我网站的 wp-config.php
时,phpunit
工作正常!
我不确定这是怎么发生的,但我的理论是我第一次 运行 安装脚本时使用了错误的凭据。但后来我更正了它们(我重新 运行 安装脚本几次)。但是我认为安装脚本并没有覆盖原来的文件。
+400 感谢@Nikita Zernov 的帮助!
我正在关注 plugin test setup/install instructions。我得到 wp scaffold plugin-tests my-plugin
到 运行。但是在下一步,当我尝试 运行 bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
时,出现以下错误:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (61)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
我的本地 Wordpress 站点是 运行 MAMP(正在运行)。我不确定这是否与安装脚本相关,因为我认为它正在为 运行 测试创建一个临时数据库...如果它使用内置 OSX [=64= 是否重要] 或 MAMP 的 MySQL?
这是 wp --info
$ ./vendor/wp-cli/wp-cli/bin/wp --info
PHP binary: /Applications/MAMP/bin/php/php5.6.10/bin/php
PHP version: 5.6.10
php.ini used: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
WP-CLI root dir: /Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/wp-cli/wp-cli
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.19.2
更新 2 我发现原来 MySQL 没有安装...这就是我无法连接的原因!但现在是。我 运行 安装脚本,这有效...
$ ./vendor/wp-cli/wp-cli/bin/wp db tables
wp_users
wp_usermeta
wp_posts
wp_comments
wp_links
wp_options
wp_postmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
但是当我 运行 phpunit
我得到这个:
$ phpunit
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
我的部分问题是我不清楚 wp-cli 是否应该 运行 完全基于原生 (cli) PHP/Mysql 或 MAMP 的 PHP/Mysql,或者两者的某种结合。
更新 4 我很确定最后一个问题是需要在 MAMP 中安装 phpunit,但我 运行 从 OSX...
中安装它$which phpunit
/usr/bin/phpunit
在this gist中提到。
更新 6
原来你不能再使用 pear 安装 phpunit。所以我将它添加为 require-dev 下的作曲家依赖项,但是当我 运行 那个版本时,我得到了同样的错误!
$ ./vendor/phpunit/phpunit/phpunit
PHP Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
我什至将它添加到我的路径中以确保...
$ which phpunit
/Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/phpunit/phpunit/phpunit
更新 7
阅读 this 博客 post 底部的评论后,我发现安装脚本引用了 mysqladmin
的 OSX 版本。我不确定这是否重要,但我在路径中添加了 MAMPs 版本,并重新 运行 安装脚本。无论如何,它似乎都会在 /tmp/
中安装 Wordpress 文件。当我 运行 phpunit
通常,如果您 ftp 或远程登录到本地主机,您将获得 conection refused
,如果您想修复错误,请将 httpd.conf
更改为 ServerName localhost
此外,如果您想进行远程登录,请尝试启用远程登录,方法是转到
System Preferences -> Sharing -> Remote Login box (check it)
.
对于MySQL问题
确保'skip-networking'在配置文件中被注释掉(在本例中/opt/local/etc/mysql55/my.conf
)或者启动mysql服务器时,它不以'–skip-networking'开头
在跳过网络模式下,mysql 实例根本不“监听 TCP/IP 连接。所有与 mysqld 的交互都必须使用命名管道或共享内存(在 Windows 上)或 Unix 套接字文件(在 Unix 上)” from MySql Docs
希望对您有所帮助。
如果您使用的是 MAMP,问题可能与您的 MySQL 服务器设置有关。确保选中 MAMP 设置中的 Allow network access
选项:
更新 1
在您的根目录中创建 phpinfo.php
文件(对于 MAMP,通常是 /Applications/MAMP/htdocs
)。粘贴以下内容:
<?php phpinfo() ?>
然后检查Loaded Configuration File
属性。在终端中使用 nano
或其他文本编辑器打开它。然后找到并将这3个属性pdo_mysql.default_socket
、mysql.default_socket
、mysqli.default_socket
更改为您的套接字文件。
引用自http://maccrazy.com/lion-upgrade-killed-my-php-site-and-how-i-fixed-it
我终于 phpunit
到 运行!!
我无法在任何地方找到此记录...
在安装过程中的某个时刻,Wordpress 核心文件安装在 /tmp/wordpress/
中。 That Wordpress 安装有自己的 wp-config.php
文件,该文件的值不正确。当我更正这些值以匹配我网站的 wp-config.php
时,phpunit
工作正常!
我不确定这是怎么发生的,但我的理论是我第一次 运行 安装脚本时使用了错误的凭据。但后来我更正了它们(我重新 运行 安装脚本几次)。但是我认为安装脚本并没有覆盖原来的文件。
+400 感谢@Nikita Zernov 的帮助!