Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Command Not Found When Executed via PHP shell_exec()

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 5 months ago )

 

I want to execute following command on my Ubuntu server using php:

android create project --target 8 --name $fname --path ./$fname --activity MainActivity --package $fpack 2>&1

The above command is to create an Android app project. So when I enter this command on my terminal then it works fine, but when I execute it via PHP:

<?php
$fname = $_POST['fname'];
$fpack = $_POST['fpack'];
$email = $_POST['email'];

// Creating a new Android project.
var_dump(shell_exec("android create project --target 8 --name $fname --path ./$fname --activity MainActivity --package $fpack 2>&1"));

?>

When I run my PHP script I get the following output:

string(26) "sh: 1: android: not found "

Why it works when I enter manually in terminal (from user 'ashish' account) but not with php? my apache user and group is same (ashish). Any help will be appreciated :)

usr_profile.png

User

( 5 months ago )

The question is a bit old, but for those who experience this problem can try to set the environment variables of direct on the server. PHP uses the putenv () function.

Example:// Set Variable Enviromental

$JAVA_HOME = "/usr/lib/jvm/java-8-oracle"; 
$ANDROID_HOME = "/opt/android-sdk-linux";
$PATH="$JAVA_HOME/bin:/usr/local/bin:/usr/bin:/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/build-tools/24.0.0-preview";

putenv ("JAVA_HOME = $JAVA_HOME"); 
putenv ("PATH = $PATH");

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif