Hosting & Deployment

Configure a Host Firewall for a PHP VPS

Expose only required network services while preserving administrative access and documenting firewall ownership.

A host firewall reduces the number of services reachable from untrusted networks. On a VPS, the intended public surface is usually much smaller than the set of processes listening on the machine. Firewall changes must be planned carefully because an incorrect rule can lock administrators out.

Inventory listening services

List active listening ports and identify which service owns each one. Public web traffic commonly needs HTTP and HTTPS, while SSH should be restricted to approved sources where possible. Database, cache, control-panel and internal application ports should not be publicly reachable unless a documented requirement exists.

Apply default-deny rules carefully

Define an inbound policy that denies unsolicited traffic and explicitly allows required services. Preserve established connections and ensure IPv4 and IPv6 policies are both considered. A rule set that protects IPv4 but leaves IPv6 open is incomplete.

Coordinate with provider firewalls

Cloud or hosting-provider firewalls may operate in addition to the operating-system firewall. Document both layers and ensure their rules do not conflict. Do not assume that a closed host port is also blocked at the provider edge, or vice versa.

Test and recover

Schedule a maintenance window, keep an existing SSH session open and test a second connection before ending the first. Use a timed rollback mechanism when applying remote firewall changes. Record the final rules and the command needed to restore them.

Checklist

  • Inventory all listening ports.
  • Expose only required services.
  • Apply equivalent IPv4 and IPv6 policies.
  • Restrict administrative and database access.
  • Test remote changes with a rollback path.
Share this page Help other developers discover this resource.