Skip to main content

Overview

This guide covers common issues you may encounter with Wecode, along with diagnostic steps and solutions.

Common Installation Issues

Composer Installation Fails

Symptoms:
  • composer install fails with download errors
  • Hash verification fails during install.sh
Solutions:
# 1. Check PHP version
php -v  # Should be 8.4 or higher

# 2. Check memory limit
php -i | grep memory_limit  # Should be at least 512M

# 3. Increase memory for Composer
php -d memory_limit=-1 composer.phar install

# 4. Clear Composer cache
composer clear-cache
composer install

# 5. Download Composer manually
wget https://getcomposer.org/composer.phar
php composer.phar install

# 6. Use verbose mode to see errors
composer install -vvv

Migration Failures

Symptoms:
  • php artisan migrate fails with SQL errors
  • “SQLSTATE[42000]” errors
Solutions:
# 1. Check database connection
php artisan migrate:status

# 2. Verify .env database settings
cat .env | grep DB_

# Test connection manually
mysql -u wecode_user -p wecode_db -e "SELECT 1;"

# 3. Check database exists
mysql -u root -p
SHOW DATABASES;
SELECT USER FROM mysql.user WHERE USER='wecode_user';
EXIT;

# 4. Recreate database if needed
mysql -u root -p
DROP DATABASE IF EXISTS wecode_db;
CREATE DATABASE wecode_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON wecode_db.* TO 'wecode_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

# 5. Run migrations again
php artisan migrate:fresh
php artisan db:seed --class=installation_seeding

Permission Denied Errors

Symptoms:
  • “Permission denied” when running scripts
  • Web server cannot write to storage
Solutions:
# 1. Make scripts executable
chmod +x install.sh setup.sh

# 2. Fix directory ownership
sudo chown -R www-data:www-data /var/www/wecode

# 3. Fix storage permissions
sudo chmod -R 775 /var/www/wecode/storage
sudo chmod -R 775 /var/www/wecode/bootstrap/cache

# 4. Fix assignments/tester folders
sudo chown -R www-data:www-data /var/wecode-data
sudo chmod -R 775 /var/wecode-data

# 5. Check SELinux (if on RedHat/CentOS)
getenforce  # Check if enforcing
sudo setenforce 0  # Temporarily disable for testing
# If this fixes it, configure SELinux properly:
sudo setsebool -P httpd_unified 1
sudo setsebool -P httpd_can_network_connect 1

Application Key Missing

Symptoms:
  • “No application encryption key has been specified”
  • Blank page or 500 error
Solutions:
# 1. Generate application key
php artisan key:generate

# 2. Verify .env file has APP_KEY
grep APP_KEY .env

# 3. If .env doesn't exist
cp .env.example .env
php artisan key:generate

# 4. Clear config cache
php artisan config:clear
php artisan config:cache

Docker Permission Errors

Docker Socket Permission Denied

Symptoms:
  • “permission denied while trying to connect to Docker daemon socket”
  • Code execution fails
Solutions:
# 1. Add web server user to docker group
sudo usermod -aG docker www-data

# 2. Verify group membership
groups www-data
# Should show: www-data : www-data docker

# 3. Fix socket permissions
sudo chmod 660 /var/run/docker.sock
sudo chown root:docker /var/run/docker.sock

# 4. Restart web server (to apply group changes)
sudo systemctl restart nginx php8.4-fpm

# 5. Test Docker access
sudo -u www-data docker ps
# Should list containers without error

Docker Container Fails to Start

Symptoms:
  • Student code execution fails
  • “Error response from daemon: container not found”
Solutions:
# 1. Check Docker is running
sudo systemctl status docker
sudo systemctl start docker

# 2. Verify Docker images
docker images

# 3. Pull required images
docker pull gcc:latest
docker pull python:3.11
docker pull openjdk:17

# 4. Check container logs
docker ps -a  # List all containers
docker logs <container_id>

# 5. Clean up stopped containers
docker container prune

# 6. Check disk space
df -h
docker system df

Docker Out of Disk Space

Symptoms:
  • “no space left on device”
  • Container creation fails
Solutions:
# 1. Check Docker disk usage
docker system df

# 2. Remove unused containers
docker container prune -f

# 3. Remove unused images
docker image prune -a -f

# 4. Remove unused volumes
docker volume prune -f

# 5. Full cleanup (careful!)
docker system prune -a --volumes -f

# 6. Configure Docker cleanup
# /etc/docker/daemon.json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

