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

  • Home
  • SEARCH
  • 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 8141487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:31:31+00:00 2026-06-06T12:31:31+00:00

We have a server running PHP 4.3.9 with safe_mode ON and safe_mode_exec_dir setted to

  • 0

We have a server running PHP 4.3.9 with safe_mode ON and safe_mode_exec_dir setted to /usr/local/bin/php/

So, as it is written on php.net, we can’t execute any script which is not in safe_mode_exec_dir.

I want to call unzip system command (don’t have zip library) which is inside /usr/bin. So I can’t call by a PHP script.

I’ve created a shell script which is placed in /usr/local/bin/php to execute unzip function.
So basically, it takes 2 arguments (archive file and file destination).

  • When I call it in command line with simple user, it works fine.
  • When I call it with PHP script, it doesn’t run (error code 127)

Shell script is with following permission : -rwxr-xr-x
So It can be runned by apache users.

I can’t understand why it doesn’t run.

Shell script :

#!/bin/bash
DIR=$1
FILE=$2

# Write to file to check if shell script is running
echo "BANANA" > /my/path/to/app/banana-log.txt

# If file exists, run unzip
if [ -a $FILE ];
    then
        /usr/bin/unzip -u $FILE -d $DIR >> /my/path/to/app/banana-log.txt
else
    echo "FILE_NOT_FOUND $1"  >> /my/path/to/app/banana-log.txt;
fi

PHP Script :

$output = array();
$return_value = -1;

//-- Get safe_mode_exec_dir value
$shell_script = ini_get('safe_mode_exec_dir') . "/myscript.sh";
$shell_cmd = sprintf("sh %s %s %s", $shell_script, escapeshellarg('/my/destination/path'), escapeshellarg('my/path/to/archive/file.zip'));


//-- Execute command
echo "COMMAND IS : ", $shell_cmd;
$output = exec($shell_cmd, $output, $return_value);
echo "RESPONSE IS : ", implode("<br />",$output);
echo "RETURN CODE IS : ",$return_value;
  • 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-06T12:31:32+00:00Added an answer on June 6, 2026 at 12:31 pm

    After checking apache error log, I’ve seen following message :

    sh: /usr/local/bin/php/sh: No such file or directory

    So, It isn’t clear but exec already call shell command. My command start by sh.
    Therefore, php execute following command :

    sh sh /usr/local/bin/php/myscript.sh ‘/my/destination/path’ ‘/my/path/to/archive/file.zip’

    sh file doesn’t exist at /usr/local/bin/php/

    To correct this, I’ve juste removed “sh” from exec command and it works fine !

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

Sidebar

Related Questions

How to send messages from php to node.js? I have a linux server running
I have a PHP server at home for development. It is running: Ubuntu 9.10
I have two websites running on my own root server (ubuntu/nginx/php-fpm). Now I want
Strange issue. I have SQL Server running on an EC2 box that I can
I have a bluetooth server running on my Ubuntu desktop written using PyBlueZ. That
I have an Apache server running which hosts a php web application. This server
I have a linux server running ubuntu 10.10 maverick with apache and php installed,
I have an OS X 10.6 Server running apache, php. I have CronniX installed
I have a web server that is running PHP 5.3.6 non thread safe (VC9),
I have a Windows Server 2003 and asp.net website running on localhost. I have

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.