The more standard Unix way to do this is to
set the user id of an executable. In other words, if root sets the uid of an executable, and user
foo executes it (she needs to have the permission), the program will execute as root.
Beware, this approach can leave security holes open on your system! Use with care.
Unfortunately, Linux systems
ignore the setuid bit on interpreted executables for security reasons. (This is not necessarily the case for other unices like the BSDs or MacOSX).
This can be circumvented by writing a small C program to do it. In your favorite text editor, save the following under the name
start_lamp.c
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
char *cmd[2] = {"/opt/lampp/lampp", "start"};
execvp("/opt/lampp/lampp", cmd);
return 0;
}
Now do the following:
$ gcc start_lamp.c -o start_lamp # compile the code
$ sudo chown root start_lamp # change the owner of the executable
$ sudo chmod +s start_lamp # set the UID
$ ./start_lamp # start the server
That should be it. Now next time you want to launch the server simply call the executable with your normal user, and it should execute with root permissions.
Note I tested this on my (Debian) machine with a trivial example. I don't have LAMPP to test it really, so I cannot guarantee it works. If you encounter any kind of problem, please do let me know.
Extra reading:
-
setuid(7)
@scorz: I have no idea what you wrote means, but I'm reading the man right now :)
EDIT expect(1) is not installed on my system...