Laravel Valet was released last week and you should definitely check it out!
It basically allows you to “park” your sites folder (mine is called ~/Code
, for example) then magically access all subfolder on their own local domain name, like so subfolder.dev. No need to cd
into a folder to run PHPs webserver. Valet runs in a daemon and takes care of all of that!
Check out how to install and use it: https://laravel.com/docs/5.2/valet
Right now it’s OS X only, but I think Linux support is coming soon.
2 Likes
@pedroborges Did you get issues with the panel on Valet? All my sites pages work but i get a 404 when trying to access the panel. Did you come across this?
There is now a Linux fork of Valet now.
Edit: I just tried with the Kirby 2.5.8 Starter Kit on Valet and I can reach the panel. Strange. Upgrading my project to latest Kirby version does not help.
Ah ha! I have figured out the problem. My projects are in projectfolder/public
structure. If I put kirby straight in the projectfolder
, the panel works. Ill ask over on the Laravel forums how to make it work, i think this is a Valet issue.
Under the hood, Valet uses Nginx, not Apache. So the .htaccess rules are useless there.
Valet has drivers for different projects. I made the Kirby driver which only works with the default folder structure. In your case you will need to add a custom driver. Valet’s documentation has a section for that and you can look at existing drivers to learn what’s possible.
Thank @pedroborges I have looked but i cant make it work. I created a local valet driver containing this:
<?php
class LocalValetDriver extends KirbyValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return void
*/
public function serves($sitePath, $siteName, $uri)
{
return is_dir($sitePath.'/public/kirby');
}
/**
* 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)
{
if ($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)
{
// Needed to force Kirby to use *.dev to generate its URLs...
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
if (preg_match('/^\/panel/', $uri)) {
$_SERVER['SCRIPT_NAME'] = '/public/panel/index.php';
return $sitePath.'/public/panel/index.php';
}
if (file_exists($indexPath = $sitePath.'/public/index.php')) {
$_SERVER['SCRIPT_NAME'] = '/public/index.php';
return $indexPath;
}
}
}
I had hoped that would would work but all its doing is adding /public/ into all the paths and i get a debug page when trying to access the panel.
For instance my asset paths now look like this:
<link rel="stylesheet" href="http://example.dev/public/assets/css/site.css">
I think i need to modify the $sitePath
variable but i have no idea where that is set.
Do you have any ideas how i can make this work. The reason i want this is because i use a build tool that compiles into the public folder.
My project is structured like this:
sites
myprojectone
node_modules
public
---.htaccess
---assets
---content
---index.php
---kirby
---license.md
---panel
---readme.md
---robots.txt
---site
---thumbs
src
---fonts
---images
---js
---sass
package.json
webpack.mix.js
The more robust solution would be to register the public
directory as a Valet site directly using the link
command. Then you don‘t even need the custom driver.
Thanks @lukasbestle thats exactly what i did in the end. Its just not quite as slick as parking the whole directory containing all my client sites (theres alot!). I will just have to link each one as I go.