Attempting to use Laravel Herd and DBngin for local Development with Radicle

Previously I setup radicle with Local on my machine, but am trying a different approach on a different machine.

I have setup Laravel Herd on my main mac machine. I am not native PHP dev, so haven’t used much of composer. I am trying to figure out how to setup Radicle locally with laravel Herd. I have also setup a database with Dbngin. I looked up online and the default DB connection for DBngin is root username and blank password.

Here is my radicle .env

and yes I spelled raidcle wrong here but it is spelled wrong (the same) in the database

DB_NAME='raidcle'
DB_USER='root'
DB_PASSWORD=''

# Optionally, you can use a data source name (DSN)
# When using a DSN, you can remove the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST variables
# DATABASE_URL='mysql://database_user:database_password@database_host:database_port/database_name'

# Optional database variables
# DB_HOST='localhost'
# DB_PREFIX='wp_'

WP_ENV='development'
WP_HOME='http://example.com'
WP_SITEURL="${WP_HOME}/wp"

# Specify optional debug.log path
# WP_DEBUG_LOG='/path/to/debug.log'

# Generate your keys here: https://roots.io/salts.html
AUTH_KEY='generateme'
SECURE_AUTH_KEY='generateme'
LOGGED_IN_KEY='generateme'
NONCE_KEY='generateme'
AUTH_SALT='generateme'
SECURE_AUTH_SALT='generateme'
LOGGED_IN_SALT='generateme'
NONCE_SALT='generateme'

ACORN_ENABLE_EXPIRIMENTAL_ROUTER='True'

I have run yarn && yarn build and composer install

Herd paths look like this

And Herd sites look like this

Screenshot 2023-11-14 at 11.43.10 AM

I tried the wp.test in a browser but I get this error

This is my database setup


Screenshot 2023-11-14 at 11.44.59 AM

Any help here to get a local dev environment setup with Larvel Herd DBngin and Radicle would be great thanks

Did you create a database? https://sequel-ace.com/ is pretty good. “raidcle” from your screenshot is just a friendly name for the database server in DBngin it’s self and is not relevent.

1 Like

Ok, I hadn’t I did just now, In DB pro, and changed the DB_NAME in the .env to radicle-db same as the db I just setup

But still the same error

I haven’t tried Radicle with Herd yet but looking at your site paths, something seems off with both the Herd paths and the Site paths.

As you can see with the other Herd Paths, this part is looking for projects in a parent directory. In your case it seems like that’s /Users/anderskitson/acorn.

I’m confused why there are 3 separate sites for, what looks like, the same project. Assuming it’s just one project, I think your Site Path should look like /Users/anderskitson/acorn/radicle-main rather than adding /public/content, /public/dist, or /public/wp.

*corrected above. I originally made a mistake with the recommended site path

1 Like

So the way herd paths work is it somehow autogenerates all those sites based on your path. So if I change it to your recommendation then I get this.


Maybe I should just use larvel valet instead.

In your General Settings → Herd Paths, it should be /Users/anderskitson/acorn.

That being said, I would probably put the project in the Herd directory or valet/Sites rather than acorn, especially if you’re developing anything other than websites in that directory.

also, if you use valet/Sites you can always switch to valet at any time, if it’s already installed.

1 Like

Ok we are getting closer now I just have the one site. I moved into the Herd folder

However I get this

I tried updating the bud proxy

bud
    .proxy(`http://radicle-main.test`)

I must be missing some key point.

did you also change the WP_HOME variable to http://radicle-main.test in your .env file?

Hmm, yes just tried that per your suggestion, and still getting the same 404. Tried restarting Herd as well. How do I run it with Valet since you said that is installed?

If you want to switch to using Valet instead of Herd, I think you have to install valet separately. Laravel Valet - Laravel 10.x - The PHP Framework For Web Artisans

One last thing you can try with Herd is to add a local radicle driver to the project. I have valet installed so this may or may not work for you, but here’s what you can try:

Add a LocalRadicleDriver.php file to the root of your project /radicle-main and add the following to that file:

<?php
use Valet\Drivers\LaravelValetDriver;

