# Reusable PHP and CodeIgniter upgrade prompt

Copy this prompt into a new task and fill in the project-specific details. Adapt
the process to the actual project; do not copy settings or assumptions from
another site.

## Project details

- Repository: `<absolute repository path>`
- Existing application directory: `<path>`
- Upgrade working directory: `<path>`
- Original/rollback directory: `<path>`
- Development URL: `<URL, if available>`
- Target PHP command: `php8.5`
- Target framework: latest stable CodeIgniter version compatible with PHP 8.5,
  verified against the official release and upgrade notes at the time of work.
- Dependency management: no Composer install or update; use verified official
  manual distributions and retain licenses.
- Production and staging topology, approved services, and deployment owner:
  `<confirm before integration testing>`

Example for the next project:

- Repository: `/var/www/php85/koushik/rateit_latest.com`
- Existing application: `html/`
- Proposed preserved original: `old/`
- Upgraded application: a new `html/`

In the example, `html/` currently contains the application and a tracked
`vendor/` tree; its `app/Config/Paths.php` points to the CodeIgniter framework
under `vendor/codeigniter4/framework/system`. Verify the installed version and
all dependencies rather than assuming the same structure as another site.
The directory rename is a proposed workflow, not an instruction to change the
site immediately. Check whether `html/` is serving traffic and obtain approval
for any interruption or cutover. Confirm `old/` does not already exist. Protect
the preserved copy from HTTP access and avoid committing a duplicate backup.

## Instructions for the upgrading assistant

Upgrade this project to PHP 8.5 and a current compatible CodeIgniter release.
Work through implementation and verification, not just a plan. Preserve
application behavior, integrations, and data. Ask for decisions when the
deployment topology, service ownership, security, or behavior is unclear.
Do not assume the framework, application, or server layouts match another site.

### 1. Inventory and baseline

1. Inspect Git status, existing changes, directory structure, entry points,
   routes, framework version, PHP extensions, dependencies, tests, and current
   deployment configuration. Do not revert unrelated work or alter Git history.
2. Record PHP and framework versions and run available baseline tests. Use
   `php8.5` for target-runtime commands; do not change the system default PHP.
3. Inventory the public routes, static assets, custom framework changes, app
   configurations, bootstrap constants, environment settings, sessions,
   databases, Redis, search, shared libraries, and external services. Identify
   which URLs belong to PHP versus any Node or other application by examining
   the real proxy configuration, not by guessing from application routes.
4. Compare representative production pages with development in read-only
   mode. Record pre-existing warnings, browser console errors, response codes,
   and behavior separately from regressions introduced by the upgrade.
5. Identify runtime data and permissions, including uploads, logs, caches,
   sessions, scheduled tasks, symlinks, ACLs, ownership, and process users.
   Record what must be retained for cutover and rollback.

### 2. Isolate the upgrade and preserve a rollback

1. Confirm the working and rollback directories, available disk space,
   permissions, and whether the existing app is active. Create a verified
   backup outside the web root where appropriate. Do not copy secrets into
   source control or expose backups through the web server.
2. For the example `html/` workflow, after approval preserve the original as
   `old/` and create the new `html/` from a verified copy. Account for tracked
   paths, ignored runtime files, symlinks, permissions, and temporary service
   interruption. If a safe rename cannot be done, prepare a separate staging
   directory and agree on a cutover instead.
3. Preserve source, assets, routes, application-specific dependencies, and
   required configuration. Do not blindly copy live caches, sessions, logs, or
   uploads into a development copy. Plan how production runtime data will be
   retained during cutover.
4. Never delete or overwrite the original, broad directories, or another user's
   changes. Do not modify shared server configuration, shared libraries, or
   third-party code without approval. Use local adapters where practical.

### 3. Upgrade framework and dependencies

1. Obtain the official manual distribution for the verified stable release;
   verify its provenance and published checksum when available, and retain
   licenses. Record versions and sources. Do not run Composer.
2. Check how the project loads CodeIgniter and dependencies. A project may use
   a standalone `system/` directory or `vendor/codeigniter4/framework/system`.
   Decide how the new manual distribution and autoloading fit that project
   before replacing files. Preserve required non-framework vendor dependencies.
3. Follow the official version-by-version upgrade guidance. Merge new
   bootstrap, front controller, `spark`, paths, autoloading, configuration,
   filters, routing, validation, sessions, cookies, security, and test setup
   with the application's existing behavior. Do not overwrite custom code with
   stock framework files without comparing it.
4. Trace custom behavior formerly placed in framework bootstrap files: URL
   constants, environment selection, service endpoints, and other application
   settings may need to move to supported application configuration.
