Question: How can I restart if a directory 'xyz' exist in the remote SSH server using PHP-SSH2?

```
 <?php
 function fsmoke_ping($command_name1, $menu_name1, $title_name1, $host_ip1)
 {
    $connection = ssh2_connect('http://xxxx.com', 22);
    ssh2_auth_password($connection, 'username', 'password');     

    $sftp = ssh2_sftp($connection);
    $handle = file_exists('ssh2.sftp://' . $sftp . '/etc/xyz/devices/$menu_name1', 'w+')  or die('Cannot open file:  '.$menu_name1);

    $data = "++$menu_name1\nprobe = $command_name1\n menu = $menu_name1\n title = $title_name1\n host = $host_ip1";
    fwrite($handle, $data);
    fclose($handle);

    exec(`sudo /etc/init.d/xyz reload`);

}
?>

```

in this, 

```
 exec(`sudo /etc/init.d/xyz reload`); 

```

is not working.so how can i restart it in here??

Answer: 
Obviously [ssh2\_exec](http://php.net/manual/en/function.ssh2-exec.php). `exec` will execute statement on your local machine.
use `/etc/init.d/xyz reload` in newfile (by chmod 755) and append `newfile nobody nobody` in `/etc/sudoers`
and use `exec(sudo newfile reload);`