Place Laravel on Default Level / Directory [duplicate]

Posted on

Question :

I have a Laravel application and I deploy it via git to my server. But the problem is that the server always throws the deploy into the public folder , and Laravel originally is meant to stay up .

.htaccess or Laravel itself for example …


Answer :

There is a way to resolve this by .htaccess and laravel . And an extra gambiarra that I’ll teach you (maybe it’s the easiest way).


A of htaccess consists of writing the following code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1


You will have to move the file public/index.php to the root, or just ./index.php .


 //index.php (agora fora da pasta public)

 //require_once __DIR__ . '/../bootstrap/start.php'

 require_once __DIR__ . '/bootstrap/start.php'

After that, you’ll have to change the way index.php and bootstrap/paths.php files are being used by the require function (you’ll have to get the /../ string at the beginning).

Gambiarra Extra (Powered By Wallace)

You can simply create a index.php file in the root and include the file that is within public/index.php .

As follows:


require __DIR__ .  '/public/index.php';

Of the three methods, I would recommend htaccess .


Leave a Reply

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