Lumen is a micro-framework based on laravel, lumen has the same foundation as laravel and also has many same components. 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 which need to be faster.

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

Every time when I install lumen or laravel, I modify its directory structure to keep the public directory separate from code, and in this article, We will discuss how we can do that with lumen. so after changing the directory structure our directory structure looks 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 the public directory 1 step back from its location so the structure will become like the above.

Now make some changes in your index.php, which is inside your public folder, correct your bootstrap loader path and bind a 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 you are done with it.