terminal commands on the server ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
garyed
Forum Newbie
Posts: 13
Joined: Fri Feb 20, 2009 6:45 pm

terminal commands on the server ?

Post by garyed »

Can I run a command from a php file that will actually run on my server as if I were typing the same command in a linux terminal?
If I run this code from a remote browser the ls command outputs to the browser & the aplay doesn't do anything.
I want the ls to output to my servers terminal & also the beep too.
Is this possible ?

Code: Select all

<?php 
$aa = "ls /var/www";
system ($aa);
$bb = "aplay /var/www/beep.wav";
system = ($bb);
 
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: terminal commands on the server ?

Post by Eran »

exec() and/or shell_exec() are probably what you are looking for.
http://www.php.net/manual/en/function.shell-exec.php
http://www.php.net/function.exec
garyed
Forum Newbie
Posts: 13
Joined: Fri Feb 20, 2009 6:45 pm

Re: terminal commands on the server ?

Post by garyed »

pytrin wrote:exec() and/or shell_exec() are probably what you are looking for.
http://www.php.net/manual/en/function.shell-exec.php
http://www.php.net/function.exec
I've tried them both & I can't get them to work.
I've been searching the net for two solid days & I can't find the answer so if anyone has one I wish they would post a simple code to use the
"aplay" command because that is what I'm really trying to do. Have someone click on a page & have aplay play the beep.wav file on my computer (running Apache).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: terminal commands on the server ?

Post by VladSun »

1. Use absolute path. E.g.:

Code: Select all

exec('/usr/local/bin/aplay /var/www/beep.wav');
2. Print error output to see what's wrong:

Code: Select all

exec('/usr/local/bin/aplay /var/www/beep.wav 2>&1');
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply