Skip to content
prod 352bb92
Browse

2 · Local database

Objective — confirm the local DB provisioned in Phase 2 is running, uses utf8mb4, and is the database .env points Laravel at. Create it only if it is missing (for a local-only workflow or a skipped Phase 2), then prove the installer can connect.

Steps at a glance:

  1. Start the database service — In Herd → Services → Database, start Local_MySQL or Local_MariaDB (wait for the green dot).
  2. Verify the connection — Herd Pro requires a TCP connection (-h 127.0.0.1), not a socket.
  3. Confirm or create the database — Phase 2 Step 1 should already have created it; this step verifies charset/collation and creates only if missing.
  4. Confirm .env points at it and prove the connection — Phase 2 Step 5 activated local .env; this step confirms Laravel resolves the right DB and table count.

The installer needs a reachable local database before page 4 runs. Phase 2 owns the provisioning and .env template activation; this page is the local readiness checkpoint that catches a stopped DB service, wrong charset, stale config cache, or .env pointing at the wrong schema.

Use Zaj-PROJECT.md as the non-secret source for the local DB row: DB engine/version, host/port, database name, username, charset/collation, and last verified date. Do not put passwords there; keep secret values in the vault.

In Herd → Services → Database, start Local_MySQL or Local_MariaDB (wait for the green dot). Homebrew (brew services start mysql / mariadb), DBngin, and MAMP all work too.

  1. Start the service and wait for its green dot — or use a terminal alternative.

    Terminal window
    brew services start mysql # or: brew services start mariadb
    # Expected: "Successfully started" (skip if you started it from the Herd GUI)
    • ✅ The local DB engine is running.

Herd Pro requires a TCP connection (-h 127.0.0.1), not a socket.

  1. Connect over TCP and print the engine version.

    Terminal window
    mysql -h 127.0.0.1 -P 3306 -u root -e "SELECT VERSION();"
    # Expected: a single version string (e.g. 11.x-MariaDB or 8.x)
    • ✅ A version prints — no socket error.
  2. If it fails, map the error to its fix.

    ErrorFix
    Can't connect through socket '/tmp/mysql.sock'Add -h 127.0.0.1 -P 3306
    Connection refusedStart the DB service from Herd
    Access deniedCheck the root password in Herd’s DB settings
    • ✅ Reconnecting after the fix returns a version.

Phase 2 Step 1 should already have created the local database and user. Run the idempotent create anyway: it is a no-op when the DB exists, and it only creates the schema if Phase 2 was skipped or you are doing a local-only workflow.

  1. Confirm the utf8mb4 database exists, creating it only if missing.

    Terminal window
    mysql -h 127.0.0.1 -u root -e "CREATE DATABASE IF NOT EXISTS \`[project]_local_db\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
    # Expected: no output (silent success; no-op if Phase 2 already created it)
    • ✅ The database exists; no error printed. If Phase 2 already created it, this command changed nothing.
  2. Verify the charset and collation.

    Terminal window
    mysql -h 127.0.0.1 -u root -N -e "SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME='[project]_local_db';"
    # Expected: utf8mb4 utf8mb4_unicode_ci
    • ✅ The local DB is charset-safe for the installer.

Use the exact local DB name from Phase 2 if your project used a different suffix. utf8mb4 matters — many CodeCanyon apps store emoji and multi-byte content and throw collation errors on a 3-byte utf8 database.

4. Confirm .env points at it and prove the connection

Section titled “4. Confirm .env points at it and prove the connection”

Phase 2 Step 5 laid down and activated the local .env. Confirm the live file resolves to the provisioned local DB, then prove Laravel can use it.

  1. Confirm the DB_* block in .env.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=[project]_local_db
    DB_USERNAME=[project]_local_user
    DB_PASSWORD=""
    • .env points at the Phase 2 local DB. root with an empty password is the simplest local example, but a dedicated per-env user/password from Phase 2 is valid and preferred.
  2. Clear the stale config cache, then check the connection.

    Terminal window
    php artisan config:clear
    php artisan db:show 2>&1 | head -5
    # Expected: connection details for [project]_local_db; 0 tables for fresh install, or the existing table count when resuming
    • db:show reports the right database.
  3. If db:show looks wrong, confirm with a direct query — it can report tables from a different project on the same server.

    Terminal window
    DB_NAME=$(grep '^DB_DATABASE=' .env | cut -d= -f2 | tr -d '"')
    mysql -h 127.0.0.1 -u root -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='${DB_NAME}';"
    # Expected: 0 tables (fresh install) — OR the existing table count if the installer already ran (resuming)
    • ✅ The direct query returns the correct table count for this project state.

One more reason to trust the direct query over the artisan helper:

Do not mark this step done until every box below is checked.

  • 👤 DB service running — green dot in Herd, or brew services.
  • 🤖 Connects over TCPmysql -h 127.0.0.1 connects without a socket error.
  • 🤖 Local schema confirmed — exists or was created only if missing, with utf8mb4 / utf8mb4_unicode_ci.
  • 🤖 .env verifiedDB_* resolves to the Phase 2 local DB and every secret is double-quoted.
  • 🤖 Table count interpreted0 for a fresh install, or an existing table count accepted with evidence when resuming.
  • 🤖 Project state updatedZaj-PROJECT.md records the local DB engine/version, host/port, DB name, DB user, charset/collation, and verification date; passwords stay only in the vault.