How to deploy TALL stack app on Azure App Service(feat. Bun)

Tutorial: Deploy a PHP, MySQL, and Redis app to Azure App Service https://learn.microsoft.com/en-us/azure/app-service/tutorial-php-mysql-app?source=recommendations

Based on this article, create App Service and MySQL resource. This will guide you to create github action for deploy your app to App Service. (Step 7)

There are a few other steps to complete the deployment properly.

Open the GitHub action script and add these steps to build frontend assets before zipping all the code up.

- name: Setup bun
uses: oven-sh/setup-bun@v2
 
- name: build frontend assets
run: bun install --no-save && bun run build

Also, create startup.sh file to execute necessary command on each deployment.

#!/bin/bash
 
echo "Copying custom nginx config over to /etc/nginx/sites-available/default.conf"
 
NGINX_CONF=/home/site/wwwroot/default.conf
 
if [ -f "$NGINX_CONF" ]; then
cp /home/site/wwwroot/default.conf /etc/nginx/sites-available/default
service nginx reload
else
echo "File does not exist, skipping cp."
fi
 
# DB migration
php /home/site/wwwroot/artisan migrate --force
 
# Clear caches
php /home/site/wwwroot/artisan cache:clear
 
# Clear and cache routes
php /home/site/wwwroot/artisan route:cache
 
# Clear and cache config
php /home/site/wwwroot/artisan config:cache
 
# Clear and cache views
php /home/site/wwwroot/artisan view:cache

This is the sample default.conf file

server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public;
index index.php index.html;
server_name example.com;
port_in_redirect off;
 
location / {
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
}
 
# Disable .git directory
location ~ /\.git {
deny all;
access_log off;
log_not_found off;
}
 
# Add locations of phpmyadmin here.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 3600;
fastcgi_read_timeout 3600;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
  • You need to put an absolute path to make the script work. Startup Command

  • Also, you need to add the ASSET_URL environment variable to make all the statically imported assets available over an HTTPS connection.