Trouble setting up algolia command

I’m using the Algolia WP plugin - Version 2.11.3. My end goal is sort an index by date, but right now I’m trying to follow the steps listed here -https://www.algolia.com/doc/integration/wordpress/indexing/importing-content/?language=php

I have WPCli installed but after following all of the steps under “Setup Algolia Command”, i get an error when running wp algolia hello - No such file or directory in wp-includes/wp-db.php on line 1612. I know the WP cli is working because running wp --info prints our the expected information.

I’m running all of this locally using VVV. Any tips on how to get these commands to run?

Hi @katie.jenkins,

Welcome to the Algolia Community!

We do not recommend using the Algolia WordPress plugin as we no longer offer support for that plugin.

We created a new guide for connecting WordPress to Algolia, which it looks like you’ve already found!

If you still have the Algolia WordPress plugin installed and activated, you will need to deactivate that plugin and use the guide instead.

If you’ve already installed everything according to the guide, you should not be getting the error.

Can you confirm the installation of the Algolia php client as seen in the guide here, and then post your code for the Algolia plugin that you have created from the guide?

I look forward to your reply!

from my algolia-custom-integration.php:


/**
 * Plugin Name:     Algolia Custom Integration
 * Description:     Add Algolia Search feature
 * Text Domain:     algolia-custom-integration
 * Version:         1.0.0
 *
 * @package         Algolia_Custom_Integration
 */

// Your code starts here.
require_once __DIR__ . '/api-client/autoload.php';
// If you use composer, require the composer autoload
// require_once __DIR__ . '/vendor/autoload.php';

global $algolia;

$algolia = \Algolia\AlgoliaSearch\SearchClient::create("HOC1MH55SU", "4e5996351308aa6d6c697ed2919447e4");

require_once __DIR__ . '/wp-cli.php';

from my wp-cli.php file:

<?php

if (! (defined('WP_CLI') && WP_CLI)) {
    return;
}

class Algolia_Command {
    public function hello( $args, $assoc_args ) {
        WP_CLI::success('Algolia is correctly loaded 🎉');
    }
}

WP_CLI::add_command( 'algolia', 'Algolia_Command' );

and here is the structure inside of my plugins folder - https://cl.ly/fd3c9c87989f

HI @katie.jenkins,

That looks good!

Do you get a stack trace or can you see the file it’s looking for in wp-includes/wp-db.php on line 1612?

Can you confirm that that file exists?

I look forward to your reply!

this is from 1612:

if ( WP_DEBUG ) {
			mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
		} else {
			@mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
		}

I looked a little more closely at the error and saw that there’s a second part to it, which kind of shows why the 1612 error is happening

This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down. 

My database is in fact up and running, my site is working just fine…

Hi @katie.jenkins,

Can you go into your wp-config.php and change your DB_HOST to 127.0.0.1 instead of localhost and see if that helps?

Best regards,

no luck with that :frowning:

Hi @katie.jenkins,

The error seems to be coming from the WP CLI instead of the Algolia setup.

Maybe reinstall the WP CLI and see if that helps with the error. Maybe run some other WP CLI commands and see if you have other issues with the database setup.

Sometimes, in my experience, the MySQL instance running in your browser is different than the mysql instance you are running from the command line. Or you may not have MySQL access from the command line.

Let us know how it goes!

thanks @cindy.cullen! After doing a little more digging, I realized I was running my cli command from inside of the vagrant directory rather than ssh’ing into the box. Once i did that, i get the “Success: Algolia is correctly loaded :tada:” message…hooray! Now on to the hard part :wink:

I’m going through this guide, and it seems as though this a guide for a fresh install of Algolia. We have been using Algolia for quite awhile now, so I’m worried about indexing the wrong posts from the lower environments. That has happened to me before where all of the permalinks in production were incorrect and pointed to a lower environment. How would I go about keeping everything as is?

Hi @katie.jenkins,

I’m glad you figured it out!

Can you explain what you mean by ‘lower environment’? Do you mean a development or staging environment?

You can prefix your indices with something like ‘dev_’ or ‘staging_’ or ‘production_’ or just ‘prod_’.

You can have multiple indices for your different environments.

This documentation may be helpful.

Let us know how that works for you!