We have a few articles about Laravel framework, but we have not shown how to in install and Laravel in production. If you have ever tried to install Laravel in your site, you might have seen some problems that needs to open public folder in order to run the site properly. In short, when you open the Laravel application directory, you expect to open the application index file. But it’s showing the directory structure and the files and folders. In this tutorial we will show you how to solve this problem step by step with proper and reliable way to change Laravel 5 public folder.
Before starting, let’s see the default directory of Laravel and how you might run the Laravel projects. If you install Laravel inside www directory of you wamp or mamp, you probably go to localhost/laravelapp direcotry. In this cause you have to navigate to public directory and it will show you the application home page. On the other hand, if you install Laravel out of the www directory, you can run it through artisan command.
php artisan serve
I this case, you don’t need to open the public directory. All you need to do is to open localhost::8000 on windows OS. It will open the Laravel home page.
The point is here, if you put your project online for production, you can’t run php artisan serve command there, and you don’t want to open public folder to see your home page as well. Now let’s learn how to solve this problem.
How to Change Laravel 5 Public Folder?
Mainly there is two way to do solve this problem. Using htaccess or changing the directory structure. We will got the second option which is the best way and reliable way as well.
The default directory will look like this.
Create a folder inside this directory and move all the files except public folder. We will create a folder and name it technig.
Move all the files that are inside public directory one folder back. Your folder structure should look like this.
Now you can delete the public folder,
Open the index.php file that you see in the above directory and change the following lines of code.
change it to
And the another line near line 36.
change this one to
You are don’t know. If you open you application directory now, you will see you Laravel home page.
It was an easy and reliable way to change Laravel 5 public folder. If you face any problem during this file changing laravel files, feel free to comment it bellow. We hope it help you. 🙂