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

相关推荐
BingoGo2 小时前
PHP 泛型之殇 泛型 RFC 提案被拒绝
后端·php
JaguarJack2 小时前
PHP 泛型之殇 泛型 RFC 提案被拒绝
后端·php
用户30745969820721 小时前
PHP 扩展——从入门到理解
php
鹏仔先生2 天前
拷贝漫画APP下载页PHP程序,后台带免费AI写作
php
大树882 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠2 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质2 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
Inhand陈工2 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信
酣大智2 天前
ARP代理--工作原理
运维·网络·arp·arp代理
云水一下2 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php