Change the public path of lumen

Udit Rawat
DrupalJournal
Published in
2 min readAug 15, 2018

Lumen is micro-framework based on laravel, lumen have same foundation as laravel and also have many same component. But it is faster and leaner than the full application. Of course, i used Laravel for my major project but prefer lumen and slim framework for my api project that need to be faster.

Most of coding style is same as laravel and we can also use other laravel and available packages from package list with it.

Every time when i install lumen or laravel, I modify it’s directory structure to keep public directory separate from code, and in this article i will discuss how we can do that with lumen. so after changing directory structure our directory structure look like something below.

<?php 
/**
* --api
* --public
**/
// api directory will contain all our code
// public directory will contain all our public stuff

We hardly need to make any changes in .htaccess for it. ( Until you have some special kind of changes ). The very first thing you need to do is move public directory 1 step back from it’s location so the structure will became like above.

Now make some changes in your index.php, that is inside your public folder, correct your bootstrap loader path and bind new public path to your app like below.

<?php/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/../api/bootstrap/app.php';/*
* Bind new public path
*/
$app->bind('path.public', function() {
return __DIR__;
});
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$app->run();

Now point your host to public directory and your are done with it.

--

--

Udit Rawat
DrupalJournal

Full Stack Developer, Passionate about innovations in coding and mobile applications. [https://drupaljournal.com/]