Sometimes we need to deploy multiple PHP programs on a server, and it’s certainly not reasonable to use multiple ThinkPHP frameworks, so we need to deploy multiple applications within a single ThinkPHP.

1、Install Multi-Application Mode

We need to install an extension think-multi-app using the composer command.

1
composer require topthink/think-multi-app

2、Enable Multi-Application

Add the following code to the return in the config/app.php file.

1
'auto_multi_app'   => true,

The comma after this sentence must not be missing.

image-20221228224619020

3、Create Application

First, delete the original app/controller file.

Enter the following command in the terminal

1
php think build [Project Name]

After creation, you can see the project you just created under the app folder, and the project will come with a built-in index.php file containing an Index class.

4、Route Writing

We need to write routes to direct to the applications. The specific rules are as follows:

1
Route::get('rule', 'app\[Project Name]\controller\[Class]@[Function]')

This way, you can access the corresponding application through the corresponding URL.