Can I create two app with a single installation of slim?


Hello guys, how are you going ? I hope well!

So i want to ask something…

I have installed my slim 3 and i have coded my api with it for my android app.

And then i want to create a website(app) with a view… Is possible to create another instance of the slim app ?

In the “api/v1” folder, i have my first instance
In the root path, i want to have the second

Possible ?


Yes, absolutely. In fact, I’ve done something similar at work. Configure the app with different settings in your index.php, probably different routes?

I’d show you an example, but I’m responding on my phone. Hopefully that still helps


Yes, different routes…

Ok, Antnee; i can wait you, please show me your example when you will be with your computer…

I’m waiting…


Well I don’t know what your index.php looks like, but if they both look something like this:

use Slim\App;

require_once '../vendor/autoload.php';
$app = new App();

$app->get('/', Your\Apps\IndexAction::class);
$app->get('/foo', Your\Apps\FooAction::class);


Then you just define different routes. We have ours in different files which we include, but the basic idea is the same. The core app is the same thing, but we can use different routes and actions so that the two appear to be different apps, even though it’s the same code base. You may have different dependency resolution, I don’t know… but it’s quite possible, and it’s not terribly difficult.

I can see that you’re using Docker Compose, too. We also do this, and we have one container build that maps the public directory to one app’s index.php, and the other container maps to the other.

Incidentally, now I’m on a larger screen, I notice that you have an index.php in the root of the project. You really ought to have it in a subdirectory so that it’s not possible for someone to request sensitive files. If I were to go to /composer.json on your second app I’d be able to view the contents of the file, for example. You don’t want to do that