Skip to main content

Overview

Keeping Wecode updated ensures you have the latest features, bug fixes, and security patches. This guide covers update procedures for the application, dependencies, and system components.
Always back up your database and files before performing any updates. See Backup Guide for details.

Pre-Update Checklist

Before updating, ensure:
  • Full backup completed (database + files)
  • Maintenance window scheduled
  • Update plan documented
  • Rollback plan prepared
  • Team notified of downtime
  • Test environment available (recommended)

Application Update Workflow

Standard Update Process

# 1. Enable maintenance mode
cd /var/www/wecode
php artisan down --message="Updating Wecode, back soon!" --retry=60

# 2. Backup current state
mysqldump -u wecode_user -p wecode_db | gzip > "backup_$(date +%Y%m%d_%H%M%S).sql.gz"
tar -czf "files_$(date +%Y%m%d_%H%M%S).tar.gz" /var/wecode-data/

# 3. Pull latest changes from repository
git fetch origin
git status  # Check for local changes
git pull origin main  # or master, or specific branch

# 4. Update dependencies
composer install --no-dev --optimize-autoloader

# 5. Run database migrations
php artisan migrate --force

# 6. Clear and rebuild caches
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear

php artisan config:cache
php artisan route:cache
php artisan view:cache

# 7. Update file permissions
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

# 8. Restart services
sudo systemctl restart php8.4-fpm
sudo systemctl restart nginx  # or apache2

# 9. Verify application
php artisan migrate:status
php artisan queue:restart  # If using queue workers

# 10. Disable maintenance mode
php artisan up

Git Pull Workflow

Check for Updates

cd /var/www/wecode

# Check current version/commit
git log -1 --oneline

# Fetch latest changes without applying
git fetch origin

# View what will be updated
git log HEAD..origin/main --oneline

# View file changes
git diff HEAD..origin/main --stat

Handle Local Changes

If you have local modifications:
# Option 1: Stash changes (preserve local edits)
git stash save "Local changes before update"
git pull origin main
git stash pop  # Reapply changes (may need manual merge)

# Option 2: Commit local changes
git add .
git commit -m "Local customizations"
git pull origin main  # May create merge commit

# Option 3: Discard local changes (careful!)
git reset --hard origin/main  # DESTRUCTIVE: loses local changes

Update Specific Version

# List available tags/releases
git tag -l

# Checkout specific version
git checkout v2.0.0

# Or specific branch
git checkout develop

Running Migrations

Check Migration Status

# View current migration status
php artisan migrate:status
Output example:
+------+------------------------------------------------+-------+
| Ran? | Migration                                      | Batch |
+------+------------------------------------------------+-------+
| Yes  | 2014_10_12_000000_create_users_table          | 1     |
| Yes  | 2014_10_12_100000_create_password_resets_table| 1     |
| No   | 2024_03_01_add_moss_integration               | -     |
+------+------------------------------------------------+-------+

Run Pending Migrations

# Run migrations (production)
php artisan migrate --force

# The --force flag is required in production (when APP_ENV=production)
# It bypasses the confirmation prompt

Preview Migrations

# See SQL that will be executed (without running)
php artisan migrate --pretend

Rollback Migrations

If an update causes issues:
# Rollback last batch of migrations
php artisan migrate:rollback

# Rollback specific number of batches
php artisan migrate:rollback --step=2

# Rollback all migrations (dangerous!)
php artisan migrate:reset
Always test migrations on a staging environment first. Some migrations may be irreversible or cause data loss.

Composer Updates

Update All Dependencies

# Update all packages
composer update

# Update with optimizations for production
composer update --no-dev --optimize-autoloader

Update Specific Packages

# Update Laravel framework only
composer update laravel/framework

# Update multiple packages
composer update laravel/framework laravel/sail

Check for Outdated Packages

# List outdated packages
composer outdated

# Direct dependencies only
composer outdated --direct

Security Updates

# Check for security vulnerabilities
composer audit

# Update packages with security fixes
composer update --with-dependencies

Handle Dependency Conflicts

