Scroll To Top

How to Change Laravel 5 Public Folder to Your Site Name?

Posted in Code1 year ago • Written by Hujjat Nazari3 Comments

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.

Introduction

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.

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.

Step 1

The default directory will look like this.

change laravel 5 public folder

change laravel 5 public folder default structure

Create a folder inside this directory and move all the files except public folder. We will create a folder and name it technig.

Step 2

Move all the files that are inside public directory one folder back. Your folder structure should look like this.

change laravel 5 public folder

change laravel 5 public folder

Now you can delete the public folder,

Final step

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.

Conclusion

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. 🙂


TAGS: , , , ,

3 Comments so far. Feel free to join this conversation.

  1. muriloJanuary 14, 2017 at 3:00 am - Reply

    hello my friend , very good tutorial .I had done like this example .
    It worked ok , the laravel folder I created at one place and the public folder , I created in the public folder . It worked ok .

    But the probleme is when I gonna make a upload of a image , in my admin area . The image was suppose to go to my public folder/assets/images/myimage.jpg
    but is goint to my laravel application ->
    laravel/public/assets/images/myimage.jpg .

    It seams that I need to change as well the public path directory to laravel make the upload outside the laravel structure folder ,and make the upload inside the root folder that I created ( the public ) do you know how I can do it ?

    I make upload like this –
    $file->move(public_path(‘/assets/temp’), $main_image_filename);
    (It was supose to go to assets , but is going to local/laravel/public/assets…. )

    Thanks my friend

  2. Hujjat NazariApril 12, 2017 at 10:00 am - Reply

    That’s Okay.

    You should use asset() function to access those images. It will look in the public directory no matter where it is.

  3. SumedhaSeptember 1, 2017 at 1:38 pm - Reply

    Hello sir, I follow all steps but my css and js are not working for example I am giving in my app.blade.php and on inspect browser I found it as http://localhost:8000/css/bootstrap.min.css, so how can I use my css files in project, is there any problem with public location? Please help.

Leave A Response