Run Laravel artisan migrate after each deploy

Javier "Ciberman" Mora 1 Reputation point
2022-12-13T12:58:26.933+00:00

Hi. I have a question related to Azure AppServices.
We are deploying a Laravel app using "git push" from local. I'm used to manage Linux VPS but I'm a bit lost when it comes to AppServices.

I want to run a command (php artisan migrate) each time the app is deployed immediately after the git push and before the site is online again. The command updates the DB or does nothing depending if there are pending schema changes.

Where should I configure this command? I was reading about Kudu deployment hooks but I'm not sure if it's the right choice. It looks overcomplicated for what I have to do.

Should I use Kudu deployment hooks or should I use the Azure Startup command, or what should I use?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2022-12-19T08:07:34.047+00:00

    @Javier "Ciberman" Mora , Apologies for the delay from over the weekend.

    I would suggest you leverage Azure Startup (under ‘Configuration’ in the portal target, Startup command.
    The easiest way to run database migrations with your database is directly from within the App Service container.

    You may check this tutorial sample application:
    Tutorial: Build a PHP (Laravel) and MySQL Flexible Server app on Azure App Service

    As a side note, these commands or scripts are executed after the built-in Docker container is started, but before your application code is started.

    For more info, see:

    PHP 8 (NGINX) and Laravel Migrations

    Configure handler mappings

    0 comments No comments

  2. Javier "Ciberman" Mora 1 Reputation point
    2022-12-26T17:37:11.587+00:00

    Hello. I have configured an startup script here:

    274094-image.png

    This is my startup script:

    root@be4e0b8db42b:/home# cat startup-farmaticapproxdevel-apache.sh   
    #nginx start  
    cp /home/site/mpm_worker.conf /etc/apache2/mods-avalilable/mpm_worker.conf  
    cp /home/site/opcache-recommended.ini /usr/local/etc/php/conf.d/opcache-recommended.ini  
    service apache2 restart  
      
    # Deploy our amazing Laravel App  
    cd /home/site/wwwroot/ && ./deploy-azure.sh  
      
    # Installing cron  
    apt-get update -qq && apt-get install cron -yqq  
    (crontab -l 2>/dev/null; echo "* * * * * /usr/local/bin/php /home/site/wwwroot/artisan schedule:run 2>&1")|crontab  
    service cron start  
    

    How can I see the logs generated by my ./deploy-azure.sh script? I need to know if migrations have run succesfully or if there is any error or warning during deployment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.