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-fpmcontainer_name: phpvolumes:#ntunnel_sqlite.php文件所在基礎路徑掛載- /var/www/html/:/var/www/html# db文件所在基本路徑掛載- /iothub/iothub-manage/db/:/var/www/html/dbnetworks:- app-networknginx:image: nginx:latestcontainer_name: nginxports:- "80:80"volumes:- /var/www/html/:/var/www/html#nginx配置文件- ./nginx/nginx.conf:/etc/nginx/conf.d/default.confdepends_on:- phpnetworks:- app-networknetworks: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.phprewrite ^/sqlite/(.*)$ /sqlite/ntunnel_sqlite.php last;# 處理 PHPlocation ~ \.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容器中的全路徑