1、SQLlite数据库是一个本地.db文件,默认不支持远程连接;
2、Navicat 可以通过ntunnel_sqlite.php文件连接远程SQLlite库;
3、安装Navicat,安装完成,在安装目录下找到ntunnel_sqlite.php文件;
4、上传当前文件到远程服务器;
赋权 chmod +644 ntunnel_sqlite.php
5、生成docker-compose文件
version: '3.8'
services:
php:
image: php:7.4-fpm
container_name: php
volumes:
#ntunnel_sqlite.php文件所在基础路径挂载
- /var/www/html/:/var/www/html
# db文件所在基本路径挂载
- /iothub/iothub-manage/db/:/var/www/html/db
networks:
- app-network
nginx:
image: nginx:latest
container_name: nginx
ports:
- "80:80"
volumes:
- /var/www/html/:/var/www/html
#nginx配置文件
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
networks:
- app-network
networks:
app-network:
driver: bridge
server {
listen 80;
server_name localhost;
#根路径
root /var/www/html;
index index.html;
# 默认访问:_h5ai 主页
location / {
index index.html;
}
# 专门处理 /sqlite/ 路径下的 PHP 请求
location /sqlite/ {
# 重写路径,让所有 /sqlite/xxx 请求都指向 ntunnel_sqlite.php
rewrite ^/sqlite/(.*)$ /sqlite/ntunnel_sqlite.php last;
# 处理 PHP
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
}
6、启动对应的docker-compose文件【docker-compose -f docker-compose.yml】
登录容器,查看文件挂载是否成功
7、访问文件,nginx配置的是80端口
http://172.26.10.93/sqlite/ntunnel_sqlite.php
填充对应的db文件(php容器里面的数据库文件全路径),验证是否可以正常连接
8、Navicat配置,隧道网址就是远程连接的PHP路径
用户名密码如果没有可以不填,数据库文件为php容器中的全路径