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 7050395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:08:17+00:00 2026-05-28T03:08:17+00:00

I need to allow a PHP script on my local web server, to SSH

  • 0

I need to allow a PHP script on my local web server, to SSH to another machine to perform a specified task on some files. My httpd runs as _www with low permissions, so setting up direct passwordless SSH is difficult, not to say ill-advised.

The way I do it now is to have a minimal PHP script that sudo-exec’s (as me) a shell script which is outside of the document root. The shell script in turn calls (as me) the PHP code that does the actual SSH work, and prints its output. Here’s the code.

read_remote_files.php (The script I call from my browser):

exec('sudo -u me -n /home/me/run_php.sh /path/to/my_prog.php', $results);
print $results;

/home/me/run_php.sh (Runs as me, calls whatever it’s given):

php $1 2>&1

sudoers:

_www ALL = (me) NOPASSWD: /home/me/run_php.sh

This all works, as my_prog.php is called as me and can SSH as me. It seems it’s not too insecure since run_php.sh can’t be called directly from a browser (outside document root). The issue I’m having is that my_prog.php isn’t called as an HTTP program so doesn’t have access to the HTTP environment variables (DOCUMENT_ROOT etc).

Two questions:

  1. Am I making this too complicated?
  2. Is there an easy way for my final script to get the HTTP variables?

Thanks!
Andy

  • 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-28T03:08:17+00:00Added an answer on May 28, 2026 at 3:08 am

    “I need to allow a PHP script on my local web server, to SSH to another machine to perform a specified task on some files.”

    I think that you are phrasing this in terms of a solution that you have difficulty in getting to work rather than a requirement. Surely what you should be saying is “I want to invoke a task on machine B from a PHP script running under Apache on Machine A.” And then research solutions to this — to which there are many from a simple ‘roll-your-own’ RPC tunnelled over HTTP(S) to using an XMLRPC or SOA framework.

    Two caveats:

    • Do a phpinfo(); on both machines to check what extensions are available and
    • Also check your php.ini setting to make sure that your service provider hasn’t disabled any functions that you expect to use (or do a Q&D script to echo 'disable_functions = ' . ini_get('disable_functions') . "\n"; ...)

    If you browse here and the wider internet you’ll find many examples. Here is one that I use for a similar purpose.

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

Sidebar

Related Questions

I need a PHP/MySQL based Bug Tracking script that will allow me to put
I need to allow a consultant to connect to SSIS on a SQL Server
I need a php script that you can use to set up a online
I have a php script that I'm trying to pull some data from a
What I need to have happen: PHP needs to launch an server app which
I need to allow other Python applications to register callback functions for events in
I need to allow the vertical scrollbar in a multiselect listbox (VB6) however, when
I need to allow full-text searching on two fields that are concatenated together. In
I need to allow users to upload PDF documents that other users will read.
I need to allow users to select an assembly in much the same way

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.