thinkphp6:配置多app应用(thinkphp6.0.5 / php 7.4.9)
一,创建两个应用:
我们在演示中创建两个app
web
adm
在app目录下,新建这两个目录
liuhongdi@ku:/data/php/mytp/app$ mkdir web liuhongdi@ku:/data/php/mytp/app$ mkdir adm
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/26/thinkphp6-pei-zhi-duo-app-ying-yong-thinkphp6-5-php-7-4-9/
对应的源码可以访问这里获取: 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