Problems setting vhost environment variables in Apache
Hi
I am using WHM/CPanel 124 with Almalinx 9.5 and Apache 2.4.63 and I'm trying to set some environment variables in my apache config for a specific vhost/site.
I have installed mod_env with easyApache and found the obscure location described here:
https://docs.cpanel.net/ea4/apache/modify-apache-virtual-hosts-with-include-files/
However it seems that the /etc/apache2/conf.d/userdata/ssl/2_4/<user>/<domain>/custom_env.conf
I'm creating (had to create all dirs below /etc/apache2/conf.d/userdata/), just isn't being read although I can see there's an include in /home/virtfs/<user>/etc/apache2/conf/httpd.conf that points to /etc/apache2/conf.d/userdata/ssl/2_4/<user>/<domain>/
custom_env.conf just contains a few variables like: SetEnv DB1_PASS 'xxxxxxxx'
I am running:
/usr/local/cpanel/scripts/rebuildhttpdconf
/usr/local/cpanel/scripts/restartsrv_httpd
...after adding the .conf file
Wondering if anyone can help (and why there is not a simpler way to do this) as I am completely stuck here.
-
Hey there! It's important to note that you can't modify or delete anything inside /home/virtfs, so please don't try to edit the files there.
I would expect any file you create ending in ".conf" to be loaded properly in the include system, and unless the default Apache template has been modified there is no way that it won't be read. You'll see the following line at the end of each Apache vhost inside the main /etc/apache2/conf/httpd.conf file:
# To customize this VirtualHost use an include file at the following location
# Include "/etc/apache2/conf.d/userdata/ssl/2_4/username/domain.com/*.conf"
</VirtualHost>It's also worth noting that there is both the SSL and non-SSL vhost, so make sure you editing both just to be consistent and avoid confusion.
I would recommend trying to add something that isn't related to the mod_env system just to see if that takes affect - that would at least narrow down the issue to a problem with the include or with mod_env.
0 -
Thanks cPRex - I am using the SSL vhost exclusively here. Turns out they are getting set I was looking in the environment section when I did a phpinfo.php to check. They are showing up in the PHP variables section as like:
$_SERVER['DB_HOST'] localhost0 -
Great - so things are working as expected?
0 -
Sure are! Sometimes I get frustrated when I find myself spending more time working round CPanel (and it's ilk) because they just don't let me do the things I am used to doing directly (like adding something to the standard vhosts conf)! Alls well that ends well...
0 -
Oh for sure, I get that. I just tell people to remember that those systems are in place because cPanel has to integrate with everything on the machine, so direct edits in the "usual" way don't interact well.
0
Please sign in to leave a comment.
Comments
5 comments