wp-cli: unable to run phpunit on MAMP - bash

I'm following the plugin test setup/install instructions. I got wp scaffold plugin-tests my-plugin to run. But then at the next step when I try to run bash bin/install-wp-tests.sh wordpress_test root '' localhost latest I get the following error:
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'
My local Wordpress site is running with MAMP (which is working). I'm not sure if that's relevant for the install script since I think it's creating a temporary DB to run the tests... Does it matter if it uses the built-in OSX mysql or MAMP's MySQL?
Here's the output from 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
Update 2
I figured out that originally MySQL wasn't installed... that's why I couldn't connect! But now it is. I ran the install script, and this works...
$ ./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
But when I run phpunit I get this:
$ 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
Part of my problem is that I'm not clear on whether wp-cli should be running entirely on native (cli) PHP/Mysql, or MAMP's PHP/Mysql, or some combination of both.
Update 4
I'm pretty sure the final problem is that phpunit needs to be installed in MAMP, but I'm running it from OSX...
$which phpunit
/usr/bin/phpunit
Mentioned in this gist.
Update 6
It turns out you can no longer install phpunit using pear. So I added it as a composer dependency under require-dev, but when I run that version I get the same error!
$ ./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
I even added it to my path to be sure...
$ which phpunit
/Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/phpunit/phpunit/phpunit
Update 7
After reading the comments at the bottom of this blog post, I see that the install script was referencing the OSX version of mysqladmin. I'm not sure if this matters, but I prepended MAMPs version in the path, and re-ran the install script. It seems to install the Wordpress files in /tmp/ anyway. Same error when I run phpunit

If you are using MAMP, issue may be relevant to your MySQL Server settings. Make sure to check Allow network access option in MAMP settings:
Update 1
Create phpinfo.php file in your root directory (usually /Applications/MAMP/htdocs for MAMP). Paste the following content:
<?php phpinfo() ?>
Then check the Loaded Configuration File property. Open it using nano or other text editor in terminal. Then find and change this 3 propertiespdo_mysql.default_socket, mysql.default_socket, mysqli.default_socket to your socket file.
Referenced from http://maccrazy.com/lion-upgrade-killed-my-php-site-and-how-i-fixed-it

I finally got phpunit to run!!
I couldn't find this documented anywhere...
At some point during the installation process, Wordpress core files are installed in /tmp/wordpress/. That Wordpress installation has it's own wp-config.php file which had incorrect values. When I corrected those values to match the wp-config.php of my site, phpunit worked without problems!
I'm not sure how this happened, but my theory is that the first time I ran the install script with the wrong credentials. But later I corrected them (I re-ran the install script several times). But I think the install script didn't overwrite the original files.
+400 to #Nikita Zernov for so much help!

Normally if you ftp or telnet to localhost you'll get conection refused, if you want to fix the error change your httpd.conf to ServerName localhost
Also if you want to do remote login try enable remote login by going to
System Preferences -> Sharing -> Remote Login box (check it).
For MySQL Problem
Make sure ‘skip-networking’ is commented out in configuration file(in this case /opt/local/etc/mysql55/my.conf) or when starting mysql server, it does’t start with ‘–skip-networking’
In skip-networking mode, the mysql instance doesn’t “listen for TCP/IP connections at all. All interaction with mysqld must be made using named pipes or shared memory (on Windows) or Unix socket files (on Unix)” from MySql Docs
I hope it help.

Related

Illegal instruction: 4 when executing php artisan migrate

I am new with Laravel and working on a project to practice myself. I have set up and connected my database and when I try to execute the migrate command on the VS Code terminal, I get the error: Illegal Instruction: 4
I have seen different discussions but was not able to find one with good instructions to solve this.
Most of them were for other programs and not Laravel/VS Code.(also I am a Mac user)
Any ideas on this and how to solve it?
enter image description here
This error seems to occur if you have SSL issues or config issues in the options section.
It may be how the composer runs from a root directory and it cannot find the real path of a SSL certificate.
We experienced this due to an incorrect configuration on Symfony[*] where the the mysql port was set to 33060 instead of 3306.
I think you can get this error if your mysql configuration is pointing to the wrong host/port combination, possibly combined with SSL enabled.
The issue is in the php mysql layer so which framework is in use is not so important.
You are trying outside the project folder you should go inside your project folder
cd YOUR_FOLDER_NAME
then
php artisan migrate

autoload.php won't work on my web server

