Contact me

~ / projects / 02

Professional workshop 1, 2025

The video training catalogue of a library network, online and redeployed on every push.

Symfony development, tests, deployment

Architecture7 components

Two paths lead to the same server: the visitors' path and the code's path. A push to main triggers a workflow that connects to the VPS over SSH and updates the site, without me touching the server.
Architecture diagram: Dev machine to GitHub (push), GitHub to GitHub Actions (triggers), GitHub Actions to Symfony 6.4 (SSH / git pull / composer), Visitor to nginx (HTTPS), nginx to Symfony 6.4 (FastCGI), Symfony 6.4 to MySQL (Doctrine). OVH VPS / UBUNTU push triggers SSH / git pull / composer HTTPS FastCGI Doctrine Dev machinegit push GitHubmain branch GitHub Actionsworkflow deploy.yml Visitorbrowser nginxvirtual host Symfony 6.4PHP-FPM / Doctrine MySQLtrainings

Context

A Symfony site in two parts: a public front end to browse trainings and playlists, and a protected back office to manage everything. It runs on my VPS, and GitHub Actions keeps it up to date on its own.

What was there

The starting Symfony project is unfinished. The MVC architecture is in place and the Doctrine entities exist, but a good part of the controllers and business logic is still to be written.

The request

Complete the public site (catalogue, playlists) and add a secure back office to manage trainings, playlists and categories. Then put the whole thing online.

What I built6 features

  1. Playlists: count and sort

    A column shows how many trainings each playlist holds, sortable both ways. The same count appears on the detail page.

  2. Back office

    Adding, editing and deleting trainings, playlists and categories, with Symfony forms. Every deletion asks for confirmation.

  3. Authentication

    The admin area sits behind a login form handled by the Symfony Security component.

  4. Videos

    Each training shows its YouTube video from its id.

  5. Tests and documentation

    PHPUnit tests, documentation generated with phpDocumentor and published on its own subdomain.

  6. Continuous deployment

    A GitHub Actions workflow connects to the VPS over SSH on every push to main: git pull, composer install in production mode, cache cleared, ownership handed back to www-data.

Code excerpts2 excerpts

Code copied as is from the repositories:

The deployment pipeline YAML
name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: deploy sur le vps
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.VPS_HOST }}
          username: ${{ secrets.VPS_USER }}
          key: ${{ secrets.VPS_SSH_KEY }}
          script: |
            cd /var/www/mediatek
            git pull origin main
            composer install --no-dev --optimize-autoloader
            php bin/console cache:clear --env=prod
            chown -R www-data:www-data /var/www/mediatek
mediatek86 / .github/workflows/deploy.yml Server access (host, user, SSH key) lives in GitHub secrets, never written in the repository.
Sorting playlists by number of trainings PHP
public function findAllOrderByFormationsCount($ordre): array{
    $playlists = $this->findAll();
    $nbrFormations = [];
    foreach($playlists as $p){
        $nbrFormations[] = count($p->getFormations());
    }
    if($ordre == 'ASC'){
        array_multisort($nbrFormations, SORT_ASC, $playlists);
    }else{
        array_multisort($nbrFormations, SORT_DESC, $playlists);
    }
    return $playlists;
}
mediatek86 / src/Repository/PlaylistRepository.php It works, but the sorting happens in PHP after loading everything. See "In hindsight": an ORDER BY COUNT(f.id) is what's missing.

In hindsight4 points

What I would
do differently.

Reread today with a more systems and database minded eye. None of this kept the project from working, but all of it would matter in production.

  1. #1

    Sorting by number of trainings

    It loads every playlist, counts their trainings in PHP, then sorts the array. A single query with COUNT(), GROUP BY and ORDER BY would do the work in the database, without loading every training into memory.

  2. #2

    Deploying with git pull

    The server pulls the repository directly: if composer install fails halfway, the site is left in a broken state. I would build each release in its own folder, then switch a symbolic link, with a one-command rollback.

  3. #3

    Migrations

    The workflow does not run doctrine:migrations:migrate, so a schema change has to be applied by hand in production. I would add it to the pipeline, right after a database backup.

  4. #4

    The admin account

    It is defined in security.yaml. For several administrators, a User entity in the database with hashed passwords is cleaner, and the committed .env has to leave the repository.

Stack18 technologies

Backend

  • PHP 8.4
  • Symfony 6.4
  • Doctrine ORM
  • PHPUnit
  • phpDocumentor

Frontend

  • Twig
  • HTML / CSS
  • JavaScript

Data

  • MySQL
  • Doctrine Migrations

Infra

  • OVH VPS
  • Ubuntu
  • nginx
  • PHP-FPM
  • GitHub Actions

Tools

  • Composer
  • Symfony CLI
  • Git

Demovideo

The video only loads when you click it, so there is no YouTube cookie until you ask for one.

BTS SIO framework12 skills

The framework competencies this project puts to work.

B1IT service support and delivery

  • B1.2Handle incidents and requests for support and changes
  • B1.3Develop the organisation's online presence
  • B1.4Work in project mode
  • B1.5Make an IT service available to users

B2Application design and development (SLAM)

  • B2.1.1Model an application solution
  • B2.1.3Develop an application solution
  • B2.1.4Design and build a user interface
  • B2.2.1Gather, analyse and update information about an application solution
  • B2.2.4Update technical and user documentation
  • B2.2.5Design and run tests for the updated components
  • B2.3.1Design or adapt a database
  • B2.3.2Carry out operations on a database