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容器添加路径挂载,并一定要挂载到工作目录下

相关推荐
专业程序开发源4 分钟前
springboot外卖系统94294-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·spring·php·课程设计
吴声子夜歌7 分钟前
Nginx应用与运维——Nginx在Kubernetes中的应用(二)
运维·nginx·kubernetes
Ruiery9 小时前
Linux 6.6内核 CPU 深度解析(七):调度器启动 — 从单核到多核,调度器分阶段点亮
linux·运维·服务器
50万马克的面包9 小时前
CSDN-栈队列数组-知识点整理
linux·运维·服务器
MicrosoftCloud10 小时前
用户权限 04|/etc/sudoers 安全配置:从最小授权到「别把 ALL 随便给人」
运维·安全·ubuntu·sudo·sudoers
꯭自꯭闭꯭11 小时前
达梦事物特性及MVCC
linux·运维·数据库
郑州光合科技余经理11 小时前
海外版外卖加盟:总站与分站配送规则怎么分开管
java·开发语言·前端·后端·uni-app·php·ai编程
专业程序开发源12 小时前
springboot简历管理系统81389-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·spring·php·课程设计
专业程序开发源12 小时前
springboot社区养老系统44071-计算机课程设计、毕业设计
vue.js·spring boot·后端·python·django·php·课程设计
亚川楼宇自控系统数据中心厂家12 小时前
实验室智能化管理系统|人环物智一体化管控平台
运维