skip to Main Content

Laravel application is not automatically opening in my browser php artisan serve must open in browser directly

when i execute php artisan serve the url must open in browser .

When in start Laravel application it must open in browser directly

2

Answers


  1. I don’t think running php artisan serve on its own automatically opens your Laravel application in a browser tab. Doing it manually should not be difficult.

    But if you really insist, here’s a one-liner command for Windows:

    start http://localhost:8000 && php artisan serve --port 8000
    

    On Linux:

    xdg-open http://localhost:8000 && php artisan serve --port 8000
    
    Login or Signup to reply.
  2. For Linux

    #!/bin/bash
    
    # Start the Laravel development server in the background
    php artisan serve &
    
    # Wait for a few seconds to make sure the server has started 
    sleep 5
    
    # Open the default web browser with the Laravel server URL
    xdg-open http://127.0.0.1:8000
    

    Save the above code in a file as .sh, for example, start_laravel.sh.
    chmod +x start_laravel.sh
    then
    ./start_laravel.sh

    For Windows

    Save the above code in a file as .bat, for example, start_laravel.bat and run

    @echo off
    
    REM Start the Laravel development server in the background
    start "" php artisan serve
    
    REM Wait for a few seconds to make sure the server has started
    timeout /t 5
    
    REM Open the default web browser with the Laravel server URL
    start http://127.0.0.1:8000
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search