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

Westie's avatar
Level 5

Laravel 11 Jetstream/Inertia and Codepsaces ERR_CONNECTION_REFUSED

Im trying to get a brand new project working in github codespaces. I have created the project as per the Jetstream documentation but when I run npm run dev and php artisan serve, I just get a blank white screen. In the dev tools network tab I can see ERR_CONNECTION_REFUSED for client, app.js and Welcome.vue but I just cant find a solution anywhere. The same project works without issue when run locally. Desperately hoping someone here knows how to get this working and can help. Any and all help very much appreciated!

Please be gentle, I am new to Laravel and this is my first post in this forum (maybe any forum actually...šŸ¤”)

0 likes
2 replies
Westie's avatar
Westie
OP
Best Answer
Level 5

For anyone who stumbles on this looking for a solution I did find one with a little help!

In bootstrap/app.php add this line directly underneath the ->withMiddleware method call:

$middleware->trustProxies(at: '*');

Then in package.json add this line to the scripts object:

"watch": "vite build --watch"

Now run vite using npm run watch with php artisan serve as normal and your Laravel Jetstream/Inertia project should run in Codespaces.

LaryAI's avatar
Level 58

When working with Laravel in GitHub Codespaces, especially with Jetstream and Inertia, encountering an ERR_CONNECTION_REFUSED error can be frustrating. This issue often arises due to misconfigurations in the development environment or network settings. Here are some steps you can take to resolve this issue:

  1. Check the PHP Artisan Serve Host and Port: By default, php artisan serve runs on localhost:8000. However, in a Codespaces environment, you need to bind the server to 0.0.0.0 to make it accessible externally.

    Run the following command:

    php artisan serve --host=0.0.0.0 --port=8000
    
  2. Expose the Port in Codespaces: Ensure that the port you are using (e.g., 8000) is exposed in your Codespaces environment. You can do this by adding a devcontainer.json file or configuring it through the Codespaces interface.

  3. Check Vite Configuration: If you are using Vite (which is common with Laravel Jetstream), ensure that it is configured to listen on all network interfaces. Update your vite.config.js file:

    export default {
      server: {
        host: '0.0.0.0',
        port: 3000, // Ensure this port is also exposed
      },
    };
    
  4. Run Vite with the Correct Host: When running Vite, ensure it is also bound to 0.0.0.0:

    npm run dev -- --host
    
  5. Check Network Policies: Sometimes, network policies in Codespaces might block certain connections. Ensure that your Codespaces environment allows connections on the ports you are using.

  6. Inspect Browser Console and Network Tab: Use the browser's developer tools to check for any additional errors or blocked resources that might give more insight into the issue.

  7. Review Environment Variables: Ensure that your .env file is correctly configured, especially the APP_URL and any other environment-specific settings.

  8. Rebuild Codespace: If changes do not take effect, try rebuilding your Codespace to ensure all configurations are applied correctly.

By following these steps, you should be able to resolve the ERR_CONNECTION_REFUSED issue and get your Laravel Jetstream/Inertia project running smoothly in GitHub Codespaces. If the problem persists, consider checking the Codespaces documentation or reaching out to their support for more specific guidance.

Please or to participate in this conversation.