Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

simondavies's avatar

VALET: Simple Site using static files from within folder failing to display

Basically this is the same issue i have experienced at work, thought i would try at home as well.

I have set up a simple two page site as below:

static.dev
    public/
        index.php
        about.php

Both pages are a basic html page with a link on the homepage to the about page and on the about page a link to the homepage, so i can go from home to about and back again.

Now the issue here is that visited static.devand i get the homepage no worries. I then click on the about link and the URL changes to static.dev/about.php but the visual page is still the homepage.

When i then run valet which i get the BasicValetDriverbeing used.

I then took both the files and placed outside the public file into the root of that domain etc so:

static.dev
    index.php
    about.php

Then i run it again, and all works as it should, i then added an extra folder to extend the test

static.dev
    index.php
    about.php
    test/
        index.php

Then run this and all worked even going to the test folder as test/index.phpor test.

I then try this again but with all inside the public folder.

static.dev
    public/
        index.php
        about.php
        test/
            index.php

Ans as expected the url and that work and display but it only selected / shows the main index.php, and also if i just go to static.dev/test/ it instead downloads a file that then has the following:

<b>Notice</b>:  Undefined index: extension in <b>/Users/myusername/.composer/vendor/laravel/valet/cli/drivers/ValetDriver.php</b> on line <b>121</b><br />

So i then decided to add another driver called BasicPHPValetDriver.php that was mentioned and excepted at https://laracasts.com/discuss/channels/general-discussion/valet-404-on-non-laravel-php-sites/replies/160860

But again nothing, run it and still no luck, running valet whichstill gives me the BasicValetDriver, but if i put the files back on the root and its works fine, but this time gives me my new BasicPHPValetDriverdriver created a momento.

So any ideas where i can go from here? It seems to be the public folder causing an issue or at least the settings etc, its always setting it to root and the index.php page no mater what file etc is called?

I will keep pluggin away at this too....

Valet Version 1.1.12

0 likes
3 replies
simondavies's avatar
simondavies
OP
Best Answer
Level 26

typical have a cuppa tea and restart looking at it and i have created a new Driver, that simply added the publicfolder within the pathing, see below, be great though to have this dynamic as i might want to call it by another name, html, build etc, if any one can advise further on this that would be cool, might have another cuppa and see myself :-)

            <?php

        class StaticPHPValetDriver extends ValetDriver
        {

            private $site_folder = '/public';
            /**
             * Determine if the driver serves the request.
             *
             * @param  string  $sitePath
             * @param  string  $siteName
             * @param  string  $uri
             * @return void
             */
            public function serves($sitePath, $siteName, $uri)
            {
                if (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';
            }
        }
3 likes
interphased's avatar

Thanks for the Driver. I work on both Laravel and non-Laravel applications and had some issues since both projects use /public/index.php. To fix it so the Driver only runs on non-Laravel projects check for artisan to exist too:

public function serves($sitePath, $siteName, $uri)
{
    if (!file_exists($sitePath.'/artisan') && file_exists($sitePath.$this->site_folder.'/index.php')) {
        return true;
    }

    return false;
}
1 like

Please or to participate in this conversation.