Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to add /usr/local/texlive/2012/bin/x86_64-linux to the PATH environment for my Apache user (www-data) after installing TeX Live 2012 manually.

I edited my /etc/environment

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/texlive/2012/bin/x86_64-linux"

to include this path within my system-wide PATH environment variable for all users.

However, if I execute sudo -u www-data printenv PATH I'm only getting:

# sudo -u www-data printenv PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I can't understand the source of this issue and appreciate any help.

share|improve this question

3 Answers 3

I had a similar problem where I needed a specific export for www-data to use when running PHP exec command and managed to cobble together this solution:

  • Edit /etc/apache2/envvars:

    sudo nano /etc/apache2/envvars
    
    • Add your export to the end of the file and save it.

      export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/texlive/2012/bin/x86_64-linux"
      
    • Restart Apache:

      sudo service apache2 restart
      

Now if you execute the following PHP

<?php
    $descriptorspec = array(
       0 => array("pipe", "r"),  // stdin
       1 => array("pipe", "w"),  // stdout
       2 => array("pipe", "w"),  // stderr
    );
    $process = proc_open('env', $descriptorspec, $pipes, dirname(__FILE__), null);
    $stdout = stream_get_contents($pipes[1]);
    fclose($pipes[1]);
    var_dump($stdout);
?>

You should see your environmental path as set in the file. It seems that apache spawns commands under www-data using the contents of that config file only and not from and of the bash.bashrc etc type files? I Can't say for certain because I'm new to Linux.

Not sure if this is exactly what you are trying to achieve but hope it helps.

share|improve this answer
    
On Ubuntu 12.04 with Apache 2.2.22 /etc/init.d/apache2 has the following: ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin" if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR" fi if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS" fi This overrides anything in /etc/environment and suggests that /etc/apache2/envvars is the best place to add/edit vars required globally for apache. You can set environment vars locally within a VirtualHost config using SetEnv. –  George Feb 3 at 14:00
    
It's also worth noting that it looks like it's only LANG and PATH that are set in this way, so any other vars added to /etc/environment are included just fine. –  George Feb 3 at 14:01

Your /etc/environment doesn't need the export statement in front of the key/value pairs. As stated in the wiki:

It is not a script file, but rather consists of assignment expressions, one per line.

See this other question on how the format works.

share|improve this answer
    
I know, I tried both variants, but none of them worked out. In my case it was sufficient to add the additional path to /etc/apache2/envvars. However, a sudo -u www-data printenv PATH still does not recognize the additional path using /etc/environmnent, so the original question is no solved. –  DigNative Jan 13 '13 at 9:31

https://help.ubuntu.com/community/EnvironmentVariables under "System-wide environment variables" first note will answer your question.

share|improve this answer
    
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  fossfreedom Jan 12 '13 at 23:53
    
I don't know what's the difference in this note to the things I did previously. Note 1 states, that /etc/environment needs to be edited --- but that's what I did (both with export statement and without). So is answer is no solution to my question (or at least something essential is missing). –  DigNative Jan 13 '13 at 9:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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