简体   繁体   English

无法在 Apache 中设置环境变量

[英]Unable To Set Environmental Variables in Apache

I am trying to set environmental variables in Apache for a little added security, and access them with PHP.我正在尝试在 Apache 中设置环境变量以增加一点安全性,并使用 PHP 访问它们。 I am using SetEnv inside of the VirtualHost directive in httpd.conf.我在 httpd.conf 的 VirtualHost 指令中使用 SetEnv。 So in httpd.conf, I have:所以在 httpd.conf 中,我有:

<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName "website.com"
    ServerAlias "www.website.com"
    SetEnv myDatabaseServer myserver.rds.amazonaws.com
    SetEnv myPort 3306
    SetEnv myUsername Username
    SetEnv myPassowrd Password
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =website.com [OR]
    RewriteCond %{SERVER_NAME} =www.website.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Using a phpinfo() file, I am seeing none of my environmental variables listed, and I cannot access them in PHP using getenv either, so I am assuming that they are never even getting there.使用 phpinfo() 文件,我没有看到列出的任何环境变量,我也无法使用 getenv 在 PHP 中访问它们,所以我假设它们甚至永远不会到达那里。 I am always sure to restart httpd after changes.我总是确定在更改后重新启动 httpd。 I know I must be missing something small, but I rarely have to dig into config files, so I am hoping somebody can give me some insight or suggestions.我知道我一定遗漏了一些小东西,但我很少需要深入研究配置文件,所以我希望有人能给我一些见解或建议。 This is an AWS server.这是一个 AWS 服务器。 I don't know if it matters, but the server is accessed by secure https.我不知道这是否重要,但服务器是通过安全 https 访问的。 Thanks for any help!谢谢你的帮助!

So it turns out that I had set up an auto-renewing SSL certificate when I set up this server.所以事实证明,当我设置这个服务器时,我已经设置了一个自动更新的 SSL 证书。 I am new to all this web development, so I just figured EVERYTHING went into the httpd.conf file when it came to Apache.我对所有这些 web 开发都是新手,所以我只是认为 Apache 的所有内容都进入了 httpd.conf 文件。 Boy was I wrong.男孩是我错了。 When I created this certificate, about a dozen other config files were set up.当我创建这个证书时,大约设置了十几个其他配置文件。 I went through them one by one and eventually found one named httpd-le-ssl.conf.我一一浏览,最终找到了一个名为 httpd-le-ssl.conf 的文件。 In this config, there was a VirtualHost setup listening to 443. I put my environmental variables in there and, voila, it worked!在这个配置中,有一个监听 443 的 VirtualHost 设置。我把我的环境变量放在那里,瞧,它起作用了!

Thanks for the suggestions!感谢您的建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM