CLIENTPORTAL 1.0.0-RC1 DEPLOYMENT
=================================

Recommended production environment
- PHP 8.0+ with PDO MySQL, cURL, Fileinfo, OpenSSL
- MySQL/MariaDB
- HTTPS
- Apache or compatible web server
- Cron
- SMTP account for outbound mail

Environment variables supported by includes/config.php
- APP_ENV=production
- DB_HOST=localhost
- DB_NAME=clientportal
- DB_USER=clientportal_app
- DB_PASS=strong-database-password
- SETUP_KEY=long-random-first-run-key (only needed for remote first-run admin setup)

Fresh install
1. Create the database and dedicated MySQL user.
2. Import database/schema.sql.
3. Configure DB_* environment variables or edit the local defaults in includes/config.php for development only.
4. If installing remotely, set SETUP_KEY.
5. Open /clientportal/create_admin.php?key=YOUR_SETUP_KEY.
6. Create the first administrator with your own email and 12+ character password.
7. The setup page automatically locks once an admin exists.
8. Log in and configure Admin -> Settings.
9. Set Public site URL to the full HTTPS base URL.
10. Configure SMTP and use Send Test Email.
11. Configure Stripe/PayPal webhooks if payments are used.
12. Configure the daily automation cron.
13. Create a database backup.
14. Run System Health and Production Check.
15. Switch Application environment to Production.

Upgrade from Stage 12
1. Back up the database and uploads.
2. Replace Stage 12 application files with Stage 13.
3. Import database/upgrade_stage12_to_stage13.sql ONCE.
4. Configure Public site URL and email transport.
5. Test email.
6. Run System Health and Production Check.

SMTP
Admin -> Settings supports:
- SMTP host
- port
- STARTTLS/TLS, SSL/TLS, or no encryption
- username
- password
- From address

The SMTP password is never printed back into the Settings form. Blank password submissions preserve the saved value.

Backups
Admin -> Settings -> Database Backup exports the full SQL database.
This SQL contains application settings and may contain payment/email secrets.
Store backups securely.
The /uploads directory is NOT included in SQL backup and must be copied separately.

Logs
PHP errors are written to:
  /clientportal/storage/logs/app.log

The storage directory is protected by .htaccess.
Admin users can inspect the recent log in:
  Admin -> Settings -> Error Log

Email attempts are logged in email_delivery_log and visible in:
  Admin -> Settings -> Email Log

Security
- No fixed production administrator credentials are shipped.
- First-run administrator setup locks after an admin exists.
- Login CSRF and rate limiting remain enabled.
- Client invitations/password resets use hashed expiring tokens.
- Session IDs regenerate on login.
- Session cookies use HttpOnly, SameSite=Lax, and Secure under HTTPS.
- Team permissions are enforced server-side.
- Audit events record important administrative/security/payment events.
- Database/schema/storage directories are protected from direct Apache access.
- Do not run production with the MySQL root account.

Before 1.0
RC1 should be tested on a staging copy of the production server:
- admin/staff/client login
- forgot/reset password
- client invitation
- lead capture/conversion
- project/template creation
- Smart File package selection
- proposal acceptance
- contract signing
- invoice creation/payment
- Stripe sandbox/test webhook
- PayPal sandbox webhook
- recurring invoice cron
- reminder automations
- file upload/download
- SMTP delivery
- SQL backup restore test