sudo systemctl restart docker

Database Connection Issues

Connection Refused

Symptoms:
  • “SQLSTATE[HY000] [2002] Connection refused”
  • Cannot connect to database
Solutions:
# 1. Check database is running
sudo systemctl status mariadb  # or mysql
sudo systemctl start mariadb

# 2. Verify connection settings in .env
DB_HOST=localhost  # Not 127.0.0.1 if using socket
DB_PORT=3306
DB_DATABASE=wecode_db
DB_USERNAME=wecode_user

# 3. Test connection manually
mysql -h localhost -u wecode_user -p wecode_db

# 4. Check database is listening
sudo netstat -tlnp | grep 3306
# or
sudo ss -tlnp | grep 3306

# 5. Check bind address in MySQL config
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# bind-address should be 127.0.0.1 or 0.0.0.0

sudo systemctl restart mariadb

Access Denied for User

Symptoms:
  • “SQLSTATE[HY000] [1045] Access denied for user”
Solutions:
# 1. Verify credentials in .env
cat .env | grep DB_

# 2. Test credentials
mysql -u wecode_user -p
# Enter password from .env

# 3. Reset user password
mysql -u root -p
ALTER USER 'wecode_user'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
EXIT;

# Update .env with new password
DB_PASSWORD=new_password

# 4. Grant permissions
mysql -u root -p
GRANT ALL ON wecode_db.* TO 'wecode_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

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

Too Many Connections

Symptoms:
  • “SQLSTATE[HY000] [1040] Too many connections”
Solutions:
# 1. Check current connections
mysql -u root -p
SHOW PROCESSLIST;
SHOW STATUS WHERE Variable_name = 'Threads_connected';
EXIT;

# 2. Increase max connections
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# Add or modify:
max_connections = 200

sudo systemctl restart mariadb

# 3. Optimize Laravel database connections
# .env
DB_CONNECTION_TIMEOUT=60

# config/database.php
'mysql' => [
    // ...
    'pool' => [
        'min' => 2,
        'max' => 10,
    ],
],

# 4. Check for connection leaks
# Review code for unclosed connections

File Permission Problems

Cannot Write to Storage

Symptoms:
  • “file_put_contents(): failed to open stream: Permission denied”
  • Logs not being written
Solutions:
# 1. Fix storage permissions
sudo chown -R www-data:www-data /var/www/wecode/storage
sudo chmod -R 775 /var/www/wecode/storage

# 2. Verify directory structure
ls -la /var/www/wecode/storage/
# Should show: drwxrwxr-x www-data www-data

# 3. Create missing directories
mkdir -p /var/www/wecode/storage/logs
mkdir -p /var/www/wecode/storage/framework/cache
mkdir -p /var/www/wecode/storage/framework/sessions
mkdir -p /var/www/wecode/storage/framework/views

sudo chown -R www-data:www-data /var/www/wecode/storage
sudo chmod -R 775 /var/www/wecode/storage

# 4. Check bootstrap/cache
sudo chown -R www-data:www-data /var/www/wecode/bootstrap/cache
sudo chmod -R 775 /var/www/wecode/bootstrap/cache

Cannot Access Assignments Folder

Symptoms:
  • Submitted files not saving
  • “Failed to open stream” errors for assignments
Solutions:
# 1. Verify folder location
# In Wecode Settings page, check:
# - Assignments Path
# - Tester Path

# 2. Create folders if missing
sudo mkdir -p /var/wecode-data/assignments
sudo mkdir -p /var/wecode-data/tester

# 3. Set ownership
sudo chown -R www-data:www-data /var/wecode-data

# 4. Set permissions
sudo chmod -R 775 /var/wecode-data

# 5. Test write access
sudo -u www-data touch /var/wecode-data/assignments/test.txt
# Should succeed

# 6. Check path in database
mysql -u wecode_user -p wecode_db
SELECT * FROM settings WHERE setting_name LIKE '%path%';
EXIT;

Queue Processing Issues

Queue Workers Not Processing Jobs

Symptoms:
  • Submissions stuck in queue
  • No code execution happening
Solutions:
# 1. Check queue connection in .env
cat .env | grep QUEUE_CONNECTION
# Should be: QUEUE_CONNECTION=redis (or database)

# 2. Verify Redis is running (if using Redis)
sudo systemctl status redis
sudo systemctl start redis
redis-cli ping  # Should respond "PONG"

# 3. Check queue status
php artisan queue:work --once  # Process one job
php artisan queue:failed  # List failed jobs

