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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:05:50+00:00 2026-06-18T14:05:50+00:00

I need to start php process from shell on remove server with some arguments,

  • 0

I need to start php process from shell on remove server with some arguments, so i thought that it should be a nice idea to make REST API, that executes some function when user performs GET request.

I wrote a simple bash script for testing and figured out that command-line argument is not being specified, when calling this script from website:

shell_exec('/var/www/test.sh 123')

Bash script source:

#!/bin/sh
echo $1;

When calling this bash script from root (or other existing user) it correctly shows argument it has received. When i call this script from website (that is running under user www-data under apache2), it returns nothing:

Also, if i execute this bash script in my console under www-data user, it also returns nothing:

su -c '/var/www/test.sh 123' www-data

Also i’ve tried to start process from different user from php (is supposed that this will not work for security reasons, but just in case):

$result = system("su -c '/var/www/test.sh 123' sexyuser", $data);
// var_dump($result): string(0) ""
// var_dump($data): int(1)

So, what privileges should i give to www-data user to run process under php?

  • 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-06-18T14:05:51+00:00Added an answer on June 18, 2026 at 2:05 pm

    You should let php run the script and handle the results

    check php.net on exec for example http://www.php.net/manual/en/function.exec.php

    //called by example.com/myshell.php?day=today&k=y&whatever=youwant
    $arguments = implode(" ", $_GET);
    $lastline_of_exec_result = exec ( "/your/command.sh ".$arguments); //sh called with today y youwant
    echo $lastline_of_exec;
    

    Where $arguments are the stringified list of ALL information your script got from GET arguments

    if you want a ore precise in and output, try this:

    //called by example.com/myshell.php?day=today&k=y&whatever=youwant
    $argument = $_GET['whatever'];
    $output = array();
    $last_line = exec("your/command.sh ".$argument, &$output); //sh called with youwant
    foreach($output as $line)
        echo $line."<br/>".PHP_EOL;
    

    or of course (with shell_exec)

    $argument = $_GET['whatever'];
    $output = shell_exec("your/command.sh ".$argument);
    echo "<pre>".$output."</pre>";
    

    make sure (shell_)exec is not listed under disable_functions in your php.ini

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

Sidebar

Related Questions

I need to verify in php that a string should not start or end
I need to start a Unix process by calling a PHP-page through the web.
I need some advice before I start. My PHP Skills are only 3 months
Using PHP's proc_open() , I can start a process, read from STDOUT and STDERR
I need to start a copy of a Rails app from within Java. I
I need to start NSTimer by 0:0:0 that I am doing and I have
I need to start a project that will be json-API-centric, which means that most
Basically I hate a satellite website that is including form.php from an entirely different
I have one PHP script that has to start a second script in the
Possible Duplicate: PHP Curl script to pull data from remote server every 10 minutes

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.