Forum

Thread tagged as: Error, Configuration

Perch Licence not working - Development environment

Hi all

I am having trouble with Perch running on my development environment. Even though I have setup my Perch licence so that it accepted my development domain, it's still saying that it's not valid domain.

I am running Laravel Valet as my development environment.

Any ideas?

Thanks in advance.

Steve

Steve Forbes

Steve Forbes 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Is Perch up to date?

Hi Rachel

Yes, it's running the latest version.

Thanks

Rachel Andrew

Rachel Andrew 394 points
Perch Support

It looks like you are not sending the data to our server. The usual reason for that is people running very up to date PHP with an old version of Perch.

If that isn't the case then maybe a firewall blocking the request (eg. you have cURL installed but your Mac firewall is blocking it).

Is there anything in the error log?

Hi Rachel

That is strange. I am running PHP 7.1.2 with the latest version of Perch. I also have my Mac firewall turned off.

Where can I find the error log? Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't really know what Laravel Valet is, but which version of cURL is it using? Does it have somewhere to configure your hostname?

Hi Steve, You probably need a custom valet driver for Perch (https://laravel.com/docs/5.4/valet#custom-valet-drivers). I'm gonna see how my local perch sites run on valet this arv (previously used homestead for dev), if I create a working custom driver for it I'll share it.

Cheers, Andrew

Righto, after much messing around with custom driver config this seems to be working for me. It's just a local custom driver, so you need to save this code into a file called 'LocalValetDriver.php' in the root of your project. I will make a general Perch driver soon, as I have a lot of Perch projects I'll need to run on Valet.

I think this file is probably more complex than it needs to be, but I just wanted to get something which worked asap. The driver is effectively just the Valet basic driver but with code to ensure the $_SERVER['SERVER_NAME'] variable is properly set (it's not set by default), as Perch uses that variable to validate the licenses.

Hope it helps!

<?php

class LocalValetDriver extends ValetDriver
{
    /**
     * Determine if the driver serves the request.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return bool
     */
    public function serves($sitePath, $siteName, $uri)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return true;
    }
    /**
     * 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($sitePath, $siteName, $uri)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];

        if (file_exists($staticFilePath = $sitePath.'/public'.$uri)) {
            return $staticFilePath;
        } elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
            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($sitePath, $siteName, $uri)
    {
        $_SERVER['PHP_SELF']    = $uri;
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        $dynamicCandidates = [
            $this->asActualFile($sitePath, $uri),
            $this->asPhpIndexFileInDirectory($sitePath, $uri),
            $this->asHtmlIndexFileInDirectory($sitePath, $uri),
        ];
        foreach ($dynamicCandidates as $candidate) {
            if ($this->isActualFile($candidate)) {
                $_SERVER['SCRIPT_FILENAME'] = $candidate;
                $_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate);
                $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
                $_SERVER['DOCUMENT_ROOT'] = $sitePath;
                return $candidate;
            }
        }
        $fixedCandidatesAndDocroots = [
            $this->asRootPhpIndexFile($sitePath) => $sitePath,
            $this->asPublicPhpIndexFile($sitePath) => $sitePath . '/public',
            $this->asPublicHtmlIndexFile($sitePath) => $sitePath . '/public',
        ];
        foreach ($fixedCandidatesAndDocroots as $candidate => $docroot) {
            if ($this->isActualFile($candidate)) {
                $_SERVER['SCRIPT_FILENAME'] = $candidate;
                $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
                $_SERVER['SCRIPT_NAME'] = '/index.php';
                $_SERVER['DOCUMENT_ROOT'] = $docroot;
                return $candidate;
            }
        }
    }
    /**
     * Concatenate the site path and URI as a single file name.
     *
     * @param  string  $sitePath
     * @param  string  $uri
     * @return string
     */
    protected function asActualFile($sitePath, $uri)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return $sitePath.$uri;
    }
    /**
     * Format the site path and URI with a trailing "index.php".
     *
     * @param  string  $sitePath
     * @param  string  $uri
     * @return string
     */
    protected function asPhpIndexFileInDirectory($sitePath, $uri)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return $sitePath.rtrim($uri, '/').'/index.php';
    }
    /**
     * Format the site path and URI with a trailing "index.html".
     *
     * @param  string  $sitePath
     * @param  string  $uri
     * @return string
     */
    protected function asHtmlIndexFileInDirectory($sitePath, $uri)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return $sitePath.rtrim($uri, '/').'/index.html';
    }
    /**
     * Format the incoming site path as root "index.php" file path.
     *
     * @param  string  $sitePath
     * @return string
     */
    protected function asRootPhpIndexFile($sitePath)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return $sitePath.'/index.php';
    }
    /**
     * Format the incoming site path as a "public/index.php" file path.
     *
     * @param  string  $sitePath
     * @return string
     */
    protected function asPublicPhpIndexFile($sitePath)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return $sitePath.'/public/index.php';
    }
    /**
     * Format the incoming site path as a "public/index.php" file path.
     *
     * @param  string  $sitePath
     * @return string
     */
    protected function asPublicHtmlIndexFile($sitePath)
    {
        $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
        return $sitePath.'/public/index.html';
    }


}

For anyone using Perch with Valet, I've cleaned up this driver and added it to Github, also made it a general Perch driver.

https://github.com/andocobo/perch-valet-driver