5. Check every bundled or shared library for PHP 8.5 and framework
   compatibility. Manually update only what is needed, using official
   distributions and dependencies. Document any necessary local patches,
   autoload/class-map changes, and licenses. Do not silently drop dependencies.
6. Fix observed PHP 8.5 errors and deprecations, including dynamic properties,
   null handling, outdated signatures, removed functions, and old dependency
   conflicts. Prefer focused application fixes or local wrappers to editing
   shared libraries.

### 4. Preserve configuration and isolate services

1. Compare every original default with the new configuration. Preserve
   production behavior unless a change is explicitly approved. Document each
   intentional change and its deployment requirements. Do not copy one
   project's ports, hosts, database names, or keys into another project.
2. Inventory secrets and where they are consumed, including SMTP, payment,
   CAPTCHA, encryption/hash keys, cloud credentials, and shared configuration.
   Never print or commit secret values. Keep them in an approved protected
   configuration mechanism outside source control and the public document root.
   Coordinate rotation for previously exposed credentials.
3. Before putting credentials in a development `.env`, verify that HTTP access
   to it and other non-public files is denied. A Git ignore rule is not HTTP
   protection. If access is allowed, stop and have the administrator fix it.
   Use approved staging credentials and targets; do not copy production secrets
   into development.
4. Check whether the app and shared libraries each have independent database,
   Redis, search, storage, and CMS configuration. An app-level override does
   not necessarily redirect a shared library. Preserve existing shared
   settings unless their owner authorizes a change.
5. Preserve session cookie names, storage paths, encryption and hashing
   compatibility where required; assess collisions when copies share a host.
   Plan key rotation or migration so existing links and data remain readable.
6. Ensure payment providers use sandbox in development. Confirm the production
   endpoint and credentials separately before release. Validate credentials
   before any database writes or external calls, and do not leave partial
   subscription or transaction records on failure.

### 5. URLs, server, and browser behavior

1. Verify the actual document root, PHP 8.5 FPM upstream, front-controller
   rewrite, static assets, query strings, and PHP/Node routing. Do not change
   or reload shared OpenResty/Nginx configuration without authorization.
   Reject unrecognized hosts if request-host-based URLs are used.
2. Compare clean routes, subdirectory deployments, redirects, canonical links,
   POSTs, GET forms, pagination, and static asset URLs. Test direct navigation
   as well as clicking links in a browser.
3. In CodeIgniter, distinguish route-aware `site_url()` from asset-oriented
   `base_url()`. If a temporary query-string routing workaround is approved,
   verify the framework URI protocol, parameter parsing, GET form behavior,
   and real keyboard and mouse submission. Do not apply a workaround blindly
   or change production behavior unnecessarily.
4. Check browser console, network requests, authentication redirects, cookies,
   and third-party scripts. Compare failures against production before calling
   them regressions. Do not equate an HTTP 200 with a working transaction.

### 6. Test and review

1. Run targeted PHP 8.5 lint, route and class-loading checks, and existing
   tests. Add focused regression tests for changed behavior and edge cases.
   Use isolated test databases, stubs, and sandbox credentials; test missing
   configuration and error handling as well as success paths.
2. Check representative pages and assets, including direct routes, search
   with parameters, forms, login redirects, and pages that depend on shared
   services. Exercise real user interactions where safe.
3. Test payment, email, uploads, bookings, payouts, and other writes only after
   approved staging services and test accounts are confirmed. Never submit
   real payments, email, uploads, or production writes as an incidental test.
   Clearly mark untested integrations and any blocked tests.
4. Review the complete diff, new and deleted files, ignored files, permissions,
   dependency licenses, secrets, and production configuration. Confirm the
   entry point and matching framework are deployed together. Verify that
   runtime files and backups are not accidentally committed or web-accessible.
5. Run the smallest useful tests first, then broader checks as appropriate.
   Report exact results, failures, coverage limits, remaining risks, and the
   commands used. Do not claim production readiness from offline tests alone.

### 7. Release and rollback

1. Produce a deployment checklist covering PHP 8.5 FPM, server routing,
   environment configuration, secret provisioning, writable permissions,
   shared service targets, scheduled jobs, and backup retention.
2. Identify release blockers, compare with production, and get explicit
   approval before switching directories, changing server configuration, or
   running migrations. Keep a tested rollback path and verify the upgraded
   deployment after cutover.
3. Commit only when requested, after checking staged changes for sensitive
   data and unrelated files. Follow the user's commit-message preferences.
   Report the commit, tests, and any uncommitted or ignored deliverables.
