Changing public folder on Laravel 8

I’ve just started (re)learning Laravel, now on this version 8, and working with a Apache Server (Xampp) that runs lots of other web applications (a server machine that run some essential internal services and APIs) and was thinking if it was possible to just put the public folder on the htdocs, so it’s accessible, and the application outside of it.

I’ve been using CodeIgniter 4.1.1 lately and was a tricky part to learn but now is rather simple to do, just changing one or two references inside the index.php code and it’s done, how would it be done on Laravel 8?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you want to bring public folder out of the project than you need to change the dir path inthe index.php file:

from

   require __DIR__.'/../vendor/autoload.php';
   $app = require_once __DIR__.'/../bootstrap/app.php';

to

require __DIR__.'/vendor/autoload.php';
   $app = require_once __DIR__.'/bootstrap/app.php';

Method 2

If you want to remove public from your app URL then you place your index.php and .htaccess to the root folder and The following change in index.php

from

  require __DIR__.'/../vendor/autoload.php';
  $app = require_once __DIR__.'/../bootstrap/app.php';

to

require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x