From Linux to macOS: Setting Up a Simple Local PHP Dev Server

As a long-time Linux user, I was familiar with setting up LAMP stacks manually, configuring Apache, and managing .htaccess files. But my previous PC simply wasn’t powerful enough to run the tools I needed for modern development workflows. After upgrading to a Mac Studio with 36 GB of shared memory, I was finally able to run LMStudio with Qwen3-CoderVSCodium, and other essential apps.

To make the most of my system resources, I chose a lightweight PHP-based solution for building brochure-style websites — one that doesn’t require Apache, Docker, or a full LAMP stack. It gives me exactly what I need, without the bloat I used to fight against.

Here’s how I did it — and how you can too.

Step 1: Install PHP via Homebrew

macOS doesn’t come with an up-to-date version of PHP anymore, so I use Homebrew to install the latest version.

brew install php

Step 2: Create Your Local Project

Next, I created index.php, about.php, contact.php, 404.php and router.php

This router.php script mimics .htaccess behavior, allowing URLs like /about instead of /about.php.

<?php
// router.php

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

if ($uri === '/' || $uri === '') {
    require 'index.php';
    exit;
}

$page = ltrim($uri, '/');
$page = preg_replace('/[^a-zA-Z0-9_-]/', '', $page);

if (file_exists("$page.php")) {
    require "$page.php";
} else {
    http_response_code(404);
    require '404.php';
}

Step 3: Run the Server

From the project directory, I run:

php -S localhost:8000 router.php
macOS Terminal window showing PHP built-in server running on localhost at port 8000 with router script.

Now, I can visit: http://localhost:8000

Step 4: Going Live

Once I move the site to a real web server (Apache), I replace router.php with a .htaccess file like this one:

RewriteEngine On

# Serve real files/folders directly
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Rewrite clean URLs to .php files
RewriteRule ^([^/.]+)$ $1.php [L]

# Optional custom 404
ErrorDocument 404 /404.php

This keeps the URLs clean on production servers too.

Switching from Linux to macOS came with a few changes, but using Homebrew and the PHP built-in server, I was able to set up a lightweight, fast, and clean dev environment — perfect for brochure websites, static projects, or quick prototypes.

Wrapping Up

As part of this transition, I’ve also started moving away from WordPress in favor of simple PHP sites. For many small business websites, WordPress is often more than what’s needed — and that extra weight adds up. A typical WordPress site backup using a plugin like All-in-One WP Migration can easily reach 100 MB, while the same site rebuilt with plain PHP often weighs in at just 1–2 MB. When you’re managing dozens of websites, that size difference matters — in storage, speed, and simplicity. Thanks to PHP’s built-in ability to run locally, as described in this post, I now have a development workflow that’s faster, lighter, and better suited to my needs.

Leave a Reply