# If update fails due to conflicts
composer why-not laravel/framework 12.0

# Try updating with broader constraints
composer update --with-all-dependencies

# Clear composer cache
composer clear-cache
composer update

Clearing Caches

Application Caches

# Clear all caches
php artisan cache:clear          # Application cache
php artisan config:clear         # Configuration cache
php artisan route:clear          # Route cache
php artisan view:clear           # Compiled views
php artisan event:clear          # Event cache

# Clear compiled files
php artisan clear-compiled

Rebuild Caches (Production)

After clearing, rebuild for performance:
# Rebuild caches
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

OPcache (PHP)

# Restart PHP-FPM to clear OPcache
sudo systemctl restart php8.4-fpm

# Or reload gracefully
sudo systemctl reload php8.4-fpm

Redis Cache

If using Redis for caching:
# Flush all Redis data (careful!)
redis-cli FLUSHALL

# Flush specific database
redis-cli -n 0 FLUSHDB

# More targeted: clear Laravel cache only
php artisan cache:clear  # Uses configured cache driver

Version Upgrade Notes

Laravel Framework Upgrades

Wecode is built on Laravel. Major Laravel upgrades require careful planning.

Laravel 7 → Laravel 12

This is a major upgrade spanning multiple Laravel versions. Review official Laravel upgrade guides for each version.
Key changes to review:
  • PHP version requirements (8.4+)
  • Breaking changes in each Laravel version (8, 9, 10, 11, 12)
  • Updated configuration files
  • Deprecated helper functions
  • Database schema changes
Upgrade process:
# 1. Review upgrade guides
# Laravel 8: https://laravel.com/docs/8.x/upgrade
# Laravel 9: https://laravel.com/docs/9.x/upgrade
# Laravel 10: https://laravel.com/docs/10.x/upgrade
# Laravel 11: https://laravel.com/docs/11.x/upgrade
# Laravel 12: https://laravel.com/docs/12.x/upgrade

# 2. Update composer.json
# Change Laravel version requirement
nano composer.json
# "laravel/framework": "^12.0"

# 3. Update dependencies
composer update

# 4. Update configuration files
# Compare with fresh Laravel installation
php artisan vendor:publish --tag=config

# 5. Run migrations
php artisan migrate

# 6. Test thoroughly
php artisan test  # If tests exist

PHP Version Upgrades

Upgrading to PHP 8.4

# 1. Add PHP repository (Ubuntu)
sudo add-apt-repository ppa:ondrej/php
sudo apt update

# 2. Install PHP 8.4
sudo apt install php8.4 php8.4-fpm php8.4-mysql php8.4-mbstring \
    php8.4-xml php8.4-curl php8.4-zip php8.4-gd php8.4-bcmath

# 3. Update web server configuration
# Nginx: Update fastcgi_pass in site config
sudo nano /etc/nginx/sites-available/wecode
# Change: fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;

# 4. Restart services
sudo systemctl restart php8.4-fpm nginx

# 5. Verify PHP version
php -v
php artisan --version

# 6. Disable old PHP version (optional)
sudo systemctl stop php8.1-fpm
sudo systemctl disable php8.1-fpm

Database Upgrades

MySQL/MariaDB Upgrades

# 1. Backup database
mysqldump -u root -p --all-databases | gzip > all_databases_backup.sql.gz

# 2. Update package
sudo apt update
sudo apt upgrade mariadb-server

# 3. Run upgrade script
sudo mysql_upgrade -u root -p

# 4. Restart database
sudo systemctl restart mariadb

# 5. Verify
mysql --version
mysql -u root -p -e "SELECT VERSION();"

Docker Compose Updates

Update Laravel Sail

# Update Sail package
composer update laravel/sail

# Republish Sail files
php artisan sail:install

# Rebuild containers
sail down
sail build --no-cache
sail up -d

Update Docker Images

# Pull latest images
docker compose pull

# Recreate containers with new images
docker compose up -d --build

# Remove old images
docker image prune -a

Update compose.yaml

