How Can I Remove “public/index.php” in the URL Generated Laravel?

To remove "public/index.php" from the URL in a Laravel application, you can use the built-in PHP web server or set up a web server with Apache or Nginx. Here are the steps to remove "public/index.php" from the URL using the built-in PHP web server:

  1. Navigate to your Laravel project directory in the terminal.

  2. Run the following command to start the built-in PHP web server:

php artisan serve
  1. The built-in PHP web server will start and you will see the URL where the application is being served. The URL will be in the following format: http://localhost:8000

  2. Open the URL in your web browser and you will see that "public/index.php" has been removed from the URL.

If you want to use Apache or Nginx as your web server, you will need to set up a virtual host for your Laravel project. Here are the steps to set up a virtual host with Apache:

  1. Open the Apache configuration file in a text editor. The location of the configuration file may vary depending on your operating system and Apache installation.

  2. Add the following virtual host configuration to the Apache configuration file:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /path/to/laravel/public
    <Directory /path/to/laravel/public>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>
</VirtualHost>
  1. Replace "example.com" with the domain name of your Laravel project and "/path/to/laravel" with the actual path to your Laravel project on your server.

  2. Restart Apache for the changes to take effect.

  3. Open your domain name in a web browser and you will see that "public/index.php" has been removed from the URL.

I hope this helps! Let me know if you have any questions.