So I followed the instructions on how to use composer to install google's api client.
When I try to open a file in my web browser that only has this code
<?php
require_once 'vendor/autoload.php';
I get these errors from my hosting provider
[03-Aug-2017 23:46:22 UTC] PHP Warning: require(/home/michmarket/public_html/vendor/composer/../guzzlehttp/psr7/src/functions_include.php): failed to open stream: No such file or directory in /home/michmarket/public_html/vendor/composer/autoload_real.php on line 66
[03-Aug-2017 23:46:22 UTC] PHP Fatal error: require(): Failed opening required '/home/michmarket/public_html/vendor/composer/../guzzlehttp/psr7/src/functions_include.php' (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/michmarket/public_html/vendor/composer/autoload_real.php on line 66
I tried to make sure that all of the files API files up to date by running this in my command prompt.
$ composer require google/apiclient:^2.0
When I do, my command prompt says that all my files are up to date. Any thoughts on why I am still getting errors?
If you can't run
$ composer install
on your web server, then you need to transfer your vendor directory to your web server after running the command on your deployment server.
If your deployment server is your local machine, try to make it match the web server in terms of platform requirements as close as possible (PHP versions, you could be running newer versions locally than on the web server), or refer to https://getcomposer.org/doc/06-config.md#platform:
Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "5.4", "ext-something": "4.0"}.
Note You might want to optimize the autoloading as well, take a look at https://getcomposer.org/doc/articles/autoloader-optimization.md#autoloader-optimization.

Fatal error: Unknown: Failed opening required '<path to src>/includes/php.content-header.php'

I was going through some instructions to set up a mock website through xampp for development purposes, but ran into an issue. The instructions are as follows:
Clone this repository
Install PHP and MySQL, and php5-mysql
Changes to php.ini
auto_prepend_file=<path to src>/includes/php.content-header.php
short_tag=On
Get the most recent DB Dump and load it into MySQL
Create user sitename_login with password from includes/class.mysql_db.php
Grant this user permissions to sitename_site
Running local server
Desktop Version
From sitename.com directory run
php -S localhost:8000
As far as I know I followed the instructions as I should have, but when trying to open up php documents in xampp I got this error:
Warning: Unknown: failed to open stream: Invalid argument in Unknown on line 0
Fatal error: Unknown: Failed opening required '<path to src>/includes/php.content-header.php' (include_path='.;F:\xampp\php\PEAR') in Unknown on line 0
The folder layout in xampp is xampp->htdocs->folderName->includes->php.content-header.php
I've tried changing the location of the folders, but that didn't seem to solve the problem. I tried editing the contents of php.ini, but I was getting the same exact error even if I took out /includes/ out of the auto_prepend_file.
Any clues as to what I could do to get past this issue?
Search for require(<path to src>/includes/php.content-header.php) in your file and change it to require(__DIR__ . "\\includes\\php.content-header.php") (assuming your are on Windows)

Laravel Homestead- How to migrate an app into the same folder and connect the MySQL database?

