Best Way Eliminate Public Folder in the URL Laravel 5

Seegatesite.com – The easiest way to eliminate public folder in the url laravel 5. If you’ve managed to install laravel 5 on your computer, the problems that will arise is when you access the main page of the web application, you have to go through public/index.php url. Url doesn’t look clean. The following tutorial I will give way to eliminate public folder on laravel 5 so that the url looks pretty.

To overcome this, there are several alternatives to do. Such as .htaccess settings, change the path of a folder or edit the files in httpd.conf. This way I get directly from the article belong id-laravel.com. I will try to explain back.

Two ways I use to eliminate public folder in the URL Laravel 5

Alternative 1 : If you have your own server / using VPS

If you have a private server that can access your file server, then eliminate public folder on laravel is easy. Please edit httpd.conf on the server (If you are using ubuntu httpd.conf files contained in the folder /etc/apache2/apache2.conf), so the root document refers to laravel/public folder .

Add your httpd.conf with script below

<VirtualHost *:80>
    DocumentRoot "/path/to/laravel/public"
    ServerName laravelApp.com
    ServerAlias www.laravelApp.com
</VirtualHost>

Alternative 2: On Cpanel

Basically, the entry point of the laravel application is index.php file that is in the public folder. If you want to access the applications without any url /public on the back, then one way to do this is to move the file public/index.php to the root folder.

Here’s how to remove a public folder on the url laravel 5 on cpanel

  1. Create a folder named laravel (please give the name of your own as you wish) in the root folder of your application.In this example I used the name “laravel”.Create New Folder On Root Folder Eliminate Public Folder In The Url Laravel 5
  2. Copy all files in addition to a public folder into the folder that we have make earlier (in the example I use folder names laravel)Copy All File Except Public Folder On Other Directory Eliminate Public Folder In The Url Laravel 5
  3. Take / cut all the files in the public folder, including .htaccess file and paste the entire file to the root folderCut All File On The Public Folder Eliminate Public Folder In The Url Laravel 5
  4. Change the settings in index.php (and paths.php in the folder bootstrap/paths.php if any)
    • index.php
      require __DIR__.'/laravel/bootstrap/autoload.php';
      
      /*
      |--------------------------------------------------------------------------
      | Turn On The Lights
      |--------------------------------------------------------------------------
      |
      | We need to illuminate PHP development, so let us turn on the lights.
      | This bootstraps the framework and gets it ready for use, then it
      | will load up this application so that we can run it and send
      | the responses back to the browser and delight our users.
      |
      */
      
      $app = require_once __DIR__.'/laravel/bootstrap/app.php';
      

      Configuration Index On Laravel 5

    • paths.php
      'public' => __DIR__.'/../..',

Done, now you can access the application without /public behind.

Best Way Eliminate Public Folder In The URL Laravel 5

Ref : http://id-laravel.com/post/menghilangkan-folder-public-di-url-pada-aplikasi-laravel/

Thus article about Best Way Eliminate Public Folder in the URL Laravel 5 , hope useful

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: