I'll try to be brief with what I'm trying to accomplish.
What I'm trying to do here, is that I want to make a webApp that automates the build of android apps (APKs) based on user input.
I'm running a CLI Ubuntu Linux server (18.04.1), that has a LAMP stack installed on
For apache :
$ apache2 -v
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2021-06-18T11:06:22
For PHP :
$ php -v
PHP 7.4.21 (cli) (built: Jul 1 2021 16:09:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
For MySQL
$ sudo mysql -v -u mysql_username -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.7.34-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
I have made a directory ( /var/www/my_webapp.com/ ) where my webApp resides and it is as the following:
.
├── build.sh
├── Source
│ ├── app
│ ├── build.gradle
│ ├── gradle
│ ├── gradle.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── local.properties
│ ├── nativetemplates
│ └── settings.gradle
└── test.php
the build.sh script is responsible for calling the gradle wrapper and starting the build process, and it is as the following:
cd /var/www/my_webapp.com/Source/ && ./gradlew assembleDebug
The Source directory is a folder that contains the android app source code we want to build and compile to an APK.
and last but not least, test.php script that issues command for the bash script (build.sh) to build the APK. and it is as the following :
<?php
/**
* Execute the given command by displaying console output live to the user.
* @param string cmd : command to be executed
* @return array exit_status : exit status of the executed command
* output : console output of the executed command
*/
function liveExecuteCommand($cmd) {
while (@ ob_end_flush()); // end all output buffers if any
$old_directory = getcwd();
chdir("Source/");
$proc = popen("$cmd 2>&1 ; echo Exit status : $?", 'r');
$live_output = "";
$complete_output = "";
echo "<pre>";
while (!feof($proc)) {
$live_output = fread($proc, 4096);
$complete_output = $complete_output . $live_output;
echo $live_output . "\n";
@ flush();
}
echo "</pre>";
pclose($proc);
// get exit status
preg_match('/[0-9]+$/', $complete_output, $matches);
chdir($old_directory);
// return exit status and intended output
return array ('exit_status' => intval($matches[0]),
'output' => str_replace("Exit status : " . $matches[0], '', $complete_output)
);
}
$result = liveExecuteCommand(dirname(__FILE__) . '/build.sh');
if($result['exit_status'] === 0){
echo "finished sucessfully. <br /> ";
} else {
echo "finished with error: {$result['output']} <br /> ";
}
The problem is when I try to run the php script - test.php that is -, I get this error:
finished with error:
Exception in thread "main" java.lang.RuntimeException: Could not create parent directory for lock file /var/www/.gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p/gradle-6.5-bin.zip.lck
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:43)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
I don't know why gradle build script tries to create a directory in the path as it is shown in the previous error message, knoing that the build script resides on a completely different directory (/var/www/my_webapp.com)