Overview
Wecode provides two main installation scripts:
install.sh - Core installation script that sets up the Laravel application
setup.sh - Wrapper script that handles directory setup and calls install.sh
Quick Start
Using install.sh (Simple Setup)
For a basic installation in the current directory:
./install.sh -u db_user -d database_name -p password -s "https://your-domain.com"
Using setup.sh (Advanced Setup)
For installations with separate public and private directories:
./setup.sh -i /path/to/install -o /path/to/public -u db_user -p db_password -n "Site Name"
install.sh - Core Installation
Command Syntax
./install.sh [-a admin_user_name] [-e admin_email] -u db_user -d db -p password -s site_url
Parameters
| Parameter | Required | Description | Default |
|---|
-a | No | Admin username | abc |
-e | No | Admin email address | [email protected] |
-u | Yes | Database username | - |
-d | No | Database name | Same as db_user |
-p | Yes | Database password (also used for admin) | - |
-s | Yes | Site URL with format http://... or https://... | - |
-h | No | Show help message | - |
What install.sh Does
-
Downloads and Installs Composer
# Downloads composer installer
# Verifies SHA-384 hash for security
# Installs composer.phar locally
-
Installs PHP Dependencies
php composer.phar install
Installs all Laravel and application dependencies defined in composer.json
-
Creates Environment Configuration
Creates
.env file and configures:
APP_URL - Your site URL
DB_USERNAME - Database username
DB_DATABASE - Database name
DB_PASSWORD - Database password
-
Generates Application Key
Creates a unique encryption key for the Laravel application
-
Sets Up Database
php artisan migrate:refresh
php artisan db:seed --class=installation_seeding
Creates all database tables and seeds initial data
-
Creates Admin Users
php artisan add_admin truonganpn [email protected] $password
php artisan add_admin $username $email $password
Creates default admin and your specified admin user
Example Usage
Basic Installation
./install.sh \
-u wecode_user \
-d wecode_db \
-p "SecurePassword123" \
-s "https://judge.example.com"
With Custom Admin
./install.sh \
-a "john_admin" \
-e "[email protected]" \
-u wecode_user \
-d wecode_db \
-p "SecurePassword123" \
-s "https://judge.example.com"
Error Handling
The script validates required parameters and exits with usage information if:
- Database user (
-u) is not provided
- Site URL (
-s) is not provided
- Password (
-p) is not provided
# Error example
$ ./install.sh -u myuser
usage: ./install.sh [-a admin_user_name] [-e admin_email] -u db_user -d db -p password -s site_url
setup.sh - Advanced Installation
Command Syntax
./setup.sh [-i install_dir] [-o public_dir] -u db_user -p db_password [-n site_name] [base_url]
Parameters
| Parameter | Required | Description | Default |
|---|
-i | No | Installation directory | Current working directory |
-o | No | Public directory for index.php | ../public_html relative to install dir |
-u | Yes | Database username | - |
-p | Yes | Database password | - |
-d | No | Database name | Same as db_user |
-n | No | Site name for display | Wecode-Judge |
-a | No | Default admin username | - |
-h | No | Show help message | - |
base_url | No | Base URL (positional argument) | Auto-generated if site name provided |
What setup.sh Does
-
Validates Directories
# Converts paths to absolute paths
# Checks if directories exist
-
Clones Repository
cd $install
git clone 'https://github.com/truongan/wecode' .
-
Sets Up Public Directory
- Removes existing
public folder in public directory
- Creates symbolic link:
ln -s $install/public .
- Ensures install and public directories are separate for security
-
Calls install.sh
$install/install.sh -a $default_admin_name -u $db_user -p $db_password -s "$base_url"
Example Usage
Standard Deployment
./setup.sh \
-i /var/www/wecode \
-o /var/www/html \
-u wecode_user \
-p "SecurePassword123" \
-n "CS Department Judge" \
"https://judge.cs.example.com"
Current Directory Installation
./setup.sh \
-u wecode_user \
-p "SecurePassword123" \
"https://judge.example.com"
UIT-Style Deployment
# Automatically generates base_url as https://khmt.uit.edu.vn/wecode/cs101/
./setup.sh \
-u wecode_user \
-p "SecurePassword123" \
-n "CS101"
The script will prompt for confirmation before deleting the public folder in the public directory. This action is permanent. Make sure you have backups if needed.
Directory Structure
After running setup.sh, you’ll have:
/var/www/wecode/ # Installation directory (private)
├── app/
├── config/
├── database/
├── public/ # Original public files
├── .env # Environment config
└── ...
/var/www/html/ # Public directory (web-accessible)
└── public -> /var/www/wecode/public # Symbolic link
Post-Installation Steps
1. Verify Installation
# Check if .env file was created
cat .env | grep APP_URL
# Verify database connection
php artisan migrate:status
2. Set File Permissions
# Set ownership to web server user
sudo chown -R www-data:www-data /var/www/wecode
# Set directory permissions
sudo find /var/www/wecode -type d -exec chmod 755 {} \;
# Set file permissions
sudo find /var/www/wecode -type f -exec chmod 644 {} \;
# Make storage and cache writable
sudo chmod -R 775 /var/www/wecode/storage
sudo chmod -R 775 /var/www/wecode/bootstrap/cache
Point your web server (Apache/Nginx) to the public directory:
Nginx Example:
server {
listen 80;
server_name judge.example.com;
root /var/www/html/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
4. Move Sensitive Folders
IMPORTANT: Move the assignments and tester folders outside the public directory for security.
# Create secure location
sudo mkdir -p /var/wecode-data
sudo mv /var/www/wecode/assignments /var/wecode-data/
sudo mv /var/www/wecode/tester /var/wecode-data/
# Set permissions
sudo chown -R www-data:www-data /var/wecode-data
sudo chmod -R 775 /var/wecode-data
Then update paths in the Wecode Settings page:
- Assignments Path:
/var/wecode-data/assignments
- Tester Path:
/var/wecode-data/tester
5. Set Up Docker Permissions
# Add web server user to docker group
sudo usermod -aG docker www-data
# Restart web server
sudo systemctl restart nginx # or apache2
# For systemd
sudo nano /etc/systemd/system/wecode-worker.service
See Maintenance - Queue Processing for details.
Troubleshooting Installation
Composer Installation Fails
# If hash verification fails, download manually
wget https://getcomposer.org/composer.phar
php composer.phar install
Database Connection Errors
# Test database connection
mysql -u wecode_user -p wecode_db
# Check .env file
cat .env | grep DB_
Permission Denied Errors
# Check script is executable
chmod +x install.sh setup.sh
# Run with bash explicitly
bash install.sh -u user -p pass -s https://example.com
Migration Failures
# Reset and retry
php artisan migrate:fresh
php artisan db:seed --class=installation_seeding
Next Steps
After successful installation:
- Review Security Configuration
- Set up Backups
- Configure Docker for code execution
- Access your Wecode instance and complete web-based setup