6

I can't add /usr/local/bin to the apache users PATH variable. The user doesn't have a .profile, I can't su to the user, I can't export to the PATH from php using exec and adding

SetEnv PATH /usr/local/bin

To either the http.conf or the .htaccess file doesn't make a difference. I can't find the envvars file to change that but I suspect there's some other problem.

I have restarted apache, and indeed my server.

3
  • Please state what expected behavior you would like to observe and what behavior you instead observe. Then, why do you assume that /usr/local/bin isn't part of the $PATH and why do you want to add it? Commented Jan 13, 2014 at 12:28
  • It's not part of the path because when I echo it out from php, it shows /sbin:/bin:/usr/sbin:/usr/bin I want to add it to it to execute commands using exec. I would like to see any kind of change, and I can go from there. Commented Jan 13, 2014 at 13:17
  • Also, the path for normal users is different: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin So it is specific to the apache user. I need to be able to call an application that uses other application, it wouldn't be feasible to edit the source to directly point to each one. Commented Jan 13, 2014 at 13:25

2 Answers 2

7

Ended up following what Alfe suggested in his answer, except rather than in the /etc/init.d/httpd file (which could be overwritten easily on update) I added to /etc/sysconfig/httpd:

export PATH=${PATH:+$PATH:}/usr/local/bin

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

Comments

1

Have a look at the /etc/passwd to see which login shell the apache user has (on EC2 Ubuntu instances it should be /bin/sh which is a link to /bin/dash). Then have a look at the man page of that shell and find out which configuration files are read upon login. (For /bin/dash that would be .login in the user's home directory.) In those you should be able to extend your $PATH as you like.

EDIT:

Since you seem to have no login shell for that user: Have a look at the /etc/init.d/* scripts which start the system services. Apache will be one of them. They are started as root and may change the current user (e. g. to the apache user). In there you might be able to adjust the PATH as you like it.

Patching those scripts, however, is not considered typical configuration. Updates might overwrite what ever you patch there.

12 Comments

The /etc/passwd for apache points to /sbin/nologin, so it hasn't got a shell (I don't think, I'm not a pro unix guy). I looked for that path and couldn't find anything
I see. Probably the apache process is just started without logging on properly by just switching the current user. In this case the process running as the apache user is the root of all evil and has to change the $PATH itself before or when spawning new child processes.
I added another approach in my answer.
I don't have apache it seems, I have httpd. However, there's nothing in there about the path or changing users
No but you can probably change it there since it gets inherited by the child program.
|

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.