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

更多推荐