CodeIn House

  • Laravel
  • WordPress
  • jQuery
  • Javascript
  • Contact
Home   Laravel   How to Remove public from url in Laravel and Upload it in Sh ...

How to Remove public from url in Laravel and Upload it in Shared Hosting Server / cPanel ?

September 12, 2020 by SNK

Remove public from url in laravel application

I have been getting a lot of queries regarding, how to remove public url from laravel application so that we can host it in cPanel or shared hosting servers.

As of now laravel can be hosted itself in their dedicated VPS servers and is expensive but most of them are still using hostgator (baby plan hosting) and other shared hosting to host their application, since they are cheap and easy to use.

In this tutorial we are going to learn how we can remove public url from the laravel application and host it in shared cPanel / Hosting.

We have two different approaches for removing public URLĀ from the laravel application :-

First Approach :-

  1. Go to your laravel application and go inside public folder.
  2. Move your .htaccess file 1 step outside of the public folder, (which will be your laravel application root directory).
  3. Rename your server.php to index.php from the laravel root directory.
  4. Done.

2nd Approach :-

This approach is not straight forward but will help to secure your laravel application in much better way. Lets get started.

Step 1:-

Create new folder named local and copy all the files and folders of your laravel application directory into another folder except the public folder.

Step 2 :-

Now move all the files and folders of public folder and paste it in root directory. Look at below image how your files should look by now. Your public folder should be empty by now, get rid of it to avoid confusion.

Root Directory

laravel root directory

Local Directory

laravel local folder

Step 3 :-

Open up your index.php file which is now on root directory of your laravel application. You have to edit the index.php file which was previously on inside public folder and edit these lines.

index.php
PHP
1
require __DIR__.'/../bootstrap/autoload.php';

to

index.php
PHP
1
require __DIR__.'/local/bootstrap/autoload.php';

And

index.php
PHP
1
$app = require_once __DIR__.'/../bootstrap/app.php';

to

PHP
1
$app = require_once __DIR__.'/local/bootstrap/app.php';

Done.

Now try visiting your browser and navigate to url.

If you want to upload your website into shared hosting, directly upload it in your public_html directory inside cPanel.

If you have any problem, feel free to mention them in your comments.

SHARE ON
Buffer

Enjoyed this article?

Like us on

Laravel remove public url from laravel

Avatar for SNK

About SNK

Hello Welcome to my Blog. I develop Websites Using Laravel Framwork & WordPress. Get Latest updates on Facebook | Twitter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get Connected !! With Us

TOP POSTS

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

TUTORIALS TILL DATE

  • September 2022 (6)
  • June 2021 (7)
  • October 2020 (5)
  • September 2020 (6)
  • September 2018 (14)
  • August 2018 (3)
  • July 2018 (4)
  • March 2018 (8)
  • February 2018 (5)
  • January 2018 (1)
  • December 2017 (2)
  • August 2017 (8)
  • May 2017 (1)
  • April 2017 (1)
  • March 2017 (4)
  • February 2017 (3)
  • January 2017 (4)

CATEGORIES

  • Angular (2)
  • CSS3 (3)
  • D3 (3)
  • HTML5 (7)
  • JAVA (11)
  • Javascript (20)
  • jQuery (8)
  • Laravel (35)
  • Others (3)
  • PHP (11)
  • Spring (2)
  • WordPress (10)

Top Categories

  • Angular
  • CSS3
  • D3
  • HTML5
  • JAVA
  • Javascript
  • jQuery
  • Laravel
  • Others
  • PHP
  • Spring
  • WordPress

Get in Touch

DMCA.com Protection Status

Recent Articles

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

© 2012-22 CodeIn House.  •  All Rights Reserved.