Search code examples
apacheenvironment

Cannot set Environment Variables - Apache 2.4.57 AlmaLinux


I have some issues to set the LANG environment variable to my apache webserver.

When I print out the configuration (using php_info()) at my php-File I get the following entries (for environment):

enter image description here

Regarding the fact, that it should already been set on the default service settings (/usr/lib/systemd/system/httpd.service):

# See httpd.service(8) for more information on using the httpd service.

# Modifying this file in-place is not recommended, because changes
# will be overwritten during package upgrades.  To customize the
# behaviour, run "systemctl edit httpd" to create an override unit.

# For example, to pass additional options (such as -D definitions) to
# the httpd binary at startup, create an override unit (as is done by
# systemctl edit) and enter the following:

#       [Service]
#       Environment=OPTIONS=-DMY_DEFINE

[Unit]
Description=The Apache HTTP Server
Wants=httpd-init.service
After=network.target remote-fs.target nss-lookup.target httpd-init.service
Documentation=man:httpd.service(8)

[Service]
Type=notify
Environment=LANG=C  # <-----------------------------------

...

Even when I try to modify enviroment of the service with additional files like /etc/systemd/system/httpd.service.d/xxx.conf:

[Service]
Environment="LANG=C"
#Environment=LANG=C
#Environment=ABC=C
#Environment="DEF=C"
#EnvironmentFile=/etc/sysconfig/httpd

The environment still just contains "USER" and "HOME".

Additional information:

httpd -v
Server version: Apache/2.4.57 (AlmaLinux)
Server built:   Jul 20 2023 00:00:00

ENV Apache Module is loaded:

[root@alma-master ~]# httpd -M
Loaded Modules:
...
env_module (shared)
...

Any ideas? Thanks in advance!


Solution

  • The reason for this behavior was PHP-FPM (which seems to be a default module at recent linux versions) - in older version this module was not installed when I run "yum install php"

    All you have to do - set the parameter "clear_env" (default yes) to no.

    /etc/php-fpm.d/www.conf:

    clear_env = no