Search code examples
lumen

How to change the Public directory path in Lumen?


By default Lumen "same as Laravel" has myApp/public directory to put all the public files (assets).

I want to change that directory path from myApp/public to myApp/src/custom/public. How can I do achieve this?


Solution

  • Got the same problem, and solved it. Look here, maybe it will help you. I have done this solution for my Lumen application, which works for me.

    UPDATE

    Ok, let's go proceeding some changes to make the system to work with your tree.

    1. Add a .htaccess file in the root of your application so in the directory myApp\. Write it in :

      RewriteEngine On
      
      RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
      RewriteRule ^ %1 [L,NE,R=302]
      RewriteRule ^((?!public/).*)$ src/custom/public/$1 [L,NC]
      

    Assuming that you have configured your vhost pointing to \Path\myApp, we now accede to the index file of myApp\src\custom\public\. If we didn't make any mistakes, then we should get to a page that indicates an error, telling us that the bootstrap/app.php file is not found. Logic.

    1. We must therefore change the index.php file in the directory myApp\src\custom\public :

      Change from this :

      $app = require __DIR__.'/../bootstrap/app.php';
      

      To this :

      $app = require __DIR__.'/../../../bootstrap/app.php';
      

    You can now get your home page directly from the path wanted.