Install and secure phpMyAdmin behind Apache
Install from a trusted package or verified upstream release, isolate configuration secrets, add TLS and network authentication gates, disable dangerous defaults, and test database TLS.
Provide an administrative phpMyAdmin endpoint that is not an unauthenticated public database console.
- phpMyAdmin 5.2
- Recovery access and maintenance window Keep console access and schedule write-affecting work so an interrupted package, grant, backup, or replication change can be recovered.
- Verified backup Create a fresh backup and prove that its format, encryption key, and restore procedure are available before changing production data.
- Capacity and compatibility Check database version, storage headroom, character sets, application driver compatibility, and expected downtime.
df -h; df -i; free -m
OneLiners never runs these steps or stores secrets. Review placeholders, versions, current state, and change-control requirements before using a command.
Full guide
What you will build
- A production-ready phpMyAdmin with MySQL/MariaDB implementation of “Install and secure phpMyAdmin behind Apache” with explicit identities, configuration ownership, observable checkpoints and a tested reversal path.
- A before-state, native validation sequence and concrete evidence set covering the database service, client behavior, data or administrative surface affected by this procedure.
- A least-privilege operational runbook that keeps secrets out of commands and verifies both the required success path and an expected denial or failure boundary.
- Provide an administrative phpMyAdmin endpoint that is not an unauthenticated public database console. The result is demonstrated through the guide's native verification commands and representative application or restore evidence.
- Unrelated databases, accounts, listeners and services remain unchanged; operators can identify the exact revision, artifact and rollback action for this change.
Architecture
How the parts fit together
phpMyAdmin is a privileged PHP application placed behind a dedicated administrative hostname, TLS and an outer access-control boundary. The package or pinned upstream artifact feeds a dedicated FPM/web configuration; database credentials are entered by the operator and not embedded as administrative secrets. Restrictive network/authentication policy, two-factor support, logs, session security and a removal path compensate for the enlarged web attack surface.
- Capture effective configuration, versions, listeners, identities, grants, workload health and a recoverable before-state.
- Prepare the phpmyadmin candidate using only official phpMyAdmin with MySQL/MariaDB interfaces, protected secret delivery and the narrowest necessary scope.
- Apply one controlled layer at a time, run the immediate checkpoint and inspect native logs/status before proceeding.
- Perform end-to-end success and expected-failure tests; retain rollback evidence and schedule recurring verification.
Assumptions
- The installed phpMyAdmin with MySQL/MariaDB family and version are supported by the official sources linked below, and package/configuration provenance is known.
- A maintenance or canary window, current recoverable backup and console-level recovery path exist before state-changing database work begins.
- Operator, application, backup, replication and web-administration identities are separate; secrets are supplied by protected option files, environment injection with appropriate controls, or a secret manager.
- Representative schema size, workload, storage capacity, network policy and recovery objectives are documented for the target environment.
Key concepts
- user@host identity
- MySQL-family authorization matches both an account name and its permitted client origin, not the name alone.
- effective configuration
- The final runtime values after packaged defaults and ordered configuration fragments have been combined.
- consistent state
- Data and metadata captured at one valid transactional or recovery point rather than a mixture of moments.
- recovery objective
- The acceptable data-loss window and restoration time that drive backup, replication and validation design.
- positive and negative verification
- Proving an intended operation succeeds and an operation outside the granted/security boundary fails.
Before you copy
Values used in this guide
{{adminClientIp}}Operator-reviewed value used by this tutorial for adminClientIp; derive it from the target environment and never from untrusted request data.
Example: 192.0.2.25{{adminDomain}}Operator-reviewed value used by this tutorial for adminDomain; derive it from the target environment and never from untrusted request data.
Example: db-admin.example.com{{adminUser}}Operator-reviewed value used by this tutorial for adminUser; derive it from the target environment and never from untrusted request data.
Example: aliceSecurity and production boundaries
- Never place database passwords, encryption keys, recovery codes or private certificates directly in reusable shell history or repository files.
- Do not use `%`, global grants, disabled TLS verification, public administrative interfaces or world-readable dumps as troubleshooting shortcuts.
- Treat backups, slow logs and phpMyAdmin sessions as sensitive data; encrypt, restrict, rotate and monitor them according to the same or stronger policy as production.
Stop before continuing if
- Stop if the server version/config family is ambiguous, the backup cannot be restored, secrets would be exposed, or a proposed command affects databases/accounts beyond the declared scope.
- Do not continue when native validation, representative workload, expected-denial test, TLS identity, replication continuity or storage capacity evidence is incomplete for this procedure.
- Immediately isolate or revert a change that broadens a listener/grant, breaks application health, introduces replication error, loses recoverability or produces unbounded sensitive logs.
instruction
Choose a private access model and hostname
Prefer VPN or management network access; define DNS, TLS, identity provider or second authentication gate, database targets, and named owners.
Why this step matters
Choose a private access model and hostname is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Prefer VPN or management network access; define DNS, TLS, identity provider or second authentication gate, database targets, and named owners. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Choose a private access model and hostname”. The scope must remain limited to the selected application and supported host.
Syntax explained
getent- Invokes the principal tool or configuration operation for “Choose a private access model and hostname”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}- Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
Values stay on this page and are never sent or saved.
getent ahosts {{adminDomain}}; ip route get {{adminClientIp}}; sudo apachectl -SThe management hostname, client scope, and Apache mapping are recorded.
Checkpoint: Checkpoint: Choose a private access model and hostname
Continue whenThe management hostname, client scope, and Apache mapping are recorded. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when getent reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Choose a private access model and hostname” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v getent 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
command
Install phpMyAdmin from a trusted source
Use a supported distribution package or verify the upstream release signature/checksum; never deploy from an arbitrary archive mirror.
Why this step matters
Install phpMyAdmin from a trusted source is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Use a supported distribution package or verify the upstream release signature/checksum; never deploy from an arbitrary archive mirror. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Install phpMyAdmin from a trusted source”. The scope must remain limited to the selected application and supported host.
Syntax explained
apt- Invokes the principal tool or configuration operation for “Install phpMyAdmin from a trusted source”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
&&- Runs the following operation only when the previous command succeeds, preventing a reload or state transition after a failed validation.
sudo apt update && sudo apt install --yes phpmyadmin php-mbstring php-zip php-gd php-json php-curlphpMyAdmin and required PHP extensions install from approved repositories.
Checkpoint: Checkpoint: Install phpMyAdmin from a trusted source
Continue whenphpMyAdmin and required PHP extensions install from approved repositories. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when apt reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Install phpMyAdmin from a trusted source” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v apt 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
config
Create a protected blowfish secret and writable temp directory
Store a high-entropy blowfish_secret outside the document root with root-readable configuration permissions and a dedicated temp directory.
Why this step matters
Create a protected blowfish secret and writable temp directory is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Store a high-entropy blowfish_secret outside the document root with root-readable configuration permissions and a dedicated temp directory. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Create a protected blowfish secret and writable temp directory”. The scope must remain limited to the selected application and supported host.
Syntax explained
umask- Invokes the principal tool or configuration operation for “Create a protected blowfish secret and writable temp directory”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
/etc/phpmyadmin/config.inc.php- Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
/etc/phpmyadmin/config.inc.phpumask 077; openssl rand -base64 48; sudo install -d -o www-data -g www-data -m 0700 /var/lib/phpmyadmin/tmp; sudoedit /etc/phpmyadmin/config.inc.phpThe secret is non-default and tmp storage is private.
Checkpoint: Checkpoint: Create a protected blowfish secret and writable temp directory
Continue whenThe secret is non-default and tmp storage is private. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when umask reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Create a protected blowfish secret and writable temp directory” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v umask 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
config
Configure verified TLS to the database
Set host, port, ssl, ssl_ca, and ssl_verify so phpMyAdmin verifies the database identity; avoid local socket only if remote access is required.
Why this step matters
Configure verified TLS to the database is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Set host, port, ssl, ssl_ca, and ssl_verify so phpMyAdmin verifies the database identity; avoid local socket only if remote access is required. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Configure verified TLS to the database”. The scope must remain limited to the selected application and supported host.
Syntax explained
grep- Invokes the principal tool or configuration operation for “Configure verified TLS to the database”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
|- Passes standard output to the next read-only inspection stage; review each stage separately if the combined result is surprising.
configuration file- Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
sudo grep -nE "host|port|ssl|ssl_ca|ssl_verify" /etc/phpmyadmin/config.inc.phpEvery remote database entry requires CA verification.
Checkpoint: Checkpoint: Configure verified TLS to the database
Continue whenEvery remote database entry requires CA verification. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when grep reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Configure verified TLS to the database” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v grep 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
config
Create a dedicated Apache virtual host
Use a non-obvious path only as convenience, not security; set the phpMyAdmin Alias, deny directory listing, restrict methods, and disable script execution in upload/temp paths.
Why this step matters
Create a dedicated Apache virtual host is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Use a non-obvious path only as convenience, not security; set the phpMyAdmin Alias, deny directory listing, restrict methods, and disable script execution in upload/temp paths. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Create a dedicated Apache virtual host”. The scope must remain limited to the selected application and supported host.
Syntax explained
sudoedit- Invokes the principal tool or configuration operation for “Create a dedicated Apache virtual host”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}- Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
/etc/apache2/sites-available/{{adminDomain}}.conf- Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
/etc/apache2/sites-available/{{adminDomain}}.confValues stay on this page and are never sent or saved.
sudoedit /etc/apache2/sites-available/{{adminDomain}}.conf; sudo a2ensite {{adminDomain}}; sudo apachectl configtestThe dedicated vhost validates and exposes only the phpMyAdmin application.
Checkpoint: Checkpoint: Create a dedicated Apache virtual host
Continue whenThe dedicated vhost validates and exposes only the phpMyAdmin application. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when sudoedit reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Create a dedicated Apache virtual host” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v sudoedit 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
config
Add network and second-factor access gates
Require the management network or VPN and an Apache authentication provider before phpMyAdmin's own database login.
Why this step matters
Add network and second-factor access gates is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Require the management network or VPN and an Apache authentication provider before phpMyAdmin's own database login. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Add network and second-factor access gates”. The scope must remain limited to the selected application and supported host.
Syntax explained
htpasswd- Invokes the principal tool or configuration operation for “Add network and second-factor access gates”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}- Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
|- Passes standard output to the next read-only inspection stage; review each stage separately if the combined result is surprising.
configuration file- Is the persistent configuration boundary changed by this step. Keep an attributable backup and validate the consumer before reload.
Values stay on this page and are never sent or saved.
sudo htpasswd -c /etc/apache2/phpmyadmin.htpasswd {{adminUser}}; sudo chmod 0640 /etc/apache2/phpmyadmin.htpasswd; sudo grep -nE 'Require|AuthType|AuthUserFile' /etc/apache2/sites-available/{{adminDomain}}.confOnly the approved network and authenticated administrators pass Apache authorization.
Checkpoint: Checkpoint: Add network and second-factor access gates
Continue whenOnly the approved network and authenticated administrators pass Apache authorization. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when htpasswd reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Add network and second-factor access gates” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v htpasswd 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
command
Issue HTTPS and set defensive headers
Use a valid certificate, redirect HTTP, and configure frame, content-type, referrer, and HSTS policy compatible with phpMyAdmin.
Why this step matters
Issue HTTPS and set defensive headers is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Use a valid certificate, redirect HTTP, and configure frame, content-type, referrer, and HSTS policy compatible with phpMyAdmin. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Issue HTTPS and set defensive headers”. The scope must remain limited to the selected application and supported host.
Syntax explained
certbot- Invokes the principal tool or configuration operation for “Issue HTTPS and set defensive headers”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}- Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
Values stay on this page and are never sent or saved.
sudo certbot --apache -d {{adminDomain}} --redirect; sudo apachectl configtest; sudo systemctl reload apache2The endpoint uses a valid certificate and defensive response headers.
Checkpoint: Checkpoint: Issue HTTPS and set defensive headers
Continue whenThe endpoint uses a valid certificate and defensive response headers. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when certbot reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Issue HTTPS and set defensive headers” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v certbot 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
verification
Test allowed, denied, and database login paths
Verify a management client passes both gates, an external client is denied, database TLS is active, and error messages disclose no credentials or paths.
Why this step matters
Test allowed, denied, and database login paths is a separate checkpoint because it establishes one auditable part of provide an administrative phpmyadmin endpoint that is not an unauthenticated public database console. Performing it independently keeps a failed prerequisite, syntax error, or compatibility mismatch from being hidden by later actions.
What to understand
Verify a management client passes both gates, an external client is denied, database TLS is active, and error messages disclose no credentials or paths. Read the complete command or configuration before execution, replace the documented placeholders, and compare the target host with the supported environments listed at the beginning of this tutorial.
Capture the before-state and the exact output in the change record. If this step modifies a file or service, validate the candidate with its native checker before any reload; a successful process exit alone does not prove that the application uses the intended value.
Use a representative staging or canary host first. Repeat the stated checkpoint immediately, because proceeding with ambiguous evidence makes the later end-to-end verification and rollback materially harder.
System changes
- This step may affect the files, packages, identities, services, or runtime policy named in “Test allowed, denied, and database login paths”. The scope must remain limited to the selected application and supported host.
Syntax explained
curl- Invokes the principal tool or configuration operation for “Test allowed, denied, and database login paths”; confirm that it resolves to the expected packaged executable or file before using elevated privileges.
{{…}}- Marks an operator-supplied value. Replace every placeholder deliberately; do not paste untrusted text or leave braces in the production command.
Values stay on this page and are never sent or saved.
curl --head https://{{adminDomain}}/; curl --user {{adminUser}} --head https://{{adminDomain}}/; sudo tail -n 50 /var/log/apache2/{{adminDomain}}-error.logUnauthenticated access is challenged or denied and authorized access reaches phpMyAdmin over HTTPS.
Checkpoint: Checkpoint: Test allowed, denied, and database login paths
Continue whenUnauthenticated access is challenged or denied and authorized access reaches phpMyAdmin over HTTPS. Treat this concrete evidence as the minimum success signal and also confirm that unrelated services and the previous healthy path remain unchanged.
Stop whenStop before the next step when curl reports an error, the output differs materially from the example, an unexpected package/service/path is affected, or the required before-state and rollback artifact are missing.
If this step fails
The command for “Test allowed, denied, and database login paths” fails, produces no useful evidence, or the expected service/configuration state is absent.
Likely causeA placeholder targets the wrong environment, the installed version uses another path or unit name, permissions are insufficient, or an earlier prerequisite was not satisfied.
command -v curl 2>/dev/null || truesystemctl --failed --no-pager 2>/dev/null || truejournalctl -p warning -n 50 --no-pager 2>/dev/null || true
ResolutionDo not improvise a privileged workaround. Re-read the environment and variable table, inspect the official source for the installed version, restore the candidate file if necessary, and repeat only this checkpoint.
Security notes
- Keep secrets out of shell history, process arguments, screenshots, logs, and tutorial placeholders. Elevate only the narrow command that requires it and preserve package signature and TLS verification.
Alternatives
- When the host layout or software version differs, use the vendor-supported equivalent in a disposable staging environment and document the mapping before touching production.
Stop conditions
- Stop if the action broadens network exposure, permissions, package sources, writable paths, or service privileges beyond the tutorial's declared architecture.
Finish line
Verification checklist
curl --silent --output /dev/null --write-out '%{http_code}\n' https://{{adminDomain}}/An untrusted client receives 401 or 403, not the phpMyAdmin login page.for p in setup scripts examples; do curl --silent --output /dev/null --write-out "$p=%{http_code}\n" https://{{adminDomain}}/$p/; doneSetup, scripts, and examples paths are absent or forbidden.Recovery guidance
Common problems and safe checks
The native client reports access denied even though a similarly named account has grants.
Likely causeDatabase identities include a host component and authentication plugin; the connection matched another user@host row or transport.
mysql -e 'SELECT USER(), CURRENT_USER();'mysql -e "SELECT User,Host,plugin FROM mysql.user ORDER BY User,Host;"mysql -e 'SHOW GRANTS FOR CURRENT_USER;'
ResolutionIdentify the exact matched account and create or modify only the intended user@host identity; do not broaden it to '%' as a shortcut.
TLS is enabled but the client still connects with an unexpected identity or without hostname verification.
Likely causeThe client uses encryption-only mode, connects by an address absent from the SAN, trusts a broad system CA set, or another option file overrides policy.
mysql --print-defaultsopenssl s_client -starttls mysql -connect db.example.com:3306 -servername db.example.com </dev/nullmysql -e "SHOW STATUS LIKE 'Ssl_%';"
ResolutionUse the documented hostname, intended CA and VERIFY_IDENTITY-equivalent mode; remove conflicting client options and retest expected failure with a wrong hostname.
A change passes syntax checks but application errors, lag, latency or disk use increases.
Likely causeThe candidate is syntactically valid but workload, lock, cache, rotation, privilege or version assumptions are wrong.
mysqladmin pingmysql -e 'SHOW PROCESSLIST;'journalctl -u mariadb -u mysql -p warning --since '-10 min' --no-pager
ResolutionStop promotion, preserve evidence, revert the smallest changed configuration/account/routing layer and reproduce with a safe representative workload.
Reference
Frequently asked questions
Does a successful command mean the procedure is complete?
No. Database tools may return success before application compatibility, replica replay, restore integrity, TLS identity or expected denials are proven. Use every checkpoint and final verification.
Can an administrator use the application account for convenience?
No. Separate identities make least privilege, rotation, audit and incident containment possible; the application should not hold administrative capabilities.
Why test restoration or negative access separately?
A backup that cannot restore and a grant that was never tested for denial are assumptions, not controls. Isolation makes those tests safe and repeatable.
Recovery
Rollback
Disable the dedicated Apache site and restore the prior phpMyAdmin configuration without weakening database accounts.
- Run a2dissite for the admin vhost, validate, and reload Apache.
- Restore the archived config.inc.php and keep secrets protected.
- Remove the package only after no other local administration workflow depends on it.
Evidence