简体   繁体   中英

Is it possible to install lumen or laravel only in a sub directory

I have an existing website\\application. I want to create a JSON API using lumen in a sub directory–something like /api/ .

How do you install lumen or laravel only in a sub directory of a website?

Try using Alias in your apache conf (virtualhost):

Alias /api /path/to/api/public
<Directory /path/to/api/public>
    Allowoverride All 
    Options Indexes FollowSymLinks Includes
    Order allow,deny
    Allow from all
</Directory>

Also, because Lumen gets the wrong path when used from a sub directory you will need to change the following line in Lumens public/index.php: from $app->run(); to $app->run($app->make('request'));

redirect request with ".htaccess" (if you cannot modify apache conf):

RewriteRule ^api/(.*)$ /api/public/$1 [L]

use a Group with a prefix in your app/Http/router.php to remove the subfolder:

$app->group(['prefix' => 'api'], function () use ($app) {
  $app->get('/', function () use ($app) {
      return $app->version();
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM