Deployment Overview
ESP Website deployments follow a traditional server-based model using Apache with mod_wsgi, PostgreSQL, and Exim4 for email. Each chapter site runs in its own directory under/lu/sites with shared system dependencies.
Production Architecture
- Web Server: Apache 2.x with mod_wsgi
- Database: PostgreSQL 14+
- Cache: Memcached
- Email: Exim4 with mailgate support
- OS: Ubuntu 22.04 LTS (current supported version)
Deploying a New Site
To deploy a new chapter site, you’ll need the following information:- The hostname the chapter prefers
- The chapter’s contact email address
- The group’s name (e.g., “MIT ESP” or “Yale Splash”)
- The chapter’s preferred theme
Deployment Steps
-
SSH to the production server:
-
Run the site setup script:
-
Follow the interactive prompts to configure:
- Site directory name (choose something short and unique)
- Database credentials
- Site settings
- Initial superuser account
If the directory already exists for the chapter, you may wish to delete it first to get a clean start. Alternatively, clone the repository yourself,
cd into it, and run the script from there.Troubleshooting Setup
If something fails during setup:- Re-run specific steps using appropriate flags with
new_site.sh - Note that some steps won’t work if run twice
- The script remembers your settings; just specify the same directory
- Manually run migrations if needed:
Post-Deployment
After successfully deploying:- Email the chapter with:
- Confirmation that their site is ready
- Instructions for creating accounts
- Documentation links (repository docs, LU wiki, websupport)
- Any theme configuration notes
Configuration Files
Local Settings
Each site has alocal_settings.py file that overrides default Django settings. Key configuration:
Apache Configuration
Apache virtual host configuration template (/etc/apache2/sites-available/esp_sites.conf):
WSGI Configuration
Theesp.wsgi file handles Django application loading:
Managing Deployments
Pulling New Code
For production updates:-
Navigate to the site directory:
-
Pull latest changes:
-
Update dependencies:
-
Run migrations:
-
Collect static files:
-
Reload Apache:
Urgent Fixes (MIT-Specific)
For urgent production fixes that can’t wait for full review:Setting Up a New Server
When replacing or setting up a new production host:1. Install Base System
2. Install System Dependencies
3. Configure Services
PostgreSQL:- Configure for internet site with smarthost if needed
- Set up mailgate configuration in
/etc/exim4/conf.d
4. Migrate Site Data
From the old server:-
Copy site directories:
-
Copy configuration files:
/etc/apache2/sites-available/esp_sites.conf/etc/crontab/etc/exim4/update-exim4.conf.conf- Any custom files under
/etc/exim4/conf.d
-
Dump and restore databases:
5. Enable Services
6. Validate Deployment
For each chapter site:-
Run migrations:
-
Test key functionality:
- User login and admin interface
- Representative program pages
- Outbound email delivery
-
Monitor logs:
7. DNS and TLS
Before final cutover:- Verify DNS A records point to new server
- Set up TLS certificates (Let’s Encrypt recommended)
- Verify MX records for email delivery
- Test from external networks
8. Cutover Strategy
- Choose a low-traffic window
- Update DNS to point to new server
- Monitor logs and error rates closely
- Keep old server available for quick rollback
- After 24-48 hours of stability, decommission old server
Deactivating a Site
To deactivate a chapter site:-
Comment out or remove site configuration:
- Lines in
/etc/apache2/sites-available/esp_sites.conf - Cron jobs in
/etc/crontab - Email routing in
/etc/exim4/update-exim4.conf.conf
- Lines in
-
Archive the site directory:
-
Reload services:
Docker Deployment (Development)
For local development, use Docker Compose:- Web service: Django app on port 8000
- Database service: PostgreSQL 14 on port 5432
- Cache service: Memcached on port 11211
Environment Variables
Key environment variables for production:DJANGO_SETTINGS_MODULE: Set toesp.settingsVIRTUAL_ENV: Path to virtualenv (if using)SECRET_KEY: Unique secret key per site
Monitoring and Maintenance
Log Locations
- Apache errors:
/var/log/apache2/[sitename]-error.log - Exim mail logs:
/var/log/exim4/mainlog - PostgreSQL:
/var/log/postgresql/
Regular Maintenance
- Monitor disk space in media directories
- Rotate logs regularly
- Update system packages monthly
- Review and archive old program data
- Test backups quarterly
Database Backups
Troubleshooting
Common Issues
500 Internal Server Error:- Check Apache error logs
- Verify
esp.wsgiconfiguration - Ensure database is accessible
- Check file permissions
- Verify PostgreSQL is running
- Check credentials in
local_settings.py - Ensure database exists
- Check Exim configuration
- Verify MX records
- Test with
python manage.py shell:
Security Considerations
- Keep
SECRET_KEYunique per site and never commit to version control - Use strong database passwords
- Enable HTTPS with valid TLS certificates
- Restrict database access to localhost when possible
- Regularly update system packages and dependencies
- Set appropriate file permissions (644 for files, 755 for directories)
- Review Apache and firewall configurations