# Namecheap cPanel Shared Hosting Deployment Guide

This guide details the exact steps to deploy the **TypeStudio** application on Namecheap shared hosting (cPanel) with zero cloud-rendering costs, MySQL/MariaDB database storage, protected media storage, and cPanel cron scheduling.

---

## 1. Hosting Environment Prerequisites

Verify the following in your Namecheap cPanel dashboard:

1. **PHP Version**: Ensure **PHP 8.2 or 8.3** is selected:
   - Navigate to cPanel &rarr; **Software** &rarr; **Select PHP Version** (or **MultiPHP Manager**).
   - Set the domain to **PHP 8.2** or **8.3**.
2. **Required PHP Extensions**:
   - `pdo_mysql`
   - `openssl`
   - `mbstring`
   - `curl`
   - `fileinfo`
   - `xml`, `ctype`, `json`, `zip`, `bcmath`
3. **PHP Configuration Directives** (in **Select PHP Version &rarr; Options**):
   - `upload_max_filesize`: `256M` (or higher)
   - `post_max_size`: `256M`
   - `memory_limit`: `256M` (or `512M`)
   - `max_execution_time`: `120`

---

## 2. Directory Structure & Web Root Setup

To keep the `.env` file, database credentials, vendor code, and protected media out of the public web:

```
/home/your_cpanel_username/
├── typestudio/               <-- Laravel application core (NON-PUBLIC)
│   ├── app/
│   ├── bootstrap/
│   ├── config/
│   ├── database/
│   ├── storage/              <-- Non-public media repository
│   ├── .env                  <-- Encrypted credentials outside webroot
│   └── artisan
│
└── public_html/              <-- Domain document root
    ├── build/                <-- Compiled CSS and JS assets
    ├── index.php             <-- Main entry point
    ├── robots.txt
    └── .htaccess
```

### Option A: Subdomain with custom Document Root (Recommended)
1. In cPanel, navigate to **Domains** &rarr; **Domains**.
2. Click **Create A New Domain** (e.g. `studio.yourdomain.com`).
3. Set the **Document Root** to:
   `/home/your_cpanel_username/typestudio/public`
4. This keeps the application root outside public web access automatically!

### Option B: Deploying directly to `public_html`
If hosting on your main domain's `public_html`:
1. Upload the entire project to `/home/your_cpanel_username/typestudio`.
2. Move the contents of `/home/your_cpanel_username/typestudio/public/*` into `/home/your_cpanel_username/public_html/`.
3. In `/home/your_cpanel_username/public_html/index.php`, update the paths to:
   ```php
   require __DIR__.'/../typestudio/vendor/autoload.php';
   $app = require_once __DIR__.'/../typestudio/bootstrap/app.php';
   ```

---

## 3. MySQL Database Setup

1. In cPanel, navigate to **Databases** &rarr; **MySQL Databases**.
2. **Create Database**: e.g., `username_typestudio`.
3. **Create User**: e.g., `username_studiouser` with a strong password.
4. **Add User to Database**: Grant **ALL PRIVILEGES**.
5. Update your `.env` file with these values:
   ```dotenv
   DB_CONNECTION=mysql
   DB_HOST=127.0.0.1
   DB_PORT=3306
   DB_DATABASE=username_typestudio
   DB_USERNAME=username_studiouser
   DB_PASSWORD=YourPasswordHere
   ```

---

## 4. Environment Configuration & Permissions

1. In `/home/your_cpanel_username/typestudio/`:
   - Copy `.env.example` to `.env`.
   - Generate your application key:
     ```bash
     php artisan key:generate
     ```
   - Set production values:
     ```dotenv
     APP_ENV=production
     APP_DEBUG=false
     APP_URL=https://studio.yourdomain.com
     APP_TIMEZONE=Africa/Nairobi
     ```
2. Run database migrations and initial seeders:
   ```bash
   php artisan migrate --force
   php artisan db:seed --force
   ```
   *Default Administrator credentials:*
   - Email: `admin@typestudio.local`
   - Password: `Admin1234!#` (change immediately in **Settings**)

3. Set File & Directory Permissions:
   - Directories: `755`
   - Files: `644`
   - Ensure `storage/` and `bootstrap/cache/` are writable by the web server user.

---

## 5. cPanel Cron Setup for Background Scheduling

The scheduler runs entirely in the background even when logged out or when your computer is off.

1. Find the exact PHP CLI path on your Namecheap server. In cPanel Terminal or SSH:
   ```bash
   which php
   ```
   *(Common Namecheap path: `/usr/local/bin/php` or `/usr/bin/php`)*
2. In cPanel, navigate to **Advanced** &rarr; **Cron Jobs**.
3. Under **Add New Cron Job**:
   - **Common Settings**: Select **Once Per Minute** (`* * * * *`).
   - **Command**:
     ```bash
     /usr/local/bin/php /home/your_cpanel_username/typestudio/artisan schedule:run >> /dev/null 2>&1
     ```
   *(Replace `/home/your_cpanel_username/typestudio/` with your actual server directory path).*
4. Click **Add New Cron Job**.

---

## 6. SSL / HTTPS Security

1. In cPanel, navigate to **Security** &rarr; **SSL/TLS Status**.
2. Run **AutoSSL** on your studio domain to provision a free Let's Encrypt / Sectigo SSL certificate.
3. Verify that `APP_URL` in `.env` uses `https://`.

