I have a laravel application on my azure webapp (linux). I am trying to run some php commands after deploying.
I am using Local Git to deploy to my azure's webapp.
and as per this guide, i set the "POST_BUILD_SCRIPT_PATH" to run a script named "postbuild.sh"
(Note that i am using a .sh file since i am in a Linux based webapp. )
The problem is my postbuild.sh location is in "wwwroot" (where my laravel root application is). but i keep getting the
Could not open input file: artisan
message when i try to run any artisan command like
php artisan cache:clear
After looking up, i found that the script is being executed from a tmp location.
and i should use sourcing for running the script in the right location but it is still doesn't work.
so i created another .sh file in 'wwwroot' as well named 'clearcache.sh' and tried to source it in 'postbuild.sh' but still not working.
My postbuild.sh is
echo "Post Build .sh"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
echo "===================="
source ./home/site/wwwroot/refresh.sh
My refresh.sh is
echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
php artisan cache:clear
and the errors i am having when pushing to azure repo is:
remote: Detecting platforms...
remote: Detected following platforms:
remote: php: 7.4.24
remote:
remote: Using intermediate directory '/tmp/8d9a71074a40f5b'.
remote:
remote: Copying files to the intermediate directory...
remote: Done in 0 sec(s).
remote: /home/site/wwwroot/postbuild.sh: line 6: ./home/site/wwwroot/refresh.sh
remote:
remote: : No such file or directory
remote: Source directory : /tmp/8d9a71074a40f5b
remote: Destination directory: /home/site/wwwroot
remote:
remote: Executing pre-build command...
remote: Pre Build
remote: Finished executing pre-build command.
remote: PHP executable: /tmp/oryx/platforms/php/7.4.24/bin/php
remote: No 'composer.json' file found; not running 'composer install'.
remote:
remote: Executing post-build command...
remote: Post Build .sh
remote: Script executed from: /tmp/8d9a71074a40f5b
remote: Script location: /home/site/wwwroot
remote:
remote: ====================
Please note the following:
- Laravel root directory doesn't contain 'index.php' file, but i added a dummy 'index.php' file anyway because it was needed by Azure to validate the build.
- I removed the 'composer.json' file from the local git because i didn't need to run composer install. i just wanted to copy app & routes folder from the repo folder to 'wwwroot'