Score:0

I cannot get environment variable from apache

ma flag

On a Centos 8, I added a SetEnv into my VirtualHost conf:

<VirtualHost *:XXXX>
    Alias /static/ /opt/industrialisation/xxxx/xxxx/xxxx/
    <Directory /opt/industrialisation/xxx/xxxx/>
        Require all granted
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    WSGIDaemonProcess myproject python-home=/opt/venv/venv-xxxxx python-path=/opt/industrialisation/xxxx/xxxxx/
    WSGIProcessGroup myproject
    WSGIScriptAlias / /opt/industrialisation/xxxx/xxxx/xxxxx/wsgi.py
    SetEnv VARIABLE_NAME variable_value
</VirtualHost>

I stop and start httpd service :

[root@xxxxx ~]# systemctl stop httpd.service
[root@xxxxx ~]# systemctl start httpd.service

The service is running well :

[root@xxxxxxx ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           └─php-fpm.conf
   Active: active (running) since Mon 2023-03-06 21:57:56 CET; 5min ago
     Docs: man:httpd.service(8)
 Main PID: 49075 (httpd)
   Status: "Total requests: 1; Idle/Busy workers 100/0;Requests/sec: 0.00313; Bytes served/sec:  19 B/sec"
    Tasks: 231 (limit: 22084)
   Memory: 43.4M
   CGroup: /system.slice/httpd.service
           ├─49075 /usr/sbin/httpd -DFOREGROUND
           ├─49076 /usr/sbin/httpd -DFOREGROUND
           ├─49077 /usr/sbin/httpd -DFOREGROUND
           ├─49078 /usr/sbin/httpd -DFOREGROUND
           ├─49079 /usr/sbin/httpd -DFOREGROUND
           └─49080 /usr/sbin/httpd -DFOREGROUND

mars 06 21:57:56 xxxxxxx.xxxxxxx.net systemd[1]: Starting The Apache HTTP Server...
mars 06 21:57:56 xxxxxxx.xxxxxxx.net systemd[1]: Started The Apache HTTP Server.
mars 06 21:57:56 xxxxxxx.xxxxxxx.net httpd[49075]: Server configured, listening on: port xxx, port xxxx, port xxxx

I check if the variable is available but it is not :

[root@xxxxxxx ~]# cat /proc/49075/environ | tr '\0' '\n'
LANG=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
NOTIFY_SOCKET=/run/systemd/notify
INVOCATION_ID=a3e117c7287b445b9b9932f7ec8883b1
JOURNAL_STREAM=9:220753

Also I thought that system variable (like HOSTNAME) would be available to the process httpd but I only see these 5 variables.

Is it normal? Is it a problem with my check from proc? I'm confused.

ezra-s avatar
ru flag
SetEnv sets variable for Apache own use, SetEnv does not set system variables. All you can do with system variables is preload them before running httpd and invoke them in your httpd config, not the other way around. The httpd docs specify it clearly. [mod_env](https://httpd.apache.org/docs/2.4/mod/mod_env.html) "This module allows for control of internal environment variables that are used by various Apache HTTP Server modules"
Pozinux avatar
ma flag
Thanks so much for your answer.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.