2

I am using Windows 7 Ultimate, PHP 5.2, VMWare (with Ubuntu Server V11.04)

My plan is to create an environment variable in both the linux and windows platforms, and to make them work in PHP. So I created the variable "ROOT_DIR" in Windows and another "ROOT_DIR" variable in Windows.

I have this code in PHP that I expect to work in both the platforms:

<?php
echo 'My username is ' .$_ENV["ROOT_DIR"] . '!';
?>

But in Linux, all it outputs is NULL. I wonder what I'm doing wrong here. Any help would be appreciated.

10
  • 1
    Have you tried getenv()? Commented Dec 19, 2012 at 6:33
  • 1
    Surely it outputs "My username is" and "!", right? Commented Dec 19, 2012 at 6:33
  • I suspect this not PHP, but Linux/bash question. How did you define the variable? Did you use "export"? Commented Dec 19, 2012 at 6:37
  • I have tried getenv and it also didn't work. Yes I have used "export". Commented Dec 19, 2012 at 6:40
  • How do you run the code? Is it CLI or web script? Commented Dec 19, 2012 at 6:41

1 Answer 1

0

If you are running the script through the browser then try adding the following to your main .htaccess file

SetEnv ROOT_DIR "/path/to/root/"

apache setenv

Sign up to request clarification or add additional context in comments.

5 Comments

seems like I don't have a .htaccess file inside the /var/www folder. Can I just create one?
This worked. But I had to use _SERVER instead of _ENV. Or maybe I could edit my windows' htaccess so i can use _SERVER in windows as well. Where is the htaccess in Windows?
You can create a new one and place it in your root directory.
i did but it didn't work. Is there any file I should edit so that .htaccess would work?
Try adding an invalid command/text/code to the .htaccess and see if the server will be affected (by responding with with code 500). This is a way to tell that the .htaccess is actually read by the server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.