# Publish ScholarBooks at textbook.mytech4you.ae

This is a **fresh-install production package**, configured for:

**https://textbook.mytech4you.ae/**

Laravel 12, PHP 8.2, and MySQL. Production PHP dependencies are already included. You do not need Composer, Node.js, or npm on the hosting server. This package does not automatically upload itself or create your hosting database.

## 1. Hosting prerequisites

In the domain's PHP settings, select **PHP 8.2** (PHP 8.3/8.4 can also satisfy the dependency requirements). Enable `pdo_mysql`, `mbstring`, `openssl`, `fileinfo`, `zip`, `SimpleXML`, and DOM/XML plus the usual Laravel PHP extensions. Set `upload_max_filesize=8M`, `post_max_size=10M` or higher and `memory_limit=256M` or higher.

Make sure the domain points to your hosting account and has a valid HTTPS/SSL certificate. Keep HTTPS active: this package uses secure session cookies.

## 2. Upload the application privately

Use the hosting File Manager with **Show hidden files** enabled so `.env` and `.htaccess` are visible.

Extract this ZIP in a private folder, then move/rename its `ScholarBooks-Laravel-12` folder to:

```
/home/YOUR_HOSTING_USERNAME/scholarbooks
```

Replace the username/path with the actual home directory shown by your hosting panel. Keep the application, `.env`, vendor, storage, documentation, and installation script **outside the domain's public document root**.

### Preferred: the panel allows changing the document root

Set the document root for `textbook.mytech4you.ae` to:

```
/home/YOUR_HOSTING_USERNAME/scholarbooks/public
```

The normal application `public/index.php` works without editing. Ignore `web-root-alternative/`.

### Alternative: the document root is fixed

Leave the whole application in the private folder above. Copy **only the contents** of `web-root-alternative/`, including `.htaccess`, into the domain's actual document root, for example:

```
/home/YOUR_HOSTING_USERNAME/public_html/textbook
```

In that public `index.php`, change the `$applicationPath` line to the actual private application directory. Do not upload the entire Laravel application into the web root. Do not overwrite unrelated website files; use the document root assigned specifically to this domain.

Only one layout is needed. The package's original CSS and favicon are unchanged.

## 3. Create the MySQL database

In cPanel's MySQL Database Wizard, Plesk's Databases page, or the equivalent panel:

1. Create a database and a dedicated database user.
2. Assign the user to that database with the permissions needed to create the tables and read/write application data.
3. Record the **full prefixed names** (for example, `account_scholarbooks`), the database password, and the host name supplied by the hosting company.

Use an empty database for this fresh installation. The installer creates the schema automatically; no phpMyAdmin SQL import is needed.

## 4. Edit the private .env file

The included `.env` already contains a newly generated encryption key, the domain, production mode, disabled debug output, and secure cookies. Do not publish this file or paste its contents into a chat.

Fill these values with your actual hosting details:

```dotenv
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_full_database_name
DB_USERNAME=your_full_database_user
DB_PASSWORD="your_database_password"
SCHOLARBOOKS_ADMIN_USERNAME=admin
SCHOLARBOOKS_ADMIN_PASSWORD="choose_a_unique_password_at_least_12_characters"
```

Use the database host your provider specifies; it may differ from `localhost`. Quoted passwords should use dotenv escaping if they contain double quotes or backslashes.

Leave these prepared settings in place:

```dotenv
APP_ENV=production
APP_DEBUG=false
APP_URL=https://textbook.mytech4you.ae
SESSION_SECURE_COOKIE=true
SCHOLARBOOKS_MAIL_MODE=preview
```

The web-server PHP user must be able to write to `storage/` and `bootstrap/cache/`. Typically directories are 755/775 and files 644/664 depending on your host's ownership model. Keep `.env` private (usually 600/640 if compatible with your PHP user). Do not set the whole project to 777.

## 5. Install — choose ONE method

### Terminal/SSH is available

Select the hosting provider's **PHP 8.2 CLI executable**, then run:

```sh
cd /home/YOUR_HOSTING_USERNAME/scholarbooks
php deploy/install.php
```

Some hosts use `/usr/local/bin/ea-php82` or another path instead of `php`. The web PHP selector does not always change the CLI version; use the path documented by your host.

### No Terminal/SSH: use a temporary cron job

In the hosting panel's Cron Jobs/Scheduled Tasks screen, temporarily schedule this command once per minute, using your real home directory and the host's PHP 8.2 CLI path:

```sh
/usr/local/bin/ea-php82 /home/YOUR_HOSTING_USERNAME/scholarbooks/deploy/install.php >> /home/YOUR_HOSTING_USERNAME/scholarbooks/storage/logs/hosting-install.log 2>&1
```

The executable path shown is an example, not a fact about your hosting. Ask the host for the correct path if the task reports “command not found” or an old PHP version.

After a run, inspect `storage/logs/hosting-install.log` in File Manager. Successful installation creates the private file `storage/app/hosting-installed.json`. **Remove the temporary cron job after success.** Repeated runs after success exit harmlessly.

If the host supplies neither Terminal/SSH nor PHP cron execution, ask its support team to run `php deploy/install.php` once in the application folder. The package deliberately does not expose a public database installer.

### What installation does

The helper validates the settings, runs Laravel migrations, creates your chosen administrator, removes the setup password from `.env`, and compiles routes/views. It does not insert demo students or send email. It does not regenerate your application key. There is no shared default password.

If installation fails after the administrator was created, do not delete tables or rerun a fresh install. Have the host inspect the private log and finish `php artisan route:cache` and `php artisan view:cache`; existing accounts are deliberately protected from being overwritten.

## 6. Open the site

Visit **https://textbook.mytech4you.ae/** and sign in using the administrator credentials you chose. Create a semester in Settings and begin importing the approved files.

Basic checks:

- The login page loads with the ScholarBooks styling.
- Login works and the address stays HTTPS.
- Settings can create an academic semester.
- The import templates download.
- Requests for `/.env` or `/vendor/autoload.php` cannot expose private application files; those files must never be under the domain's document root.

For a 500/503 error, inspect private `storage/logs/laravel.log`; leave public debugging disabled. A 419 error often means stale cookies, an incorrect `APP_URL`, missing HTTPS, or unwritable session storage. A database error usually means the full prefixed names, user assignment, password, or DB host are incorrect.

## 7. Email can be enabled later

This package intentionally starts in **safe preview mode**. Fill in your actual verified SMTP sender and credentials before enabling email. Do not assume an email mailbox exists simply because the domain exists. See the application's README for SMTP details.

After enabling SMTP, configure the regular Laravel scheduler once per minute:

```sh
/usr/local/bin/ea-php82 /home/YOUR_HOSTING_USERNAME/scholarbooks/artisan schedule:run >> /dev/null 2>&1
```

Again, replace the PHP executable and home directory with the actual hosting values. This is different from the temporary installation job.

## Existing data and future updates

The generated `.env`/key in this package is for a **new installation only**. If you already have a populated ScholarBooks database, preserve its `.env` and encryption/hash keys; never replace them with the fresh-install file. Follow `ScholarBooks-Laravel-12/docs/DATABASE.md` for legacy migration. Do not run this fresh installer against an existing operational database.

Back up the database together with the private `.env` after installation. Keep the ZIP private because it contains your installation encryption key, and remove uploaded ZIPs from any public directory after extraction. On later deployments, preserve the live `.env` and `storage/` and run appropriate migrations rather than reinstalling.
