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

Zoul's avatar
Level 5

index.php in public folder is not loading js and css files

Hi all,

My project is working well with index.php in root, and accessible via this: http://localhost/ecommerce/ecommerce/ecommerce/ I tried to run php artisan serve and it showed an error : require_once(C:\xampp\htdocs\ecommerce\ecommerce\ecommerce/public/index.php): failed to open stream: No such file, then i moved the index.php file from root to public folder, it works but the and js and css files are not being loaded, all i can see its just plain text

=index.php file after moving it to public folder,

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

I appreciate your help !

0 likes
13 replies
Wakanda's avatar

@zool in your .env change APP_URL from

localhost:8000

To

http://localhost/ecommerce/ecommerce/ecommerce/

And then restart yor server and try again

1 like
Zoul's avatar
Level 5

Hey @loyd, Thanks for your answer ! I changed it but still the same.

Binay7587's avatar

Try this

composer dump-autoload
php artisan config-clear
php artisan cache-clear
1 like
SilenceBringer's avatar
Level 55

Hi @zool if previously your index was in root (which is wrong at all), I think you have links to your css/js like /public/js/my.js. Then you move index file back to public, so, really links should be now like /js/my.js (without public prefix)

1 like
laracoft's avatar

@zool

A Laravel folder structure looks like this. You should undo all the files you have moved etc.

C:\xampp\Laravel
├── app
├── public  <- DocumentRoot must point here
├── vendor
...
└── storage
  1. In your case, edit C:\xampp\apache\conf\httpd.conf
  2. Find DocumentRoot "C:/xampp/htdocs" and change it to be DocumentRoot "C:/xampp/Laravel/public"
  3. Restart Apache
  4. Load http://localhost/ to see your Laravel project, http://localhost/robots.txt should work
  5. If things don't work initially, re-install Laravel into the same folder C:\xampp\Laravel
1 like
siangboon's avatar

DocumentRoot should be configure to the path of "public" folder under your app, and double check the .htaccess setting..

1 like
Zoul's avatar
Level 5

Hey @binay7587 , thanks a lot for your help ! I did the same but the nothing worked yet !

Zoul's avatar
Level 5

Hey @silencebringer, thanks a lot for your help ! You are a life saver ! Your solution worked for me, however i'm a littler confused here how it worked. My css and js files were pointing to public/frontend/etc files, then i removed the public/ directory as you mentioned, because i moved the index.php file to public folder, my question is, i could get how index.php is related to my css and js files ? I mean where it catches up the public directory. I appreciate your help !

Zoul's avatar
Level 5

Hey @laracoft , thanks a lot for your help ! I removed public from my css and js files that were pointing to public folder and it worked fine! I should avoid moving the index.php file from public directory in next projects ;)

Zoul's avatar
Level 5

Hey @siangboon , thanks a lot for your help !

I removed public from my css and js files that were pointing to public folder and it worked !

My .htaccess looks like this, with this setting is my .env file protected or do i have to change it ? I appreciate your help !


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

laracoft's avatar

@zool welcome, please select the best answer that helped you solve the issue.

abberh113's avatar

I have the same problem. it works fine on local machine but not on server

Please or to participate in this conversation.