Apache与php快速部署web服务

[本文出自天外归云的博客园]

在一台服务器上临时起个web服务,读取服务器上的cfs文件内容并显示在页面上,做一个简单的web请求处理。

首先找到apache,在conf文件夹下vi httpd.conf,然后/DocumentRoot,快速查找DocumentRoot的位置:

然后在这个位置创建一个index.php文件,就可以处理web请求了。内容例如:

<html>
<?php
$path = $_GET["path"];
$dir = "/cfs";
$file_path = $dir.$path;
if (file_exists($file_path))
{
    $file_handle = fopen($file_path, "r");
    while (!feof($file_handle)) {
        $line = fgets($file_handle);
        echo $line;
        echo '</br>';
    }
    close($file_handle);
} else {
    echo "File ".$file_path." not found.";
}
?>
</html>

在conf文件夹下vi httpd.conf可以查到服务监听的ip和端口号,然后通过访问http://ip:port就可以访问服务了。如上例就是访问:http://ip:port/?path=xxxxx/xx/xxx/xx

 

posted @ 2019-04-09 16:33  天外归云  阅读(1149)  评论(0编辑  收藏  举报