First off, if this belongs on Ask Ubuntu, my apologies...I\'m not really sure what forum this falls under.
I\'m attempting to fork and build an Android project from
If forking and building script working fine when is executed under your user account in the terminal then a problem is most likely with environment variables and files permissions.
1 It could be that path defined in GRADLE_USER_HOME is not writable by www-data user. To change home dir you could execute gradle -g /path/writable/by-www-user just before running build script or use in PHP putenv() to amend 'GRADLE_USER_HOME'.
If you change GRADLE_USER_HOME then also move files like gradle.properties which may be important for you build.
2 Check if gradle command can be executed by www-data
sudo -u www-data `gradle --version`
How to check environment variables for www-user and for your user:
you can use in terminal printenv to print environment variables. For example for www-data user that would be sudo -u www-data printenv and for your user just printenv
you can save them to files and compare
sudo -u www-data printenv > wwwdata-env
printenv > my-env
diff --side-by-side --suppress-common-lines wwwdata-env my-env
Then use PHP method putenv() - to set any missing variables related to Gradle and the project you build.