
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
- Step 1: The Dockerfile: Wrap the old app in a Docker container (Review Docker Module 14).
- Step 2: Basic CI: Create a pipeline that just checks for syntax errors (
php -l). - 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
rsyncvia 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
- Why did we use
rsyncinstead of building a full Docker image for the first step? (Hint: Speed of migration). - If you were the lead developer, what is the FIRST automated test you would write for a 10-year-old PHP app?
- How would you convince the CEO that "Filesystem drag-and-drop" is a security risk?
- Research: What is "Phan" or "PHPStan", and could they be used in the
checkstage 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.