Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:00:25+00:00 2026-05-27T20:00:25+00:00

I have a simple script I’m trying to run: <?php print exec(‘whoami’); $output2 =

  • 0

I have a simple script I’m trying to run:

<?php
print exec('whoami');
$output2 = exec('ssh someotherhost ls -l /path/to/dir',$output);
print_r($output);
print_r($output2);
print $output2;
?>

The goal of this script is to run a command on another networked server. If I run the above ssh command (replacing the dummy data with real data) from the command line:
ssh someotherhost ls -l /path/to/dir

It outputs the proper ls lines. However, when I run the above script from the same dir with the same command, it does not output in any of the three bottom print lines. However, the exec() with whoami at the top does print out as expected. So my question is, why does the first command work and not the second?

Note that the two networked servers are on an internal network and are setup with ssh network key pairings. The command works, just not from within php.

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:00:25+00:00Added an answer on May 27, 2026 at 8:00 pm

    PHP may be running the ssh command with a different user than you’re doing it from the CLI. Maybe the user PHP is running it as doesn’t have the servers key in its key file or something.

    Personally, I would just use phpseclib, a pure PHP SSH implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an extremely simple script with PHP exec , calling mysql command: $dbhost
I have simple script: #!/bin/sh column=$1 awk '{print $'$column'}' When I run: ls -la
I have a simple php script on a server that's using fsockopen to connect
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have a simple php script on my domain that sends me an email:
I have simple python script, 'first.py': #first.py def firstFunctionEver() : print hello firstFunctionEver() I
I have a simple script trying to learn about hashes in Perl. #!/usr/bin/perl my
I have a simple script blah.py (using Python 2): import sys print sys.argv[1] If
I have a simple script: $('.expand').each(function(i){ var _Expand = $(this).parent(); ExpGroupBy(_Expand); }); Trying to
I have a simple script: now = datetime.datetime.now() print %d%d%d%d%d % ( now.year, now.month,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.