Remove public from url in Laravel 5.7

Amandeep Singh February 4, 2019

Remove public from url in Laravel 5.7

Laravel is the latest and powerful MVC framework. In this article, I’m going to explain the process to remove the ‘public’ from the Laravel application URL.

Here we go…

How to install Laravel:

Laravel utilizes Composer to manage its dependencies so, make sure you have Composer installed on your machine. You can also install the Laravel project via Laravel Installer. But first, download the Laravel installer using Composer and run the below mentioned command:

composer global require laravel/installer

Once installed, run Laravel new blog and it will create a directory named blog containing a fresh Laravel installation with all of Laravel’s dependencies already installed:

laravel new blog

And alternatively, you may also install Laravel by running this command in your terminal:

composer create-project --prefer-dist laravel/laravel blog

How to Run Laravel project

Now you have to configure your application on your system and for that open .env file and make the below-mentioned changes:

Set your database configuration with your application as follows:

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=blog

DB_USERNAME=root

DB_PASSWORD=1

If you have PHP installed locally and you would like to use PHP’s built-in development server to serve your application, you may use the serve Artisan command. This command will start a development server at http://localhost:8000:

php artisan serve

After setting up your Laravel project when you run the project with ‘public’, the following screen will appear:

Now when you try to run the project without ‘public’ you face this error:

How to remove Public from Laravel project URL:

When we move the project to live server, we don’t want ‘public’ in the URL and now I’ll explain how to remove ‘public’ from the URL.

To remove ‘public’ from URL first go to the project folder:

  • Rename server.php in your Laravel root folder to index.php.
  • Copy the .htaccess file from /public directory to your Laravel root folder.
  • And also copy css and js folder to your Laravel root folder.

Now you can run your Laravel application without ‘public’ in URL:

Found the article useful? Share it with your friends and co-workers… Now!
If you have any queries or doubts about this topic please feel free to contact us. We are here to help you!

Lets’s Talk

About your ideas and concept