I have a linux VPS which is running ubuntu 8.04

I want to execute some command to the terminal, for doing that i use system() or exec() function.

The functions are working properly at localhost, but aren't working properly on the VPS.

Let's say, i have a command :-

youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv

This command downloads the video's flv
I use following code in my php code

system('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv');

This should work properly. The command is executed in terminal but i do not receive the output as desired.

There are no error messages, just output from terminal which comes before the actual downloading of the video starts.

Any help would be really appreciated.

7 Years
Discussion Span
Last Post by lipo

Just to let you know I find it is best to not use the system command line functions. My reason - I find that some servers just aren't compatible with these functions due to security policies and can even crash a server if the right settings are set on the server. So perhaps if you explain what you are trying to make the command do (like copying a movie) and I will try and find an alternative. I know the file_get_contents() and file_put_contents() are good for copying files on other servers.


Hi cwarn23. Thanks for your reply.
Probably what i'm looking for is to download a youtube video and edit it using mencoder.

So i probably want to use youtube-dl and mencoder, which are installed on my VPS

I face same problem using exec(), sytem() or passthru()
If commands are run manually using ssh, it works fine.
But if done through php, it doesn't work fully and properly.

Where can the problem be ? :)


If you own a VPS (Virtual Private Server) like I do and really want to use those functions then you will need to find the security policies for php and set the security policies to allow php to interact with the core system. I think it's mainly a thing that's not enabled by default due to security reasons but I myself am not sure on how to enable these security policies. I'll google a bit for you to see if I can find such info.


I tried using exit(0) but it doesn't made any change.
One more thing...for example we execute a command as :-

echo exec('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv');

It gives output as :-

Video data found at http://v9.lscache3.googlevideo.com/videoplayback?ip=

and then the browser stops.
The execution stops exactly when the process starts (i.e when it displays the actual download percentage..like speed and percentage of download completion)

While doing same on localhost, it works fine.
Same happens with mencoder...the output displayed is upto when the real conversion of video starts.

I think there need to be some setting to be changed in php.ini
I will be looking in.


Maybe php doesn't have the permissions to access the base of the home folder where as when you do it through the command terminal you are logged in as administrator. So try something like the following but replace the end address with the address to your web directory.

echo exec('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/user/public_html/video.flv');

So the public_html folder is the base of your website.


Ya, i think you are correct.
But as of now, i dont have any user (rather than root)
let me create one and make a sub root at public_html

Will report back tomorrow.
Thanks for your help. let's see how it goes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.