LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   OpenVZ problem (http://www.linuxquestions.org/questions/linux-server-73/openvz-problem-733367/)

yourweb 06-16-2009 10:20 AM

OpenVZ problem
 
Hello everybody
I'm currently busy with developing a PHP system which needs ro run some commands such as vzctl. vzctl doesnt wants to run on a normal account and only on the root account. How can I run a root command with PHP and maybe C/C++ or perl??

OR is the best solution to put the command in a .sh file and set a cron job as root user on it? Or won't that work?

The OS is CentOS 5.3 64-bit.

lukav 06-16-2009 01:42 PM

A possible solution is to add the user name that apache is running under to the sudoers file with the option to access those specific files and to not require a password. Keep in mind that this could open a security hole - so be carefull.

If you do this, just remember to add sudo to your commands.

yourweb 06-17-2009 12:32 AM

Quote:

Originally Posted by lukav (Post 3576198)
A possible solution is to add the user name that apache is running under to the sudoers file with the option to access those specific files and to not require a password. Keep in mind that this could open a security hole - so be carefull.

If you do this, just remember to add sudo to your commands.

I have already tried to do this, but it didn't work. Probably I did something wrong, can you show me how I can do this?

lukav 06-17-2009 12:31 PM

In /etc/sudoers you will want a line similar to this:
Code:

www-data ALL=NOPASSWD: /usr/bin/vzctl
You will want to make sure that the specifics above are the same for you.

In your PHP code try executing vzctl using sudo
Code:

<?PHP
exec('sudo /usr/bin/vzctl');
?>



All times are GMT -5. The time now is 06:00 PM.