Valet: Valet directory appears in URL (CakeValetDriver)

Created on 1 May 2017  路  10Comments  路  Source: laravel/valet

What my URLs are being rewritten to:
http://dmn-analyser.dev/Users/steffen/.composer/vendor/laravel/valet/users/login

What I expected:
http://dmn-analyser.dev/users/login

The problem also occurs on a fresh CakePHP (3.4) installation. F.e. with static resources:
... href="/Users/steffen/.composer/vendor/laravel/valet/webroot/css/base.css" ...

  • I'm using the default CakeValetDriver without modifications.
  • Other drivers are working correctly.
  • I'm on the latest valet version.
  • I'm using PHP 7.0
  • I'm using a Mac.
  • The applications seems to be configured correctly.

Anyone with the same problem and/or a solution or idea?

Most helpful comment

Okay, after reading the documentation and some debugging, I think I found every $_SERVER variable CakePHP 3 needs and came to this solution:

public function frontControllerPath($sitePath, $siteName, $uri)
{
    $_SERVER['DOCUMENT_ROOT'] = $sitePath.'/webroot';
    $_SERVER['SCRIPT_FILENAME'] = $sitePath.'/webroot/index.php';
    $_SERVER['SCRIPT_NAME'] = '/index.php';
    $_SERVER['PHP_SELF'] = '/index.php';

    return $sitePath.'/webroot/index.php';
}

I will provide a PR.

All 10 comments

Having the same issue. Static files also return a 404, but only arbitrarily. Tried debugging but no luck so far.

Adding the following line to CakeValetDriver in method frontControllerPath works for me:
$_SERVER['PHP_SELF'] = $_SERVER['HTTP_HOST'];

@Luceos and @ergineker: If one of you could verify it works, I will provide a pull request.

Yes that works!

Okay, after reading the documentation and some debugging, I think I found every $_SERVER variable CakePHP 3 needs and came to this solution:

public function frontControllerPath($sitePath, $siteName, $uri)
{
    $_SERVER['DOCUMENT_ROOT'] = $sitePath.'/webroot';
    $_SERVER['SCRIPT_FILENAME'] = $sitePath.'/webroot/index.php';
    $_SERVER['SCRIPT_NAME'] = '/index.php';
    $_SERVER['PHP_SELF'] = '/index.php';

    return $sitePath.'/webroot/index.php';
}

I will provide a PR.

I don't understand this.

You are using CakePHP Framework but using Laravel Valet?

@ruchern: Yes, I think that's the concept behind Valet and its various drivers.
When there is a driver for your framework/application, you can run it on Valet.
And you can add your own drivers.

From the Documentation:

Out of the box, Valet support includes, but is not limited to:

  • Laravel
  • Lumen
  • Symfony
  • Zend
  • CakePHP 3
  • WordPress
  • Bedrock
  • Craft
  • Statamic
  • Jigsaw
  • Static HTML

However, you may extend Valet with your own custom drivers.

https://laravel.com/docs/5.4/valet

@steffenbrand Oh I see. I actually never thought of that.

@steffenbrand Thank you ! 馃挴

You're welcome. Unfortunately I don't think my PR is going to be merged.Even if the documentation lists CakePHP as supported and it's broken without it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EHLOVader picture EHLOVader  路  4Comments

webartistse picture webartistse  路  4Comments

dannygsmith picture dannygsmith  路  5Comments

tomirons picture tomirons  路  4Comments

tommytompkins picture tommytompkins  路  4Comments