1panel - 网站结合php运行时环境 - openresty、php双容器如何挂载宿主机目录

添加带php运行时环境的站点

在站点下添加php文件

php 复制代码
<?php
header('Content-Type: text/plain; charset=utf-8');

// 非工作目录下的文件访问不了
$file = '/www/sites/sqlite.remote.php/log/access.log'; // exists = false

// 工作目录下的文件可以访问
$file = '/www/sites/sqlite.remote.php/index/404.html'; // exists = true
$file = '/www/sites/sqlite.remote.php/index/db/task.db'; // exists = true
$file = 'db/task.db'; // exists = true

$info = [
    'file'      => $file,
    'exists'    => file_exists($file),
    'is_file'   => is_file($file),
    'readable'  => is_readable($file),
    'writable'  => is_writable($file),
    'real_path' => realpath($file) ?: '文件不存在',
];

foreach ($info as $k => $v) {
    if (is_bool($v)) {
        $v = $v ? 'true' : 'false';
    }
    echo "$k: $v\n";
}

echo "当前工作目录: " . getcwd() . PHP_EOL;
echo "当前脚本目录: " . __DIR__ . PHP_EOL;

?>

访问php文件

http://192.168.20.108:40202/print-test.php

php挂载宿主机目录

当前工作目录是php容器的目录,宿主机上的文件要通过php容器添加路径挂载,并一定要挂载到工作目录下

相关推荐
tedcloud1231 小时前
OpenShip 部署指南:开源 AI 应用快速启动模板 Linux 搭建实践
linux·运维·服务器·人工智能·开源
大翻哥哥1 小时前
轻量级PHP网页在线客服系统 隐私聊天—— 可定制
开发语言·php
晚风吹长发10 小时前
Docker基础——Docker Network(网络详解)
linux·运维·网络·ubuntu·docker·容器
LedgerNinja12 小时前
WEEX API 自动化交易实践:下单、撤单、订单查询与状态闭环
运维·自动化
摩西蒙12 小时前
计算机网络
开发语言·计算机网络·php
执笔画流年呀12 小时前
Linux搭建Java项目部署环境
java·linux·运维
Dory_Youth13 小时前
联想笔记本电脑失灵
运维·笔记·电脑
W.W.H.13 小时前
嵌入式 Linux外接USB/WIFI模块兼容5G频段实战
linux·运维·5g·wifi
运维大师13 小时前
【K8S 运维实战】24-资源优化HPA与VPA
运维·kubernetes·github
GlobalHRTalk13 小时前
埃及名义雇主EOR业务概述与市场发展优势分析
大数据·运维·人工智能