So my working with my project with requires this kind of capable, i combined laravel and ionic and call ionic /www folder from laravel public and its working great, but my project is actually want to directly convert this www to apk which is like online ‘appbuilder’, so i made a route that execute ionic using exec command from php, what am tryting to execute is ionic cordova build android
, so whenever user go to this route it will directly generate and download the apk, i have read all the stackoverflow topic related to this issue but nothing works. I know that whenever we execute from exec(), shell_exec() and backticks operator the user that actually run this is www-data
, and this www-data
has a lot of problem with permission. i got below error when i try to run ionic cordova build android using www-data
:
using this command: sudo -u www-data ionic cordova build android
(why did i do this, because if i run from web browser it will pop 504 error which is bad idea cus i can’t see the error)
shell.js: internal error
Error: EPERM: operation not permitted, chmod '/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/app/src/main/res/xml/config.xml'
at Object.chmodSync (fs.js:1023:3)
at copyFileSync (/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/node_modules/shelljs/src/cp.js:41:6)
at /var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/node_modules/shelljs/src/cp.js:201:5
at Array.forEach (<anonymous>)
at Object._cp (/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/node_modules/shelljs/src/cp.js:157:11)
at Object.cp (/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/node_modules/shelljs/src/common.js:186:23)
at updateConfigFilesFrom (/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/lib/prepare.js:98:11)
at Api.module.exports.prepare (/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/lib/prepare.js:42:20)
at Api.prepare (/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/cordova/Api.js:192:45)
at /usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/prepare.js:105:36
[ERROR] An error occurred while running subprocess cordova.
cordova build android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
before i got above error i changed the config.xml permission under platforms/android/app/src/res/xml to 777, but if change it back to 666, the error will look like this:
cp: copyFileSync: could not write to dest file (code=EACCES):/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/app/src/main/res/xml/config.xml
EACCES: permission denied, open '/var/www/html/instantapp-inovidea/public/mobileapps/helloworld/platforms/android/app/src/main/res/xml/config.xml'
idk what permission to let to www-data to be able to execute this ionic cordova command, any help would be great, thanks.
ps: sorry if my english is not good, im trying my best to explain everything.