欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 幼教 > 快速更改WampServer根目录php脚本

快速更改WampServer根目录php脚本

2025/9/19 8:47:51 来源:https://blog.csdn.net/weixin_59166557/article/details/145358831  浏览:    关键词:快速更改WampServer根目录php脚本

快速更改WampServer根目录php脚本

<?php
// 配置文件地址
$apacheConfPath = 'C:\Install\CTF\Wampserver\bin\apache\apache2.4.62.1\conf\httpd.conf';
$apacheConfPath2 = 'C:\Install\CTF\Wampserver\bin\apache\apache2.4.62.1\conf\extra\httpd-vhosts.conf';
// 新根目录地址
$newDocumentRoot = 'G:\Notes_and_Dictionary\book\CTF-codes\php-code-all-in-there\run_www';// step 1
function change_set($apacheConfPath, $newDocumentRoot)
{$config = file_get_contents($apacheConfPath);if ($config === false) {die("无法读取配置文件: $apacheConfPath\n");}// 修改 DocumentRoot$patternDocRoot = '/^\s*DocumentRoot\s+"[^"]+"/m';$replacementDocRoot = 'DocumentRoot "' . $newDocumentRoot . '"';$config = preg_replace($patternDocRoot, $replacementDocRoot, $config, 1, $countDocRoot);if ($countDocRoot === 0) {die("未找到 DocumentRoot 指令。\n");}// 更改 <Directory$patternDocRoot = '/<Directory\s+"[^"]+">/m';$replacementDocRoot = '<Directory "' . $newDocumentRoot . '">';$config = preg_replace($patternDocRoot, $replacementDocRoot, $config, 1, $countDocRoot);if ($countDocRoot === 0) {die("未找到 <Directory 。\n");}// 保存修改后的配置文件if (file_put_contents($apacheConfPath, $config) === false) {die("无法写入修改后的配置文件: $apacheConfPath\n");}
}
// step 2
change_set($apacheConfPath, $newDocumentRoot);
change_set($apacheConfPath2, $newDocumentRoot);
echo "更改成功,请重启服务";

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词