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

nathanpmyoung's avatar

My CSS fails to load when using "php artisan serve" to host on my computer.

Dear All,

I'm a bit new to this so sorry if this is a poor or poorly worded question.

I'm hosting a very basic laravel installation using artisan serve. I've made a few changes including using a separate css file rather than the initial version which has the css on welcome.blade.php.

The css is unable to be shown in the browsers and throws up the following error in chrome - "net::ERR_INVALID_HTTP_RESPONSE". Notably it throws up the same error for the favicon which I haven't changed, so perhaps it's a larger issue.

The css file is public/css/style.css and in welcome.blade.php I have linked to it using the following

link href="{{URL::asset('css/style.css')}}" rel="stylesheet" type="text/css"
which does leave the browser looking in the right place - ":8000/css/style.css"

My PHP/server is stored in a MAMP (not MAMP pro) server. My computer is windows 10.

Thank you for any time and help you can give.

0 likes
17 replies
tykus's avatar

You should not need the port number in a relative link; you should only need to reference the path relative to the root:

<link rel="stylesheet" href="/css/style.css">

If you omit the leading forward slash, it will try to find the asset relative to your current URI

1 like
nathanpmyoung's avatar

Thanks so much. So it seems I'm not very good at markdown here so it ignored a code block. Originally, I had linked to the css file using this in welcome.blade.php

 link href="{{URL::asset('css/style.css')}}" rel="stylesheet" type="text/css" 

But now I have changed it to your suggestion. It still doesn't work but now the error says:

the server responded with a status of 404 (Not Found)

richard's avatar

Please the entire contents of welcome.blade.php file

nathanpmyoung's avatar
<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Nathan P M Young</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
        <!-- <link href="{{URL::asset('css/style.css')}}" rel="stylesheet" type="text/css"> -->
        <link rel="stylesheet" href="/css/style.css">
    </head>
    <body>
        <div class="flex-center position-ref full-height">
            @if (Route::has('login'))
                <div class="top-right links">
                    @auth
                        <a href="{{ url('/home') }}">Home</a>
                    @else
                        <a href="{{ route('login') }}">Login</a>
                        <a href="{{ route('register') }}">Register</a>
                    @endauth
                </div>
            @endif

            <div class="content">
                <div class="title m-b-md">
                     Nathan P M Young
                </div>
                <div>
                    <a href="https://twitter.com/NathanpmYoung">twitter</i></a>
                    <a href="/about">Blog</a>
                </div>
                <div class="links">
                    <a href="/about">Blog</a>
                    <a href="https://laracasts.com">Webcomic</a>
                    <a href="https://laravel-news.com">Videos</a>
                </div>
                <div>
                      <ul>
                          @foreach ($tasks as $task)
                              <li> {{ $task->body }} </li>
                          @endforeach
                      </ul>
                </div>
            </div>
        </div>
    </body>
</html>
richard's avatar

Hmm... this is weird. Have you confirmed that the file exists in public/css folder and it is indeed style.css and not styles.css

1 like
nathanpmyoung's avatar
nathanpmyoung
OP
Best Answer
Level 1

Yeah it's public/css/style.css

Now the error is back to being Failed to load resource: net::ERR_INVALID_HTTP_RESPONSE

(the 404 was because I accidentally deleted the file, but i've restored it now and it still doesn't work.)

And sorry for messing up the best answer thing.

nathanpmyoung's avatar

Sorry that has not changed anything. The error is still the same.

tykus's avatar

Ok, get rid of the asset helper, and do it old school:

<link rel="stylesheet" href="/css/style.css">
Stratos's avatar

If you changed APP_URL in .env you need to restart your serve or cache the config. It is still weird though and it seems you're doing something wrong, the asset helper should be working fine hmm

nathanpmyoung's avatar

I'm doing it like you say tykus and it's still the same.

Stratos, I've tried restarting my serve. Yeah I figure I've messed up somehow but i don't know how.

Thank you all for your time. THis is very kind of you.

MCFreddie777's avatar

Instead of php artisan serve try using php -S localhost:8000 -t public in your project's home directory. Works like a charm for me!

4 likes
_andypeacock's avatar

I just encountered the same problem. php artisan serve has been working with no issues up till I stopped working yesterday. Today: app.js and app.cs return 404s, even though the files are there.

Solution:

  • Stop artisan serve
  • npm run dev to rebuild the assets, which neither deleted nor removed any files
  • Restart artisan serve
  • Everything worked.

No. That makes no sense to me either!

Please or to participate in this conversation.