开发者

How to Parse Apache config file, PHP config, FTP Server config

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 开发者_StackOverflow社区and web account (with domain). If you have done it before - how did you do it?

It would be quite challenging to learn

Thanks.


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.


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


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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