# 4. Start queue worker manually
php artisan queue:work --verbose
# Watch for errors

# 5. Check queue worker service
sudo systemctl status wecode-worker
sudo systemctl start wecode-worker
sudo journalctl -u wecode-worker -f

# 6. Restart queue workers
php artisan queue:restart

Queue Worker Systemd Service

Create /etc/systemd/system/wecode-worker.service:
[Unit]
Description=Wecode Queue Worker
After=network.target

[Service]
Type=simple
User=www-data
Group=www-data
Restart=always
RestartSec=3
WorkingDirectory=/var/www/wecode
ExecStart=/usr/bin/php /var/www/wecode/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
StandardOutput=append:/var/log/wecode-worker.log
StandardError=append:/var/log/wecode-worker.log

[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable wecode-worker
sudo systemctl start wecode-worker
sudo systemctl status wecode-worker

Failed Jobs

Solutions:
# 1. List failed jobs
php artisan queue:failed

# 2. View failed job details
php artisan queue:failed | grep "ID:"

# 3. Retry specific job
php artisan queue:retry <job-id>

# 4. Retry all failed jobs
php artisan queue:retry all

# 5. Clear failed jobs
php artisan queue:flush

# 6. Check failed jobs table
mysql -u wecode_user -p wecode_db
SELECT * FROM failed_jobs ORDER BY failed_at DESC LIMIT 10;
EXIT;

Moss Integration Problems

Moss Connection Fails

Symptoms:
  • Plagiarism detection not working
  • Timeout connecting to Moss server
Solutions:
# 1. Check Moss user ID in .env
cat .env | grep MOSS
# Should have: MOSS_USER_ID=your_moss_id

# 2. Test network connectivity
telnet moss.stanford.edu 7690
# Should connect

# 3. Check firewall allows outbound connections
sudo ufw status
sudo ufw allow out 7690/tcp

# 4. Test Moss submission manually
perl -v  # Ensure Perl is installed

# 5. Verify Moss script location
ls -la /var/www/wecode/moss  # or wherever Moss script is

# 6. Check Moss script permissions
chmod +x /var/www/wecode/moss

Perl Not Found

Symptoms:
  • “perl: command not found”
  • Moss integration fails
Solutions:
# 1. Install Perl
sudo apt update
sudo apt install perl

# 2. Verify installation
perl -v
which perl  # Should show /usr/bin/perl

# 3. Update Moss script shebang if needed
head -1 /var/www/wecode/moss
# Should be: #!/usr/bin/perl or #!/usr/bin/env perl

Debug Mode and Logs

Enable Debug Mode (Development Only)

Never enable debug mode in production. It exposes sensitive information.
# .env
APP_DEBUG=true
APP_ENV=local

# Clear config cache
php artisan config:clear

Laravel Logs

# View latest logs
tail -f /var/www/wecode/storage/logs/laravel.log

# Search for errors
grep -i "error" /var/www/wecode/storage/logs/laravel.log

# View last 100 errors
grep -i "error" /var/www/wecode/storage/logs/laravel.log | tail -100

# Check log file size
du -h /var/www/wecode/storage/logs/laravel.log

# Rotate logs if too large
mv /var/www/wecode/storage/logs/laravel.log /var/www/wecode/storage/logs/laravel.log.old
touch /var/www/wecode/storage/logs/laravel.log
sudo chown www-data:www-data /var/www/wecode/storage/logs/laravel.log

Web Server Logs

Nginx

# Error log
tail -f /var/log/nginx/error.log

# Access log
tail -f /var/log/nginx/access.log

# Wecode-specific logs (if configured)
tail -f /var/log/nginx/wecode_error.log

Apache

# Error log
tail -f /var/log/apache2/error.log

# Access log
tail -f /var/log/apache2/access.log

PHP Logs

# PHP-FPM error log
tail -f /var/log/php8.4-fpm.log

# Or check configured log path
php -i | grep error_log

# System PHP errors
tail -f /var/log/syslog | grep php

Docker Logs

# All containers
docker compose logs -f

# Specific service
docker compose logs -f laravel.test

# Last 100 lines
docker compose logs --tail=100

# Container logs by ID
docker logs <container_id>

Performance Issues

Slow Page Load

Solutions:
# 1. Enable caching
php artisan config:cache
php artisan route:cache
php artisan view:cache

# 2. Optimize Composer autoloader
composer dump-autoload -o

# 3. Enable OPcache
sudo nano /etc/php/8.4/fpm/php.ini
# Uncomment and configure:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60

sudo systemctl restart php8.4-fpm

# 4. Use Redis for cache/sessions
# .env
CACHE_DRIVER=redis
SESSION_DRIVER=redis

# 5. Check database slow query log
mysql -u root -p
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 2;
SHOW VARIABLES LIKE 'slow_query_log%';
EXIT;

High Memory Usage

Solutions:
# 1. Check memory usage
free -h
top -o %MEM

# 2. Reduce PHP memory limit
sudo nano /etc/php/8.4/fpm/php.ini
memory_limit = 256M  # Adjust as needed

# 3. Optimize queue workers
# Restart workers periodically
php artisan queue:restart

# Or add to queue worker config:
php artisan queue:work --max-time=3600 --memory=512

# 4. Clear caches
php artisan cache:clear

# 5. Check for memory leaks
sudo systemctl restart php8.4-fpm

Network and Connectivity

502 Bad Gateway

Symptoms:
  • Nginx shows “502 Bad Gateway”
Solutions:
# 1. Check PHP-FPM is running
sudo systemctl status php8.4-fpm
sudo systemctl start php8.4-fpm

# 2. Check PHP-FPM socket
ls -la /var/run/php/php8.4-fpm.sock
# Should exist with www-data ownership

# 3. Verify Nginx configuration
sudo nginx -t

# 4. Check fastcgi_pass in Nginx config
sudo nano /etc/nginx/sites-available/wecode
# Should match: fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;

# 5. Check logs
tail -f /var/log/nginx/error.log
tail -f /var/log/php8.4-fpm.log

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

404 Not Found

Solutions:
# 1. Check document root
sudo nano /etc/nginx/sites-available/wecode
# root should point to: /var/www/wecode/public;

# 2. Check .htaccess (Apache) or try_files (Nginx)
# Nginx needs:
location / {
    try_files $uri $uri/ /index.php?$query_string;
}

# 3. Enable rewrite module (Apache)
sudo a2enmod rewrite
sudo systemctl restart apache2

# 4. Clear route cache
php artisan route:clear
php artisan route:cache

Diagnostic Commands

System Information

# Laravel version and environment
php artisan about

# PHP configuration
php -i | less
php -m  # List modules

# Check all requirements
php artisan optimize
php artisan config:show

# Database connection test
php artisan tinker
>>> DB::connection()->getPdo();
>>> exit

# Check disk space
df -h
du -sh /var/www/wecode/*

# Check running processes
ps aux | grep php
ps aux | grep nginx
ps aux | grep mysql

Health Check Script

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

echo "=== Wecode Health Check ==="
echo ""

# 1. Web server
echo "[Web Server]"
systemctl is-active nginx >/dev/null 2>&1 && echo "✓ Nginx running" || echo "✗ Nginx stopped"

# 2. PHP-FPM
echo "[PHP-FPM]"
systemctl is-active php8.4-fpm >/dev/null 2>&1 && echo "✓ PHP-FPM running" || echo "✗ PHP-FPM stopped"

# 3. Database
echo "[Database]"
systemctl is-active mariadb >/dev/null 2>&1 && echo "✓ MariaDB running" || echo "✗ MariaDB stopped"

# 4. Redis
echo "[Redis]"
redis-cli ping >/dev/null 2>&1 && echo "✓ Redis running" || echo "✗ Redis stopped"

# 5. Docker
echo "[Docker]"
systemctl is-active docker >/dev/null 2>&1 && echo "✓ Docker running" || echo "✗ Docker stopped"

# 6. Disk space
echo "[Disk Space]"
df -h / | awk 'NR==2 {print "Used: " $5 " (" $3 " / " $2 ")"}'

# 7. Laravel
echo "[Laravel]"
cd /var/www/wecode
php artisan migrate:status >/dev/null 2>&1 && echo "✓ Database connected" || echo "✗ Database connection failed"

echo ""
echo "=== End Health Check ==="

Getting Help

If issues persist:
  1. Check Laravel logs: storage/logs/laravel.log
  2. Enable debug mode (temporarily, in development only)
  3. Search GitHub issues: https://github.com/truongan/wecode/issues
  4. Review Wecode documentation: https://github.com/truongan/wecode-judge/tree/docs
  5. Check Laravel docs: https://laravel.com/docs
  6. Ask in forums: Stack Overflow, Laravel forums

Next Steps

Build docs developers (and LLMs) love