Skip to content

Cant get a setup to work with Laravel Herd on Windows (even with a custom driver) #36

@kyloknight

Description

@kyloknight

I am using Laravel Herd on Windows 11 Pro to host all my local sites. Laravel, default WordPress as well as Themosis Framework installs work fine. Its only Lumberjack that I cant seem to configure correctly. I think this will be useful for a lot of users, as Laravel Herd is growing in popularity (everyone at our company uses it, as a lot of developers even on codeable.io).

I tried creating a custom Valet driver:

<?php 

namespace Valet\Drivers\Custom;

use Valet\Drivers\LaravelValetDriver;

class LumberjackValetDriver extends LaravelValetDriver
{
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        return file_exists($sitePath.'/web/wp/wp-load.php');
    }

    public function isStaticFile(string $sitePath, string $siteName, string $uri)
    {
        // Define potential static file paths
        $staticFilePaths = [
            $sitePath.'/web'.$uri,
            $sitePath.'/web/app'.$uri,
            $sitePath.'/web/app/themes'.$uri,
            $sitePath.'/web/app/uploads'.$uri
        ];

        // Check if the static file exists in any of the defined paths
        foreach ($staticFilePaths as $staticFilePath) {
            if ($this->isActualFile($staticFilePath)) {
                return $staticFilePath;
            }
        }

        return false;
    }

    public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
    {
        $_SERVER['PHP_SELF'] = $uri;
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];

        // Check if the request is for a wp-admin page or a static file
        if (strpos($uri, '/wp/') === 0 || $this->isStaticFile($sitePath, $siteName, $uri)) {
            if (is_dir($sitePath.'/web'.$uri)) {
                $uri = $this->forceTrailingSlash($uri);
                return $sitePath.'/web'.$uri.'/index.php';
            }
            return $sitePath.'/web'.$uri;
        }

        // Default to the main index.php for other requests
        return $sitePath.'/web/index.php';
    }

    private function forceTrailingSlash(string $uri): string
    {
        if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
            header('Location: '.$uri.'/');
            die;
        }

        return $uri;
    }
}

/wp/wp-admin works just fine. I can access the dashboard and all admin functionality without any issues. The problem is the front-end, images, js, css etc is never loaded (seems not static files load).

Any help would be appreciated, as we have quite a few sites using Lumberjack, and if we cant get this working we have to move them all over to Themosis Framework which would cost a lot of time, and not be ideal, as they are all working really great using lumberjack.

I did not put down version information for PHP or Lumberjack, as its not relevant to the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions