
September 12, 2026
12 min read
By Kokil Thapa | Last reviewed: September 2026
Manual server setup breaks under pressure. One missed firewall rule, one wrong PHP version, one forgotten cron path — and your Laravel app works locally but fails in production. Infrastructure as Code (IaC) Explained in plain terms means you describe servers, networks, DNS, and cloud resources in files that live in Git. You review them like application code, test them in CI, and apply them repeatedly. On projects I maintain with Linux system administration and Deployer 7, IaC is what turns "it worked on my laptop" into something a small Nepal team can reproduce without tribal knowledge.
What is Infrastructure as Code and why does it matter?
Infrastructure as Code treats infrastructure the same way you treat application source. Instead of logging into a panel and clicking through wizards, you write declarative or procedural definitions. A pull request shows exactly what will change before anything touches production.
The core idea is not new. Shell scripts and configuration management tools have automated servers for years. Modern IaC adds cloud APIs, state tracking, drift detection, and policy checks. That combination matters when you run multiple environments — staging, production, client sandboxes — on a budget.
For a law-firm portal or eCommerce store, IaC reduces downtime risk. DNS, SSL, load balancers, and database replicas become documented artifacts. When a developer leaves, the infrastructure does not leave with them. That is operational continuity, not buzzword bingo.
IaC sits alongside — not instead of — application deployment. On sister legal-tech sites I maintain, Deployer 7 handles Laravel releases. Terraform or cloud templates handle the EC2 instance, security groups, and elastic IP underneath. Both pipelines share Git as the source of truth. That split keeps concerns clean.
Declarative vs procedural IaC
Declarative tools describe the desired end state. You say "two Ubuntu 24.04 instances with port 443 open." The tool figures out how to get there. Terraform and AWS CloudFormation work this way.
Procedural tools run ordered steps. Ansible playbooks and shell scripts fit here. You control sequence explicitly. Many teams combine both: Terraform provisions, Ansible configures PHP-FPM pools.
Neither style is universally better. Declarative IaC excels at cloud resources with rich APIs. Procedural automation excels at bootstrapping software on a bare VPS from a domain and hosting provider where no cloud API exists.
How does Infrastructure as Code work in practice?
A typical IaC loop has five stages. You author files, commit to Git, run plan or dry-run in CI, apply to an environment, and monitor for drift. Each stage produces artifacts you can audit months later.
- Author — Write
.tf,.yaml, or playbook files describing resources. - Version — Store them in Git with branch protection and required reviews.
- Validate — Run
terraform validate, linting, and security scans in CI. - Plan — Show a diff of what will be created, changed, or destroyed.
- Apply — Execute against staging first, then production after approval.
This mirrors how you ship Laravel code. The difference is the artifact changes AWS or your VPS instead of PHP classes. Teams that already use GitLab CI for application deploys can extend the same pipeline for IaC with minimal new tooling.
A minimal Terraform example
Below is a simplified AWS example. It is not production-ready, but it shows the declarative pattern. Full walkthroughs live in our Terraform practical guide.
# main.tf — define one EC2 instance for a Laravel app
terraform {
required_version = ">= 1.9"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "ap-south-1"
}
resource "aws_instance" "app" {
ami = "ami-0dee22c13ea7a9a21"
instance_type = "t3.small"
tags = {
Name = "laravel-app-staging"
Environment = "staging"
}
}
Run terraform init, then terraform plan, then terraform apply. The plan output is your safety net. Never apply blind in production. Store state remotely — S3 plus DynamoDB locking on AWS, or Terraform Cloud — so two engineers do not corrupt the same state file.
State, modules, and environments
State is Terraform's memory of what it created. Without it, the next apply might try to recreate existing resources. Use separate state files per environment. Our guide on managing multiple environments in IaC covers directory layouts that scale past two servers.
Reusable modules encapsulate repeated patterns — a standard VPC, a Laravel-ready EC2 module with PHP 8.3 and Apache. Modules reduce copy-paste and enforce consistency across client projects.
Which Infrastructure as Code tools should you choose in 2026?
Tool choice depends on where your infrastructure lives and who maintains it. A solo developer on a single VPS needs different tooling than a team running Kubernetes on three clouds.
| Tool | Style | Best for | Learning curve |
|---|---|---|---|
| Terraform | Declarative, multi-cloud | AWS, GCP, Azure, Cloudflare DNS | Moderate |
| AWS CloudFormation | Declarative, AWS-only | Teams fully on AWS with native integrations | Moderate to steep |
| Ansible | Procedural, agentless | Configuring PHP, Nginx, cron on existing servers | Gentle |
| Pulumi | Real programming languages | Teams who want TypeScript or Python for infra | Moderate |
| Cloud-init + bash | Procedural, minimal | One or two VPS instances, tight budgets | Low |
For most Laravel and WordPress projects I touch, the practical stack is Terraform or CloudFormation for cloud primitives plus Ansible or cloud-init for OS-level setup. Pulumi is worth a look if your team already writes TypeScript — see our Pulumi in real languages article.
Official references help when you evaluate trade-offs. HashiCorp maintains current Terraform docs at developer.hashicorp.com/terraform/docs. AWS documents CloudFormation at docs.aws.amazon.com/cloudformation. Ansible docs live at docs.ansible.com.
GitOps and policy as code
GitOps for infrastructure means the Git repo is the only approved way to change production infra. Argo CD or Flux can reconcile Kubernetes clusters. Terraform Cloud or GitLab environments can gate applies behind merge approvals.
Policy as code adds guardrails. Tools like Open Policy Agent or Sentinel reject plans that open SSH to 0.0.0.0/0 or skip encryption. Pair that with IaC security scanning using tfsec, Checkov, or Trivy in CI. Treat failed scans like failing unit tests.
How do you implement Infrastructure as Code on a real project?
Start with one pain point, not a full cloud rewrite. Pick the resource that breaks most often — DNS records, firewall rules, or a staging server clone. Codify that first. Expand outward once the team trusts the workflow.
Step-by-step for a Laravel deployment stack
Imagine a typical stack: Ubuntu 24.04, Apache, PHP-FPM 8.3, MySQL 8.4, Redis 8.10, Let's Encrypt, and Deployer 7 releases. Here is a sensible adoption path.
- Inventory — Document current servers, ports, cron jobs, and env vars. Use a JSON formatter to clean up exported configs if needed.
- Pick scope — If on AWS, Terraform the EC2, security group, and elastic IP. If on a bare VPS, start with Ansible for packages and vhosts.
- Build staging first — Never experiment on production. Match PHP and MySQL versions to prod exactly.
- Wire CI — Add plan-on-PR and apply-on-merge, similar to CI quality gates for application code.
- Connect app deploy — Keep Deployer or GitLab CI for Laravel. IaC provisions the box; Deployer ships the code.
- Backup state and secrets — Remote state, encrypted secrets via SSM or Vault. Never commit
.envfiles.
On the Notary Kathmandu sister-site pipeline, application deploy and server provisioning are separate concerns. That separation saved hours when PHP-FPM pool settings needed a change without touching DNS or SSL.
For booking platforms on Laravel and Livewire, staging parity matters. IaC makes spinning up a staging clone a terraform apply instead of a half-day manual rebuild.
Immutable infrastructure vs mutable servers
Immutable infrastructure replaces servers instead of patching them in place. Packer builds a golden AMI or image. Terraform launches new instances. Deployer swaps the release. Old instances terminate after health checks pass.
Mutable servers — SSH in, apt upgrade, tweak config — are fine for small budgets. Many Nepal SMB sites run this way successfully. Move toward immutability when patch drift causes repeated production surprises.
Idempotent applies mean running the same IaC twice does not double your resources. Terraform tracks state. Ansible skips tasks already satisfied. That property is essential for safe reruns after partial failures.
Zero-downtime updates require lifecycle rules — create-before-destroy on load balancers, blue-green instance groups, or rolling ASG refreshes. Plan these before your first production apply, not during an outage.
What are common Infrastructure as Code mistakes to avoid?
IaC fails when teams treat it like a one-time script dump. The files rot, state diverges from reality, and someone SSHs in to "fix it quickly." That path destroys the value you invested in automation.
- Secrets in Git — Use environment variables, SSM Parameter Store, or GitLab masked variables. Scan repos with Trivy or gitleaks.
- Local state files — A laptop crash should not lose your infrastructure memory. Remote state with locking is non-negotiable for teams.
- No plan review — A destroy of the wrong resource shows up in plan output. Skipping review is how production databases disappear.
- Manual hotfixes — Emergency SSH edits create drift. Fix the IaC file, then apply. Document the incident.
- Over-engineering day one — Twelve modules for one VPS helps nobody. Start flat, refactor when pain appears.
- Ignoring cost —
terraform applycan launch expensive instances. Use tags, budgets, and policy checks.
Security scanning belongs in CI, not as an optional step. Our write-up on Trivy for containers and IaC shows how to catch misconfigured S3 buckets before merge.
Drift detection matters on long-lived servers. Schedule weekly terraform plan runs against production. Non-empty plans signal someone changed infrastructure outside Git. Reconcile or revert promptly.
For AWS-specific patterns, compare native tooling in our CloudFormation on AWS guide. CloudFormation integrates deeply with IAM and StackSets. Terraform offers broader provider coverage. Many teams use both for different layers.
If you run ongoing support and maintenance, IaC lowers handover friction. A new engineer reads the repo instead of shadowing for two weeks. That is worth the upfront authoring time on any project expected to live more than twelve months.
Key Takeaways
- Infrastructure as Code (IaC) replaces manual console work with version-controlled, reviewable infrastructure definitions.
- Use declarative tools like Terraform for cloud resources and Ansible or cloud-init for OS-level configuration on VPS hosts.
- Always run plan before apply, store remote state with locking, and never commit secrets to Git.
- Keep application deploy (Deployer, GitLab CI) separate from infrastructure provisioning — both can share Git as source of truth.
- Start with one high-pain resource, add CI validation and security scans, then expand modules as environments multiply.
- Schedule drift detection and treat manual SSH hotfixes as debt to reconcile back into IaC files.
People Also Ask
Is Infrastructure as Code only for large cloud teams?
No. A single developer managing two VPS instances still benefits from codified firewall rules, DNS records, and package lists. IaC scales down as easily as it scales up. The ROI appears the first time you rebuild staging in minutes instead of hours.
What is the difference between IaC and DevOps?
DevOps is a practice culture — collaboration, automation, measurement. IaC is a specific technique within DevOps. You can do DevOps without full IaC, but IaC without CI integration misses most of its safety benefits.
Can Infrastructure as Code work with shared hosting?
Limited shared hosting offers no API, so full IaC rarely applies. You can still codify DNS at Cloudflare, document deployment steps, and use Ansible where SSH access exists. For serious Laravel or eCommerce workloads, VPS or cloud instances with API access make IaC practical.
How does IaC relate to containers and Kubernetes?
Containers package applications. Kubernetes orchestrates them. IaC provisions the cluster itself — node pools, networks, IAM roles — often via Terraform or Crossplane. Application manifests then deploy via GitOps. The layers stack; they do not replace each other.
Put Infrastructure as Code to work on your next deployment
Infrastructure as Code (IaC) Explained in one sentence: describe what you need, store it in Git, validate in CI, apply with care, and never let manual drift become normal. Whether you run a legal-tech portal, a WooCommerce store, or a custom Laravel booking system, repeatable infrastructure saves money and sleep. If you want help designing an IaC pipeline alongside your application stack, contact us or explore enterprise application development and about my production workflow. Read more on the blog, browse the portfolio, or review web development services for your next project.
Frequently Asked Questions
0 Comments
Leave a comment
Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