I was able to do install Homestead and to create a new app within the virtual machine.
However, I do have apps that I created outside the virtual machine and I would like to connect my database now. It is editable under localhost/phpmyadmin, it is my mysql standard installation in port 3306.
I have the folder that I have from the Internet and the first app that I specified is called Laravel, how do I do that?
If I just copy it in the same directory, I get:
php artisan serve
PHP Fatal error: Class 'Barryvdh\Debugbar\ServiceProvider' not found in /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157
PHP Stack trace:
PHP 1. {main}() /home/vagrant/Code/foobooks/artisan:0
PHP 2. require_once() /home/vagrant/Code/foobooks/artisan:30
PHP 3. require() /home/vagrant/Code/foobooks/bootstrap/start.php:68
PHP 4. Illuminate\Foundation\ProviderRepository->load() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/start.php:210
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:57
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:121
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'Barryvdh\\Debugbar\\ServiceProvider' not found","file":"\/home\/vagrant\/Code\/foobooks\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php","line":157}}vagrant#homestead:~/Code/foobooks$
vagrant#homestead:~/Code/foobooks$ cd laravel
-bash: cd: laravel: No such file or directory
Move your database from your host machine into homestead:
Install laravel homestead
Copy your app into your shared folder (I guess you did that so far)
backup your database from your host machine
Migrate your database in homestead with artisan migrate if you want a clean and empty database structure.
OR: Rebuild it from your backup. Make sure the database user/password specified in your laravel config exists in homestead and has write access to your rebuild database.
Your homestead database is still accessible from your host machine at 127.0.0.1 and port 33060 (http://laravel.com/docs/4.2/homestead#daily-usage)
Here is a nice tutorial for homestead 2.0 in case you have problems to setup: https://laracasts.com/lessons/say-hello-to-laravel-homestead-two

Drush cannot connect to MySQL on MAMP?

Im trying to set Drush up for the first time. Im using Mamp and Mountain Lion. When I type 'drush' into the terminal I get a list of commands so it seems to be installed up OK.
Ive changed the default web directory folder in MAMP. I have many Drupal sites within folders within the web directory. So the url for one site is http://localhost:8888/omega/omegav3/ and another is http://localhost:8888/omega/omegav4/
By navigating to the site folder in the terminal I can then run a Drush command, however I get errors. When I download Views it does download the module to my sites/all/modules folder correctly, however it gives me some errors. When I try and enable the module it gives me more errors and doesn't enable the module.
unknown:omegav3 MYUSERNAME$ cd /Users/MYUSERNAME/Dropbox/sites/omega/omegav3
unknown:omegav3 MYUSERNAME$ drush dl views
PDO::__construct(): [2002] No such file or directory (trying to connect via [warning]
unix:///var/mysql/mysql.sock) environment.inc:523
Project views (7.x-3.7) downloaded to sites/all/modules/views. [success]
Project views contains 2 modules: views, views_ui.
unknown:omegav3 MYUSERNAME$
unknown:omegav3 MYUSERNAME$ drush en views
PDO::__construct(): [2002] No such file or directory (trying to connect via [warning]
unix:///var/mysql/mysql.sock) environment.inc:523
Command pm-enable needs a higher bootstrap level to run - you will need to invoke [error]
drush from a more functional Drupal environment to run this command.
The drush command 'en views' could not be executed. [error]
Drush was not able to start (bootstrap) the Drupal database. [error]
Hint: This may occur when Drush is trying to:
* bootstrap a site that has not been installed or does not have a configured
database. In this case you can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command line. See `drush
topic docs-aliases` for details.
* connect the database through a socket. The socket file may be wrong or the php-cli
may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for
details.
Drush was attempting to connect to:
Drupal version : 7.23
Site URI : http://default
Database driver : mysql
Database username : root
Database name : omegav3
Default theme : garland
Administration theme : garland
PHP executable : /usr/bin/php
PHP configuration :
PHP OS : Darwin
Drush version : 6.1.0
Drush configuration :
Drush alias files :
Drupal root : /Users/MYUSERNAME/Dropbox/sites/omega/omegav3
Site path : sites/default
File directory path : sites/default/files
unknown:omegav3 MYUSERNAME$
It seems like an issue with Drush and MySQL but ive no idea how to fix this. Im very new to the command line and ive never installed anything like Drush before so im really struggling.
Lets start with saying that i am not familiar with Drush at all. But looking at this from a MAMP perspective i think i know what is going on here.
The line
PDO::__construct(): [2002] No such file or directory (trying to connect via [warning]
unix:///var/mysql/mysql.sock) environment.inc:523 says it all.
By default MAMP is creating the MySQL socket in /Applications/MAMP/tmp/mysql/mysql.sock as stated on the MAMP launch page. However Drush is expecting the socket at var/mysql/mysql.sock.
Well there are two ways to fix this.
Stop all MAMP servers. Edit the file /Applications/MAMP/bin/startMysql.sh,
change --socket=/Applications/MAMP/tmp/mysql/mysql.sock into --socket=/var/mysql/mysql.sock. And don't forget to edit stopMysql.sh as well. This tells MAMP to store the socket elsewhere the next time it boots up the Mysql server.
Create a symlink from /var/mysql/mysql.sock to /Applications/MAMP/tmp/mysql/mysql.sock see this post for more info on symlinks. MAMP will need to be running for you to do this, as the socket file is created dynamically.
Good luck!
I had the same issue - what solved it for me was changing the database host in settings.php from "localhost" to "127.0.0.1".
For me the mysql bin was not existant.
sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql
Fixed it for me.
As an alternative to answer #1, I would recommend you change your command-line MySQL to use MAMP's - this makes sure when you mysql from the command line, that works too. Edit your ~/.bash_profile and add the following line:
alias mysql='/Applications/MAMP/Library/bin/mysql'
This worked for me
sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

Resources