简体   繁体   中英

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. I am using SetEnv inside of the VirtualHost directive in httpd.conf. So in httpd.conf, I have:

<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. I am always sure to restart httpd after changes. 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. I don't know if it matters, but the server is accessed by secure 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. I am new to all this web development, so I just figured EVERYTHING went into the httpd.conf file when it came to Apache. 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. In this config, there was a VirtualHost setup listening to 443. I put my environmental variables in there and, voila, it worked!

Thanks for the suggestions!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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