image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
LinkBack Thread Tools
  #1  
Old August 13th, 2009, 07:51 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
vito is on a distinguished road
$PATH for apache2, how can I make it understand my /etc/profile?

When I start a shell script from Apache/PHP by shell_exec() PHP function, the environment inside this shell script is NOT set as it should be.

In particular, $PATH variable contains this:
PATH=/usr/bin:/bin:/usr/sbin:/sbin

Instead of what it normally contains when I work in Terminal.

It means that the shell ignores the /etc/profile file. The question is - how can I instruct apache/php/sh to work with /etc/profile?
Reply With Quote
  #2  
Old August 15th, 2009, 10:12 AM
fintler's Avatar
Registered User
 
Join Date: Sep 2000
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
fintler is on a distinguished road
I just want to say that from what you posted, you don't know what you're doing. This is a security feature. Tread lightly or some script kiddie is going to hack into your server. Using the shell_exec() securely is difficult for highly experienced people to do correctly.

That said, you want to export your PATH env as the command itself...

Code:
$command = 'export PATH="/foo:/foo/bar"; script.sh';
shell_exec($command);
Again, keep in mind that any user input that gets constructed into the command instance var can do some serious damage to your server. So be careful. Good luck!
Reply With Quote
  #3  
Old August 15th, 2009, 04:23 PM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
vito is on a distinguished road
thanks for your reply and code example. it will work. however, I want my script.sh to get all environment configuration as I get in bash terminal. it's not a question of just PATH, but all other env variables. They are NOT initialized now, when I do shell_exec(). Why?
Reply With Quote
  #4  
Old August 16th, 2009, 11:46 AM
fintler's Avatar
Registered User
 
Join Date: Sep 2000
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
fintler is on a distinguished road
Try using system() instead of exec_shell() to get a few default env vars setup automagically (copying the char *envp[] from the parent process -- probably apache).

If you take this route, you want to be careful that there aren't any paths included that are writable by the web service process. So, try running system("export") to make sure, since it ma be different from your default login shell.
Reply With Quote
  #5  
Old August 17th, 2009, 11:23 AM
Registered User
 
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
vito is on a distinguished road
I found the solution. I have to define PATH variable by means of LSEnvironment in /System/Libraries/LaunchDaemons/org.apache.httpd.plist

By default ENV variables are NOT passed to applications, in Mac OS
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 11:37 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.