Create an environment variable for users without access to bash (/ sbin / nologin)?

2

I'm trying to create an environment variable that will be accessed by a php script by the user running httpd (user: apache). It is defined as /sbin/nologin and therefore does not access .profile , profile , .bashrc , etc ...

I assume that this variable has to be loaded globally by the OS (something like HOSTNAME ). But I can not. This variable is a string in json format that contains the data for connecting to databases, access credentials, and so on. I do not know if this is the safest way to do this, but intuitively I think so. See an ex:

linux environment:

MY_VAR_DATA='{"driver":"mysql","host":"ip_host_remoto","user":"nome_do_usuario","password":"senha_do_usuario"}'  
export MY_VAR_DATA

in php:

$connData = json_decode(getenv('MY_VAR_DATA'), true);

If anyone can help me, I'm grateful.

    
asked by anonymous 12.11.2017 / 17:30

1 answer

0

Personally the solution I found was to put the variables in the / etc / sysconfig / httpd file, but if you use the phpinfo () function list these variables in the Environment section and that we do not want. So I made a change in /etc/php.ini by disabling calls to this function through the directive 'disable_functions = phpinfo In newer versions of apache, from 2.4.24 you should edit httpd.service with the following command:

# systemctl edit httpd

Inside the editor you put the following lines:

[Service]
EnvironmentFile=/etc/sysconfig/httpd

This will cause apache to load the variables defined in / etc / sysconfig / httpd, since in newer versions this is not done anymore. If you directly edit the httpd.service file after each apache update this file will be overwritten by having to change the file again. The above solution is permanent.

    
20.11.2017 / 14:13