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

Asked

Viewed 252 times

2

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

I believe this variable must be carried globally by the OS (something like HOSTNAME). But I’m not getting it. This variable is a json format string that contains the data for connection to databases, access credentials, etc. I don’t 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’d be grateful.

  • Only include variable declaration in apache start script, then it already goes up declaring variable (/etc/init.d/apache is the first place that comes to mind, but in systemd times will know where it can be). That being said, if you need to change any information on that data you will also have to restart apache (even if he had one . profile that would be true), so why not declare right inside PHP?

1 answer

0

Personal the solution I found was to put the variables in the file /etc/sysconfig/httpd, but if you use the phpinfo() function list these variables in the Environment section and we don’t want that. So I made a change to /etc/php.ini by disabling the calls to this function via the `disable_functions = phpinfo directive In newer versions of apache, as of 2.4.24 you must edit httpd.service with the following command:

# systemctl edit httpd

Inside the editor you place the following lines:

[Service]
EnvironmentFile=/etc/sysconfig/httpd

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.