0

Possible Duplicate:
How to run PHP exec() as root?

Hey Guys,

I need to connect the linux root user in php.

i hosted my file in var/www/html/connect.php

I need to execute one shell_exec script. It says it "Only root user can login".

How can i change that? or Please help me to sort the problem.

Community
  • 1
  • 1
Dipen
  • 57
  • 9
  • 2
    possible duplicate of http://stackoverflow.com/questions/1598231/how-to-run-php-exec-as-root http://stackoverflow.com/questions/3173201/sudo-in-php-exe – Jim Apr 21 '11 at 15:54

2 Answers2

0

Usually php/apache executes the php files using the www-data user. if you need to execute your shell, all you need to do is to give the corresponding permissions to www-data for that file using chmod

pleasedontbelong
  • 19,542
  • 12
  • 53
  • 77
-1

you need to give apache (or whatever is running php) sudo rights to the server, than you can run as root, bu doing:

sudo command
Naftali
  • 144,921
  • 39
  • 244
  • 303
  • is this safe at all??? giving sudo rights to www-data seems too dangerous – pleasedontbelong Apr 21 '11 at 15:57
  • what? your giving it to `apache`, see the dupe – Naftali Apr 21 '11 at 15:58
  • Bad advice without narrowing it down to only allowing `sudo` for that script he is running. If there was an exploit on the server and someone was able to inject code, it could lead to massive problems. IE: `www-data ALL=NOPASSWD:/path/to/script` But there again, depending on what the script does can lead to holes. So yea, the OP really needs to look at the cause and effect and consequences of such actions before implementing. – Jim Apr 21 '11 at 15:58