Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: How to use ONLY relative path in apache conf files... |
|
Author |
|
jmar83
Joined: 10 Mar 2018 Posts: 16 Location: CH
|
Posted: Fri 07 Jan '22 18:40 Post subject: How to use ONLY relative path in apache conf files... |
|
|
...so i NEVER need to change them when i use another directory than D:\Tools\Apache24...?
https://i.ibb.co/j5dWSVf/apache.jpg
Thank you for your feedback!
With kind regards, Jan |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Fri 07 Jan '22 22:49 Post subject: |
|
|
This challenge has been raised before, and there's no easy answer that I know of.
What you can do is use a DEFINE statement to set the server root directory in a configuration variable, and then reference that throughout the file in directives that need a path. That way you only need to define the path in one place near the top of the configuration, e.g.
Code: | Define SRVROOT D:/Tools/Apache24
ServerRoot "${SRVROOT}"
DocumentRoot "${SRVROOT}/htdocs"
etc |
Additionally, if you want the server root to be defined outside the configuration file, you can pass an OS environment variable to Apache startup (say APACHE_ROOT) using a -D option, which can then be used to define the SRVROOT e.g.
Code: | # Define SRVROOT if APACHE_ROOT defined.
#
<IfDefine APACHE_ROOT>
Define SRVROOT ${APACHE_ROOT}
</IfDefine>
# Define SRVROOT if APACHE_ROOT not defined.
#
<IfDefine !APACHE_ROOT>
Define SRVROOT "D:/Tools/Apache24"
</IfDefine>
ServerRoot "${SRVROOT}"
DocumentRoot "${SRVROOT}/htdocs" |
See post https://www.apachelounge.com/viewtopic.php?t=8611 for more details, including how this technique can be used to pass a location path variable to an Apache Windows service. |
|
Back to top |
|
jmar83
Joined: 10 Mar 2018 Posts: 16 Location: CH
|
Posted: Mon 10 Jan '22 9:51 Post subject: |
|
|
Thank you very much, will look on it!! |
|
Back to top |
|
jmar83
Joined: 10 Mar 2018 Posts: 16 Location: CH
|
Posted: Mon 10 Jan '22 12:45 Post subject: |
|
|
Maybe somebody knows how it is with the PHP entries with absolute paths? Can i do something similar? |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 212 Location: Paris, France, EU
|
Posted: Mon 10 Jan '22 13:08 Post subject: |
|
|
Hi,
In httpd.conf, I use :
Code: | Define VERSION_APACHE 2.4.52
Define INSTALL_DIR E:/wamp64
Define APACHE_DIR ${INSTALL_DIR}/bin/apache/apache${VERSION_APACHE}
Define SRVROOT ${INSTALL_DIR}/bin/apache/apache${VERSION_APACHE}
...
<IfModule fcgid_module>
Define PHPROOT ${INSTALL_DIR}/bin/php/php
...
</IfModule> |
The variables VERSION_APACHE and INSTALL_DIR are automatically filled in when installing an Apache version.
And, for the fcgid mode, in the VirtualHost definitions, I use :
Code: | <IfModule fcgid_module>
Define FCGIPHPVERSION "7.0.33"
FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
<Files ~ "\.php$">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</Files>
</IfModule>
|
|
|
Back to top |
|
jmar83
Joined: 10 Mar 2018 Posts: 16 Location: CH
|
Posted: Mon 10 Jan '22 14:13 Post subject: |
|
|
thx!! |
|
Back to top |
|
|
|
|
|
|