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

This rename saved my day and allowed me to get Radicle working with Herd. Thank you.

2 Likes

@wispyco Sorry to ask, but what are the steps now to get this working with Radicle?

Should I place that driver within the Radicle unzipped directory and then point Herd to that directory? If you could let me know the steps to do this, please. I’ve read all the discussions but still don’t seem to get this working.

Let’s say now I have a fresh Radicle directory - what should I do next? Exactly, should I just put the driver in the directory, or should I install Valet first?

Thanks.

I think you can just put the unzipped Radicle directory inside of “~/Herd/Radicle” Radicle being the folder you unzipped. And then place the drive in the Radicle folder.

Let me know if you need more help.

You will need something like DBngin to create a mysql server and database after you create the server.

@wispyco Yeah I’m still getting the 404.

Is this the code you have in your driver? how about the folder structure?

Folder Structure:

Driver Code:

<?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 am using this, the first thing I notice is laravelValetDriver in yours where I have BasicValetDriver. I also have Herd php at 8.1

<?php

use Valet\Drivers\BasicValetDriver;

class LocalValetDriver extends BasicValetDriver
{
    /**
     * Determine if the driver serves the request.
     */
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        return true;
    }

    /**
     * !!!! ENTER THE WEB ROOT IN THE $staticFilePath VARIABLE
     * Determine if the incoming request is for a static file.
     */
    public function isStaticFile(string $sitePath, string $siteName, string $uri)
    {
        $staticFilePath = $sitePath.'/public'.$uri;

        if ($this->isActualFile($staticFilePath)) {
            return $staticFilePath;
        }

        return false;
    }

    /**
     * !!!! ENTER THE WEB ROOT IN THE $sitePath VARIABLE
     * Get the fully resolved path to the application's front controller.
     */
    public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
    {
        return parent::frontControllerPath(
            $sitePath.'/public',
            $siteName,
            $this->forceTrailingSlash($uri)
        );
    }

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

        return $uri;
    }
}

Thanks @wispyco, the driver was not working correctly. I resolved this by switching the content of the driver like yours and checking if there was already a ‘Drivers’ directory in the Valet directory, as indicated in the code:

use Valet\Drivers\BasicValetDriver;

However, I didn’t have such a folder. To resolve this, I downloaded a driver from GitHub:

Once the driver was in place, I encountered an error with the database. The issue was that DBngin did not create the database, so I had to create it manually using the command line.

After resolving these issues, everything is now working correctly.

In my opinion, the documentation should be updated to reflect this process as a reliable method for setting up a development environment for noobs like me (there are many :joy: out-there). I also found Lando to be a viable alternative.

Trellis with Radicle did not work for me due to Vagrant issues on my M1 Mac I usually use Lima but I don’t know why the server didn’t start when I spin up a Lima instance the url was not working.

If Trellis had a user interface similar to Herd, it would be the best way to work with WP development, as it handles caching and synchronisation with live sites…, which is not possible with Herd so once we finish we still need to do other stuff for the live site to work correctly with dev env.

1 Like