1
votes

I use Laravel Valet for locally serving multiple Laravel, WordPress and vanilla PHP applications.

I have one specific application that is vanilla PHP that I access via Valet from http://myapplication.test

This application has a /public/index.php file which is auto-magically displayed when I go to the test URL, as Valet knows to look in the public directory.

The problem I am having is, when I put a /public/test.php file and try to access this by going to http://myapplication.test/test.php ...it does not serve the file. Instead I am forced to go to http://myapplication.test/public/test.php

Is there any way I can fix this?

It is causing me to do an ugly duplication work-around in my codebase. In the live project, going to www.liveurl.com/test.php works, so I am having to put a second public directory inside the actual public directory to reference the file as /public/test.php everywhere in the codebase. I'd really just like to use this in the same place locally and live. I hope that makes sense.

Any help or insight appreciated. Thanks!

1
Can you please show your htacess file? either you've to move your htaccess file on route folder or you may change in public htacess.Dilip Hirapara
So I am not using Laravel for this specific project, only Valet to serve locally. So I have no routes folder. I also am using a baseline Digital Ocean live server, which isn't the issue. The issue is not being able to access a php file in the public folder locally from Laravel. My local vanilla PHP project has no .htaccess file. Hope that helps explain better.fylzero

1 Answers

5
votes

You may have to create a custom-valet-drivers for it.

Go to: ~/.config/valet/Drivers

Create PhpValetDriver.php file and paste this code:

<?php

class PhpValetDriver extends ValetDriver
{

     private $site_folder = '/public';

    /**
     * Determine if the driver serves the request.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return bool
     */
     public function serves($sitePath, $siteName, $uri)
     {
         if (!file_exists($sitePath.'/artisan') &&
              file_exists($sitePath.$this->site_folder.'/index.php')) {

             return true;
         }
         return false;
     }

    /**
     * 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 (file_exists($staticFilePath = $sitePath.$this->site_folder.$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)
    {
        $path = $sitePath.$this->site_folder;

        if ($uri == '/') {
            return $path.'/index.php';
        }

        return strpos($uri, '.php') ? $path.$uri : $path.$uri.'.php';
    }
}

and then: valet restart