I am running on Ubuntu Server 14.04.
I have a PHP file that is required to be read
If you Run a PHP file on the Ubuntu server (like test.php) and you need to read and use an environment variable, you need to do the following:
-
edit Bashrc file (if you run bash as a shell)
# Export to the following: Export DB_NAME = "My database name "
Important Do not forget the word export ! -
Save the file and exit.
-
Click on the following command:
source ~ / .bashrc
-
Check that the Environment variable is valid
$ DB_NAME echo
should print it:
My database Name
-
Edit your PHP file:
& lt ;? Php $ db = getenv ('DB_NAME'); // Name of database resonance "database name: $ db \ r \ n"? & Gt;
-
Run the PHP file
php test.php
should print it
Database Name: My Database Name
No comments:
Post a Comment