class LocalRadicleDriver extends LaravelValetDriver
{
    /**
     * Determine if the driver serves the request.
     *
     * @param  string $sitePath
     * @param  string $siteName
     * @param  string $uri
     * @return bool
     */
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        return file_exists($sitePath . '/public/content/mu-plugins/bedrock-autoloader.php') &&
               file_exists($sitePath . '/public/wp-config.php') &&
               file_exists($sitePath . '/bedrock/application.php');
    }

    /**
     * Determine if the incoming request is for a static file.
     *
     * @param  string       $sitePath
     * @param  string       $siteName
     * @param  string       $uri
     * @return string|false
     */
    public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
    {
        $staticFilePath = $sitePath . '/public' . $uri;
        if ($this->isActualFile($staticFilePath)) {
            return $staticFilePath;
        }
        return false;
    }

    /**
     * Get the fully resolved path to the application's front controller.
     *
     * @param  string $sitePath
     * @param  string $siteName
     * @param  string $uri
     * @return string
     */
    public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
    {
        $_SERVER['PHP_SELF'] = $uri;
        if (strpos($uri, '/wp/') === 0) {
            return is_dir($sitePath . '/public' . $uri)
                            ? $sitePath . '/public' . $this->forceTrailingSlash($uri) . '/index.php'
                            : $sitePath . '/public' . $uri;
        }
        return $sitePath . '/public/index.php';
    }

    /**
     * Redirect to uri with trailing slash.
     *
     * @param  string $uri
     * @return string
     */
    private function forceTrailingSlash(string $uri)
    {
        if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
            header('Location: ' . $uri . '/');
            die;
        }
        return $uri;
    }
}

I have setup Valet, parked a new folder for wordpress sites, and put the radicle-main in that folder and visited http://radicle-main.test but I get this error now

Screenshot 2023-11-14 at 2.55.10 PM

% valet --version

Laravel Valet 4.5.0

% php --version

PHP 8.2.11 (cli) (built: Sep 29 2023 00:10:16) (NTS)

I change to php 8.1 as recommended here

However now I am back to this error

I haven’t deleted the database or anything or changed the .env file so a little lost now

And this is my databases in mysql cli just to double check

mysql> SHOW DATABASES;   
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| radicle-db         |
| sys                |
+--------------------+

So my current .env is like this

DB_NAME='radicle-db'

DB_USER='root'

DB_PASSWORD=''

# Optionally, you can use a data source name (DSN)

# When using a DSN, you can remove the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST variables

# DATABASE_URL='mysql://database_user:database_password@database_host:database_port/database_name'

# Optional database variables

# DB_HOST='localhost'

# DB_PREFIX='wp_'

WP_ENV='development'

WP_HOME='http://radicle-main.test'

WP_SITEURL="${WP_HOME}/wp"

As a sanity check, did you stop Herd and restart Valet?

Also, does uncommenting DB_HOST & DB_PREFIX in .env help?

Hi there!
I hope you are well.

I was never able to connect to my DB with the default DB_HOST, which is localhost. I was able to fix it by setting the DB_HOST to 127.0.0.1.

I hope this helps!
Cheers!

2 Likes

Oh Man, that was it the DB_HOST that worked for valet. However I am really keen to get it working with Herd, so I uninstalled Valet and am back to trying to get it to work with Herd. Now getting a 404 on Herd, any idea why that may be? if I can’t get it by the EOD I will go back to valet, but I want to try Herd because it will be easier to introduce the Local environment setup to the rest of my team.

Yeahhh I had this issue before as well.

The issue is probably coming from Herd detecting your site, but doesn’t know what it is, so it gives a 404 (which is very not helpfull…)

I opened a ticket about a month ago and there is a fix by creating your own local driver. You can find it here: [Bug]: 404 Site not found: herd.sock not found · Issue #228 · beyondcode/herd-community · GitHub

Hope this helps as well!
Cheers!

You don’t have to uninstall Valet to use Herd. You only need to run valet stop. Details in link below.

You should definitely try to add a local driver. Either the one @ogamacheDev provided in the link above or the one I provided here

I found that Herd wasn’t reading my custom drivers added to valet for a Trellis project and adding the driver to the project root fixed that.

1 Like

This worked, I had named the file LocalRadicleDriver.php as per @csorrentino comment earlier but it didn’t recognize it until I named in LocalValetDriver.php I used @ogamacheDev Driver for now. I did test Bedrock while I was waiting and it worked out of the box without a driver.

Anyways thanks so much for all the help everyone it is working now.

4 Likes

Thanks for this tip, I figured that out after I uninstalled it, that I just need to stop it. I am so much in the javasScript NPM world, I get lost on this side. Thanks for the help.

2 Likes