撰写Apache环境变量和PHP脚本阅读 [英] Write apache environment variables and read them in php script

查看:137
本文介绍了撰写Apache环境变量和PHP脚本阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一些脚本使MySQL请求的index.php文件。由于明显的安全考虑,我想从这个脚本删除mysql的凭据(主机,密码,用户,数据库),并与一些Apache的环境变量替换它们。

I have an index.php file that is running some script making mysql requests. For obvious security reason, i'd like to remove the mysql credentials (host, password, user, database) from this script and replace them with some apache environment variables.

我试图创建这些变量在/ etc / apache2的/ envvars中使用code的下面一行:出口MYSQL_USER ='my_user'然后我打算让回来使用GETENV PHP函数是这样的: GETENV('MYSQL_USER')但这没有返回值

I tried to create such variables in /etc/apache2/envvars using following line of code : export MYSQL_USER='my_user' and then I intend to get it back using getEnv php function like this : getenv('MYSQL_USER') but this returns nothing.

你知道吗?谢谢!

推荐答案

四个步骤:


  • 在/ etc / apache2的/ envvars中:出口MYVAR ='值'

  • 在/etc/apache2/apache2.conf中: PassEnv MYVAR

  • 重新启动Apache

  • 在位于任何地方的Apache2运行PHP文件:回声$ _ SERVER ['MYVAR'];

  • in /etc/apache2/envvars : export MYVAR='value'
  • in /etc/apache2/apache2.conf : PassEnv MYVAR
  • Restart apache
  • in the php file located wherever apache2 is running: echo $_SERVER['MYVAR'];

这篇关于撰写Apache环境变量和PHP脚本阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