Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
- Run Pa11y for layout or functionality adjustments (skip for text-only edits).
- Run Linkinator only when links change.
- Whenever code changes touch workflows or contributor steps, update `README.md` or related docs to keep guidance accurate.
- Keep the Ubuntu installer turnkey: auto-detect Apache vs. Nginx and MySQL vs. MariaDB, seed the database by default, and ensure configuration uses the repository root even when run from another path.
- Provide containerized workflows with Docker Compose that support either MySQL or MariaDB without manual tweaks.
- Use offline-friendly validation when the network blocks npm installs: `python tools/html_checks.py <file>` and `python tools/a11y_checks.py <file>` for each modified HTML document. Prefer the standard npm-based tools when available.
- Document the exact validation commands you execute in PR summaries to streamline reviews.
49 changes: 40 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,55 @@ CREATE TABLE incident_types (id INT PRIMARY KEY, name VARCHAR(50));

## 🚀 Installation

### 1. Clone the repo
### Option A: Automated Ubuntu setup

Run the installer from the repository root (requires `sudo`):

```bash
sudo ./install_ubuntu.sh
```

Installer options:

- `--db [mysql|mariadb]` → choose the database server to install (default: auto-detects an existing install or uses `mysql`).
- `--db-name` → database name (default: `accidents`).
- `--db-user` / `--db-pass` → credentials that match `db/connect.php` defaults (`dbuser` / `dbpass`).
- `--web [apache|nginx]` → choose a web server (default: auto-detects an existing install or uses `apache`).
- `--skip-seed` → skip importing the bundled `seed.sql` file.

The script configures the chosen web server to serve this repository and seeds the database with sample data. After completion, visit [http://localhost](http://localhost).

### Option B: Docker Compose (local)

Build and start the stack (defaults to MySQL on port 3306 and the app on 8080):

```bash
docker compose up --build
```

Use `DB_IMAGE` to switch to MariaDB or change credentials/port exposure as needed:

```bash
DB_IMAGE=mariadb:11 DB_NAME=accidents DB_USER=dbuser DB_PASS=dbpass docker compose up --build
```

Access the site at [http://localhost:8080](http://localhost:8080) and the database on `localhost:3306`.

### Option C: Manual install

#### 1. Clone the repo
```bash
git clone https://github.com/ChadOhman/opensafetymap.git
cd accident-reports
```

### 2. Set up database
#### 2. Set up database
- Import schema above into MySQL
- Add reference data for categories, severity, incident types
- Create initial admin user manually

### 3. Configure DB connection
Edit `db/connect.php`:
```php
$dsn = "mysql:host=localhost;dbname=accidents;charset=utf8mb4";
$user = "your_mysql_user";
$pass = "your_mysql_pass";
```
#### 3. Configure DB connection
Edit `db/connect.php` or set environment variables for your connection details (`DB_HOST`, `DB_NAME`, `DB_USER`, `DB_PASS`).

### 4. Configure S3
- Update report submission API to upload photos to your S3 bucket
Expand Down
9 changes: 6 additions & 3 deletions db/connect.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
$dsn = "mysql:host=localhost;dbname=accidents;charset=utf8mb4";
$user = "dbuser";
$pass = "dbpass";
$dbHost = getenv('DB_HOST') ?: 'localhost';
$dbName = getenv('DB_NAME') ?: 'accidents';
$user = getenv('DB_USER') ?: 'dbuser';
$pass = getenv('DB_PASS') ?: 'dbpass';

$dsn = "mysql:host={$dbHost};dbname={$dbName};charset=utf8mb4";

$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
Expand Down
43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "3.9"

services:
app:
build:
context: .
dockerfile: docker/Dockerfile
ports:
- "8080:80"
environment:
DB_HOST: db
DB_NAME: ${DB_NAME:-accidents}
DB_USER: ${DB_USER:-dbuser}
DB_PASS: ${DB_PASS:-dbpass}
depends_on:
db:
condition: service_healthy
volumes:
- ./:/var/www/html
restart: unless-stopped

db:
image: ${DB_IMAGE:-mysql:8.0}
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-example}
MYSQL_DATABASE: ${DB_NAME:-accidents}
MYSQL_USER: ${DB_USER:-dbuser}
MYSQL_PASSWORD: ${DB_PASS:-dbpass}
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
- ./seed.sql:/docker-entrypoint-initdb.d/seed.sql:ro
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -p$${MYSQL_ROOT_PASSWORD} --silent"]
interval: 5s
timeout: 3s
retries: 30
start_period: 10s
restart: unless-stopped

volumes:
db_data:
14 changes: 3 additions & 11 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# PHP + Apache setup
FROM php:8.2-apache

# Install extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-install mysqli pdo pdo_mysql \
&& a2enmod rewrite

# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Copy project files into container
WORKDIR /var/www/html
COPY ./public /var/www/html/public
COPY ./api /var/www/html/api
COPY ./db /var/www/html/db
COPY . /var/www/html

# Set permissions
RUN chown -R www-data:www-data /var/www/html

EXPOSE 80
Expand Down
Loading