如何解析 Apache 配置文件、PHP 配置、FTP 服务器配置
我刚刚购买了 VPS 帐户用于测试和开发。
PHP 是否有解析 Apache 配置文件、PHP 配置、FTP 服务器配置、区域文件等的功能?也是一种将数据插入配置文件的方法。
我想创建一个简单的控制面板来添加 ftp 帐户和 Web 帐户(带域)。如果你以前做过——你是怎么做到的?
学习起来会很有挑战性,
谢谢。
I've just bough VPS account for testing and development.
Is there a function of PHP to parse Apache config file, PHP config, FTP Server config, zone files, etc? Also a way to insert data into config file.
I want to create a simple Control Panel to add ftp accounts and web account (with domain). If you have done it before - how did you do it?
It would be quite challenging to learn
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,PHP 没有解析这些程序的配置文件的函数 - 您必须为大多数这些格式编写自定义解析器。但是,对于 php.ini,您也许可以使用 PHP 的 ini 函数。
大多数虚拟主机控制面板要么根据他们的数据库创建整个配置文件 - 即他们从不读取它,而只是(覆盖)写入它,或者他们要求您包含(apache 和绑定支持,例如,对于 PHP,您可以在apache virtualhosts)它们生成的文件 - 该工具也永远不会读取该文件。
如果您确实想创建一个实际修改现有文件的工具,请不要忘记您不能简单地跳过注释,因为没有人会希望应用程序重写其配置文件并删除所有注释。
No, PHP has no functions to parse the config files of those programs - you'll have to write a custom parser for most of those formats. However, for php.ini you might be able to use PHP's ini functions.
Most webhosting control panels either create the whole config file based on their database - i.e. they never read it but only (over)write it or they require you to include (apache and bind support that for example, for PHP you can use php_admin_value in the apache virtualhosts) their generated file - which is also never read by the tool.
If you really want to create a tool that actually modifies existing files, don't forget that you cannot simply skip comments as nobody would want an application to rewrite his config file stripping all comments.
您可以使用以下 pear 库来解析 apache 配置文件:
http://pear.php.net/manual/en/package.configuration.config.avail-container.apache.php
解析 php.ini 文件,具体取决于您想要执行的操作,可能是最好用 ini_get 完成
You may be able to use the follow pear library to parse apache config files:
http://pear.php.net/manual/en/package.configuration.config.avail-container.apache.php
Parsing a php.ini file, depending on what you want to do, is probably best done with ini_get
我不知道这些功能,并且我非常怀疑它们的存在,原因很简单,因为有太多的 HTTP / FTP / SMTP / ... 服务器实现。 cPanel、WebMin 和其他等控制面板通常会为您完成繁重的工作,有些甚至提供 API通过 PHP 实现自动化。
对于 PHP 配置,以下函数可能可以解决问题:
ini_get()
ini_set()
< /一>ini_get_all()
get_cfg_var()
但请记住,并非所有 PHP配置指令可以更改为
ini_set()
。I'm not aware of such functions and I highly doubt they exist for the simple reason that there are just too many HTTP / FTP / SMTP / ... server implementations. Control panels like cPanel, WebMin and others usually do the heavy lifting for you and some even provide an API to automatize things from PHP.
For the PHP configuration the following functions will probably do the trick:
ini_get()
ini_set()
ini_get_all()
get_cfg_var()
Bare in mind however that not all PHP configuration directives can be changed with
ini_set()
.