Github actions to deploy laravel application on shared hosting

  Wed 01 / 05 / 2024

  Posted by: rgk

Category : Deployment

Tags : laravel , web , backend , deployment

Post Thumbnail
Description

I've setup github actions on my project and its working fine, apart from one issue, its taking too long to sync file changes. I've watched your video series on github actions and some other youtubers and kind of mixed the approaches. I've cached the composer dependencies so they won't be installing on every run, thereby reducing the files to sync. Now, one thing it takes a lot of time to push the changes as you can see. Is there any other way to reduce this time...


Also one other thing, I've migrated the project from Laravel 10 to Laravel 11 and in the Low Impact changes section, there's a package named Doctrine which they say is no longer being used in the Laravel. I wanna ask if is it safe to remove that package & whats' the best way to remove it. Currently, in my mind, I can think of only removing it from composer.json and then run composer update.Is this a right approach?



View Code
                        on:
  push:
    branches:
      - main
name: 🚀 Deploy website on push
jobs:
  web-deploy:
    name: 🎉 Deploy the App using FTP
    runs-on: ubuntu-latest
    steps:
      - name: 🚚 Get latest code
        uses: actions/checkout@v4

      - name: Installing Node Dependencies
        uses: actions/setup-node@v4
        with:
          node-version: '18'
      - run: npm install

      - name: Building Assets
        run: npm run build

      - name: Cache Composer dependencies
        uses: actions/cache@v2
        with:
          path: vendor
          key: composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            composer-

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          tools: composer:v2
          coverage: none

      - name: Install Project Dependencies
        run: composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --no-dev

      - name: 📂 Sync files
        uses: SamKirkland/FTP-Deploy-Action@v4.3.5
        with:
          server: ftp.___
          username: ___
          password: ___
                
  Answered by CDL Sure, let me explain your both problems. 1. Yes it's takes too long to intsall the dependencies, and as you mentioned that you did this, using cache so that's good option, but make sure to install those packages that are not added in the cache, otherwise it will break your functionalities. Still, if you are getting tim out issues, you can increase your memory limit to take longer time to execute those tasks. 2. Yes you can remove it from your composer.json file and run composer update so it will remove that package, also you should know that laravel latest versions are installing the doctrine dbal package behind the scene. So we don't need to worry about that package.
Solved
  Comment   Share
0 Likes   1 Comment


comment-author
rgk Author

I've noticed that on first sync or upload, it took a lot of time as you can see from the image. On subsequent, uploads or deployment run, it just synced the file changes which happened in the pushed commit. Thereby, decreasing the time and now my changes are synced at max under a minute. For the cached dependencies, its running as expected. I've removed the doctrine and pushed the changes and it ran the composer update automatically. Caching dependencies is very good in my opinion. Overall, I'm happy with my experience with Github Actions, I'm now more concerned about writing quality code, then worrying about shipping or deploying the code. It's a breeze... :) Thanks for your video explanations also. Keep up the good work.



Reply


commented 5 months ago
comment-author
Hadayat Niazi Super Admin

Also make sure to mark the post as solved, if your issue was resolved. Thank you



comment-author
Hadayat Niazi Super Admin

Perfect. Happy to help you. Thanks for your kind words.