# Shared Hosting Deployment

This project is prepared for Python shared hosting environments such as cPanel + Passenger.

If you are deploying specifically to Namecheap shared hosting, use `NAMECHEAP_SHARED_HOSTING.md` as the primary guide. It contains the exact `Setup Python App` values, storage paths, and upload policy recommended for Namecheap.

## Recommended layout

```text
/home/username/
|-- khf_ticketing/               # application code
|-- khf_ticketing/instance/      # instance config area
|-- khf_ticketing_data/          # writable storage outside public web root
|   |-- uploads/
|   |-- tmp/
|   `-- logs/
`-- public_html/                 # web root managed by hosting
```

## Required environment values

- `FLASK_CONFIG=shared`
- `DATABASE_URL=mysql+pymysql://USER:PASSWORD@HOST:3306/DBNAME`
- `SECRET_KEY=<strong-random-secret>`
- `DATA_ROOT=/home/username/khf_ticketing_data`
- `UPLOAD_ROOT=/home/username/khf_ticketing_data/uploads`
- `FILE_STORAGE_PATH=/home/username/khf_ticketing_data/uploads`
- `TEMP_UPLOAD_DIR=/home/username/khf_ticketing_data/tmp`
- `LOG_DIR=/home/username/khf_ticketing_data/logs`
- `DB_POOL_CLASS=null`
- `TRUST_PROXY_FIX=1`

## Passenger startup

Use `passenger_wsgi.py` as the startup file if your panel asks for an application entrypoint.

If the panel expects a WSGI callable file, use `wsgi.py` and the callable `application`.

## Storage rules

- Keep uploads outside `public_html`
- Do not use `app/static/uploads` on shared hosting
- Ensure the hosting account can write to `uploads`, `tmp`, and `logs`
- Downloads are served through Flask authorization checks
- `FILE_STORAGE_PATH`, `MAX_UPLOAD_SIZE_MB`, and `ALLOWED_UPLOAD_EXTENSIONS` can override database settings during deployment
- Avoid using wildcard upload extensions on shared hosting
- Keep upload sizes conservative to stay within hosting resource limits

## Database notes

- Shared hosting usually limits concurrent MySQL connections
- `DB_POOL_CLASS=null` is recommended to avoid idle pooled connections
- If your provider allows small pools, set `DB_POOL_SIZE=2` and `DB_MAX_OVERFLOW=1`

## First deployment

1. Upload the project code to your application directory.
2. Create the writable folders:
   - `khf_ticketing_data/uploads`
   - `khf_ticketing_data/tmp`
   - `khf_ticketing_data/logs`
3. Create the MySQL database and user from the hosting panel.
4. Install Python dependencies in the hosting virtual environment.
5. Configure environment variables in the panel or shell profile.
6. Import `database/mysql_schema.sql` or run migrations if supported.
7. Seed defaults with `python scripts/seed_data.py`.
8. Restart the Python application from the hosting panel.
