开发者

Can I set up variables for use in an apache configuration file?

I have a php webapp convention that I'd like to follow and a lot of setup for it is done in the apache configuration file.

Is there any way I can configure some strings that contain paths for multiple uses throughout the configuration file?

A dim example might be:

EnginePath = /opt/engine
AppPath = /opt/anapp

DocumentRoot [AppPath]/Public
CustomLog [AppPath]/Logs/Access.log combined

php_admin_value auto_prepend_file [EnginePath]/EngineBootstrap.php

As you can see, I have lots of opportunities to consolodate开发者_如何学C several repeted occurences of the system and app paths. This would make it easier to keep the configuration files as generic as possible, requiring a change in app or engine location to be edited once. Rather than several times per configuration file.

Thanks for any help!


You can use Define

http://httpd.apache.org/docs/2.4/mod/core.html#define

or mod_macro

https://httpd.apache.org/docs/trunk/en/mod/mod_macro.html


As far as I know, this is not possible in apache configuration files.

However, what may be possible is for you to pre-process your httpd.conf file. I've used this technique with other configuration files, and it should work. For example, if you use php:

Save your httpd.conf.php

<?php
$EnginePath = '/opt/engine';
$AppPath = '/opt/anapp';
?>

DocumentRoot <?php echo $EnginePath; ?>/Public
CustomLog <?php echo $AppPath; ?>/Logs/Access.log combined

php_admin_value auto_prepend_file <?php echo $EnginePath; ?>/EngineBootstrap.php

When you want to change your config, call:

php httpd.conf.php > httpd.conf

This means you have to regenerate your conf file every time you want to make a change, but that can also be automated via some quick shell scripting.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