If compose.yaml changes in the repository:
# 1. Backup current compose file
cp compose.yaml compose.yaml.backup

# 2. Update from repository
git pull origin main

# 3. Compare changes
diff compose.yaml.backup compose.yaml

# 4. Apply changes and rebuild
docker compose down
docker compose up -d --build

Queue Workers Update

After updating, restart queue workers:
# Restart queue workers gracefully
php artisan queue:restart

# Or restart systemd service
sudo systemctl restart wecode-worker

# Verify workers are running
php artisan queue:work --once  # Test single job

Automated Update Script

Create /usr/local/bin/wecode-update.sh:
#!/bin/bash

set -e  # Exit on error

WECODE_DIR="/var/www/wecode"
BACKUP_DIR="/var/backups/wecode/pre-update"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)

echo "=== Wecode Update Script ==="
echo "Timestamp: $TIMESTAMP"

# Create backup directory
mkdir -p "$BACKUP_DIR"

# 1. Backup
echo "[1/10] Creating backup..."
mysqldump -u wecode_user -p wecode_db | gzip > "$BACKUP_DIR/db_$TIMESTAMP.sql.gz"

# 2. Maintenance mode
echo "[2/10] Enabling maintenance mode..."
cd "$WECODE_DIR"
php artisan down

# 3. Git pull
echo "[3/10] Pulling latest changes..."
git pull origin main

# 4. Composer update
echo "[4/10] Updating dependencies..."
composer install --no-dev --optimize-autoloader

# 5. Migrations
echo "[5/10] Running migrations..."
php artisan migrate --force

# 6. Clear caches
echo "[6/10] Clearing caches..."
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

# 7. Rebuild caches
echo "[7/10] Rebuilding caches..."
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 8. Permissions
echo "[8/10] Fixing permissions..."
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

# 9. Restart services
echo "[9/10] Restarting services..."
sudo systemctl restart php8.4-fpm nginx
php artisan queue:restart

# 10. Disable maintenance
echo "[10/10] Disabling maintenance mode..."
php artisan up

echo "=== Update Complete ==="
echo "Current version:"
git log -1 --oneline
Make it executable:
sudo chmod +x /usr/local/bin/wecode-update.sh

Rollback Procedure

If an update causes issues:
# 1. Enable maintenance mode
php artisan down

# 2. Restore database
zcat backup_20260304_120000.sql.gz | mysql -u wecode_user -p wecode_db

# 3. Revert code
git reflog  # Find commit hash before update
git reset --hard abc123  # Replace with actual hash

# 4. Restore dependencies
composer install

# 5. Clear caches
php artisan cache:clear
php artisan config:clear

# 6. Restart services
sudo systemctl restart php8.4-fpm nginx

# 7. Disable maintenance
php artisan up

Testing After Updates

Verification Checklist

# Check application status
php artisan about

# Verify database connection
php artisan migrate:status

# Test queue workers
php artisan queue:work --once

# Check logs for errors
tail -f storage/logs/laravel.log

# Verify web access
curl -I http://localhost

Functional Testing

  • Login as admin
  • Create test assignment
  • Submit test code
  • Verify code execution
  • Check grading
  • Test Moss integration (if used)
  • Verify file uploads
  • Check notifications
  • Test scoreboard

Update Schedule Recommendations

Regular Updates

  • Security patches: Apply immediately
  • Bug fixes: Weekly or as needed
  • Minor versions: Monthly
  • Major versions: Quarterly (with testing)

System Package Updates

# Weekly: Update system packages
sudo apt update
sudo apt upgrade

# Monthly: Check for major upgrades
sudo apt dist-upgrade

# After updates: Reboot if kernel updated
sudo reboot

Update Notifications

Monitor for Updates

# Watch Wecode repository for releases
# GitHub: Watch → Releases only

# Check for updates manually
cd /var/www/wecode
git fetch origin
git log HEAD..origin/main --oneline

Subscribe to Announcements

  • GitHub repository releases
  • Wecode mailing list (if available)
  • Laravel security announcements
  • PHP security advisories

Next Steps

Build docs developers (and LLMs) love