Sunday, 15 August 2010

linux - Ubuntu: How PHP can read Environment Variable -


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:

  1. 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 ! 

  2. Save the file and exit.

  3. Click on the following command:

      source ~ / .bashrc  
  4. Check that the Environment variable is valid

      $ DB_NAME echo  

    should print it:

      My database Name  
  5. Edit your PHP file:

    & lt ;? Php $ db = getenv ('DB_NAME'); // Name of database resonance "database name: $ db \ r \ n"? & Gt;
  6. Run the PHP file

      php test.php  

    should print it

      Database Name: My Database Name  

No comments:

Post a Comment