# Executing Scripts from PHP Web Interface

**URL:** <https://community.unix.com/t/executing-scripts-from-php-web-interface/283805>\
**Category:** Shell Programming and Scripting\
**Created:** [March 3, 2011, 7:41am UTC](https://community.unix.com/t/executing-scripts-from-php-web-interface/283805 "2011-03-03T07:41:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuperDuck](https://community.unix.com/letter_avatar/superduck/32/5_5575768a8748004e209b776fc1b2916d.png) [@SuperDuck](https://community.unix.com/u/SuperDuck)\
**Post date:** [March 3, 2011, 7:41am UTC](https://community.unix.com/t/executing-scripts-from-php-web-interface/283805/1 "2011-03-03T07:41:57Z")

</div>

Later Edit: So far the problem is solved, i've loaded the .profile into the bash script, and now it's working great  
But I might have some future questions, so please don't close the thread. Thanks

Hello everyone,

I am trying to develop an web interface, which is able to execute pre-defined sh scripts and display the output in the interface.

Unfortunetely I am not able to execute the script files.  
If I execute the script inside the console it works, but if I execute it from PHP the script won't do anything.

I installed ssh2 extension for PHP and here is my code (it's just a basic one)

```php
if(!($con = ssh2_connect("server", 22))){
echo "<br/>";
echo "fail: unable to establish connection\n";

} else {

if(!ssh2_auth_password($con, "user", "password")) {

echo "fail: unable to authenticate\n";

} else {

echo "Logged In\n";

// execute a command

if(!($stream = ssh2_exec($con, "./report" )) ){

echo "Unable to execute\n";

} else{

// collect data

stream_set_blocking( $stream, true );

$data = "";

while( $buf = fread($stream,4096) ){

$data .= $buf;

echo .$buf;

}

fclose($stream);

}

}

}

?>

```

Thanks In Advance
