Module 11 Lesson 3: Legacy PHP Conversion
·DevOps

Module 11 Lesson 3: Legacy PHP Conversion

Modernizing the old. A step-by-step case study of taking a manual, high-risk PHP/MySQL application and transforming it into a fully automated containerized pipeline.

Module 11 Lesson 3: Case Study: Legacy PHP

In this study, we help "GreenGrocer," a 10-year-old e-commerce site using PHP 5.6, Apache, and Global variables.

1. The Starting Point

  • Deployment: A developer manually drags files via FileZilla (FTP).
  • Risk: "Testing" happens live on the production server.
  • Failures: The site goes down for 30 minutes every time they "Fix" a bug.

2. The Transformation Strategy

  1. Step 1: The Dockerfile: Wrap the old app in a Docker container (Review Docker Module 14).
  2. Step 2: Basic CI: Create a pipeline that just checks for syntax errors (php -l).
  3. Step 3: Staging Environment: Use Docker Compose to spin up a "Mirror" of the production site for testing.

3. The Blueprint (.gitlab-ci.yml)

stages: [check, deploy]

# Catch the obvious bugs first
lint:
  stage: check
  image: php:5.6-apache
  script:
    - find . -name "*.php" -exec php -l {} \;

# Automating the "FTP" process using SSH (Module 6)
push-to-prod:
  stage: deploy
  script:
    - rsync -avz --exclude '.git' ./ user@production-server:/var/www/html/
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
      when: manual # Required human approval to stop "Accidental Pushes"

4. The Result

  • Zero "Lost" Files: By using rsync via GitLab, they no longer "Forget" to upload a specific CSS file.
  • Rollbacks: If the rsync breaks something, they can use the Environments tab to redeploy the previous commit.
  • Confidence: The 2-minute "Lint" check caught 3 missing semicolons in the first week, preventing 3 separate outages.

Exercise: The Modernizer's Map

  1. Why did we use rsync instead of building a full Docker image for the first step? (Hint: Speed of migration).
  2. If you were the lead developer, what is the FIRST automated test you would write for a 10-year-old PHP app?
  3. How would you convince the CEO that "Filesystem drag-and-drop" is a security risk?
  4. Research: What is "Phan" or "PHPStan", and could they be used in the check stage for legacy code?

Summary

Legacy modernization isn't about throwing away the old code; it's about putting a Safety Net around it. By automating the delivery of a PHP app, you remove the "Human Anxiety" and allow the team to start refactoring with confidence.

Next Lesson: High stakes: Case Study: Highly Secure Bank Application.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn