I am trying to setup up my enviroment variable in my Ubuntu machine. Now i did some research and tryed the method on this question Set environment variable in Ubuntu

Similar question but the thing is I already wrote up the "etc/enviroment" the "etc/profile" and the "etc/bash.bashrc" file to include my variables:

export JAVA_HOME
export BASEDIR

However the problem is when i run the startup.sh on apache it still says that the BASEDIR enviroment variable is not setup right and for all I know the JAVA_HOME may not be correct as well. I am using the latest Ubuntu not sure if that a problem or not or if i have to go another way around it. Any help would be appreciated.

  • 1
    You might want to provide some context for this. How do you run it? Where do you run it from? Are the environment variables set in startup.sh? What shell runs startup.sh? – Karlson Oct 16 '12 at 14:37
  • Did you also forget to include a link to another question? – phunehehe Oct 16 '12 at 15:52
  • @Karlson I am running i have tried setting the variables at the "etc/environment" "etc/profile" and "etc/bash.bashrc" and my local .bashrc never tried a startup.sh dont see that file in the 'etc' folder. – Gilbert V Oct 16 '12 at 19:38

Apache is controlled in Ubuntu by using the Apache init script, at /etc/init.d/apache2. This script is run when you start and stop Apache with commands like:-

> sudo service apache2 [start|stop|restart|graceful|etc...]

If you look in this init script, you'll see that the environment is set and modified here, by first reading environment variables from the file /etc/apache2/envvars. This separate environment is important because the Apache's server process is a seteuid executable, which means that can run with an "effective User ID". On my Ubuntu machine, the Apache processes are run with a user name of 'www-data', even though the root user starts the process. As this is a "system account", it has no default shell or bash environment, and uses none of those files that set your user environment.

So what I think you want to do is put those environment variables in /etc/apache2/envvars.


Apache on Ubuntu has a number of .conf files (in /etc/apache2/ and subdirs) that can also be used to modify the running Apache environment. The configuration files are parsed sequentially, and are all included by the master config file: /etc/apache2/apache2.conf.

In these conf files, you can use SetEnv to modify the environment. Then you will know for sure that the environment is as you want. For example, you can add this to /etc/apache2/httpd.conf:-

 SetEnv JAVA_HOME /home/glv/information/jdk1.6.0_25/
  • What about the JAVA_HOME for all i know it may not be working either. – Gilbert V Oct 16 '12 at 19:39
  • Why do you need it if you can't tell if it's working? I'd just put it into /etc/apache2/envvars, keeping it out of /etc/profile, /etc/environment, etc. If you need it in your user environment, then just have it in ~/.bashrc. To explicitly test what path is being set, I'd write a simple server-side to print the value of these server side variables. There is another way to set Apache environment variables too. I'll add it to my answer... – Alex Leach Oct 16 '12 at 19:54
  • *server-side pre-processed HTML file (e.g .php or .shtml – Alex Leach Oct 16 '12 at 20:05
  • Also on the Ubuntu machine I am using the /etc/apache2/apache2.conf and the /etc/init.d/apache2 doesn't exist the files your describing aren't there at all. and there is no apache2 folder on it – Gilbert V Oct 16 '12 at 20:23
  • Oh, right. If not apache2.conf, the main config file should be called httpd.conf. What version of Apache do you have installed? On my system (Debian kernel with Ubuntu packages), apache2.2-common is the package containing the init scripts and other useful apache-related tools.. – Alex Leach Oct 16 '12 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.