一,創建兩個應用:
我們在演示中創建兩個app
web
adm
在app目錄下,新建這兩個目錄
liuhongdi@ku:/data/php/mytp/app$ mkdir web liuhongdi@ku:/data/php/mytp/app$ mkdir adm
說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,安裝多應用的擴展:
命令:
liuhongdi@ku:/data/php/mytp$ composer require topthink/think-multi-app Using version ^1.0 for topthink/think-multi-app ./composer.json has been updated Running composer update topthink/think-multi-app Loading composer repositories with package information Updating dependencies Lock file operations: 1 install, 0 updates, 0 removals - Locking topthink/think-multi-app (v1.0.14) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Downloading topthink/think-multi-app (v1.0.14) - Installing topthink/think-multi-app (v1.0.14): Extracting archive Generating autoload files > @php think service:discover Succeed! > @php think vendor:publish Succeed! 6 packages you are using are looking for funding. Use the `composer fund` command to find out more!
三,修改配置
liuhongdi@ku:/data/php/mytp/app$ cd ../config/ liuhongdi@ku:/data/php/mytp/config$ vi app.php
修改的內容:
增加一項:
'auto_multi_app' => true,
修改一項:
'default_app' => 'web',
四,創建應用程序
1,把app目錄下默認的controller目錄移到web目錄下:
liuhongdi@ku:/data/php/mytp/app$ mv controller/ web/
2,修改web/controller/Index.php
liuhongdi@ku:/data/php/mytp/app/web$ cd controller/ liuhongdi@ku:/data/php/mytp/app/web/controller$ vi Index.php
修改的內容:
把:
namespace app\controller;
修改為:
namespace app\web\controller;
五,測試效果:
1,訪問:
http://127.0.0.1:81/
返回:
2,訪問:
http://127.0.0.1:81/web/
返回:
3,訪問:
http://127.0.0.1:81/adm
返回:
說明:adm目錄下還沒有創建程序可供訪問
六,附nginx的虛擬站點配置文件:
root@ku:/etc/nginx/sites-enabled# more tp.com server { listen 81; server_name tp.com; access_log /data/logs/nginxlogs/tp.com.access.log; error_log /data/logs/nginxlogs/tp.com.error.log; root /data/php/mytp/public; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?s=$1 last; break; } location / { index index.html index.php; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } }
七,查看thinkphp版本:
liuhongdi@ku:/data/php/mytp$ grep 'const VERSION' vendor/topthink/framework/src/think/App.php const VERSION = '6.0.5';
八,查看php版本
root@ku:/etc/nginx/sites-enabled# php --version PHP 7.4.9 (cli) (built: Oct 26 2020 15:17:14) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies