Published on

Run WordPress Locally Without MAMP or XAMPP

Authors
  • avatar
    Name
    Manpreet Bhasin
    Twitter

Run WordPress Locally Without MAMP or XAMPP

If you've ever wanted to develop a WordPress plugin or theme locally but didn't want to install a heavyweight stack like MAMP or XAMPP, good news — you don't have to. If you already have PHP and MySQL on your machine, you have everything you need. PHP's built-in server (php -S) is perfectly capable of running WordPress for local development. There's just one small gotcha, and we'll get to it.


What You Need Before Starting

Before diving in, make sure your environment meets these requirements:

  • PHP 8.0 or higher — Check with php -v. WordPress 6.x works best with PHP 8.1 or 8.2. The built-in server has been solid since PHP 5.4, so any modern version will work.
  • MySQL installed and running — Check with mysql --version. You'll need to be able to log in with a user that has privileges to create databases. If you're connecting as root locally, that's fine.
  • Command line access — Everything here is terminal-based, no GUI tools required.
  • curl or a browser — To download WordPress. Either works.

That's it. No Apache, no Nginx, no Docker, no MAMP.


Step 1: Download and Extract WordPress

curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cd wordpress

This gives you a clean wordpress/ directory with everything WordPress needs.


Step 2: Create a Database

Log into MySQL:

mysql -u root -p

Then run these SQL commands:

CREATE DATABASE wordpress_local;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'wp_password';
GRANT ALL PRIVILEGES ON wordpress_local.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

You can name the database and user whatever you like — just keep it consistent with the next step.


Step 3: Configure WordPress

Copy the sample config:

cp wp-config-sample.php wp-config.php

Open wp-config.php in your editor and update the database credentials:

define( 'DB_NAME',     'wordpress_local' );
define( 'DB_USER',     'wp_user' );
define( 'DB_PASSWORD', 'wp_password' );
define( 'DB_HOST',     'localhost' );

Next, replace the placeholder security keys. Visit this URL in your browser to generate a fresh set:

https://api.wordpress.org/secret-key/1.1/salt/

Copy the output and replace the existing define('AUTH_KEY', ...) block in wp-config.php with it. This isn't strictly required to get WordPress running, but it's good practice.


Step 4: The Router File — The One Thing Everyone Misses

This is the part that trips people up. PHP's built-in server doesn't understand WordPress's URL rewriting the same way Apache or Nginx do with .htaccess. If you just run php -S pointing at the WordPress folder, static assets load fine but anything that relies on pretty URLs — which is basically the entire WordPress admin and most of the front-end — breaks.

The fix is a small router script. Create a file called router.php inside your wordpress/ directory:

<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

// Serve existing static files (CSS, JS, images) directly
if (file_exists($root . $path) && !is_dir($root . $path)) {
    return false;
}

// Everything else goes through WordPress
$_SERVER['SCRIPT_FILENAME'] = $root . '/index.php';
require $root . '/index.php';

This tiny script does two things: it passes real static files (CSS, JS, images) through unchanged, and it routes everything else through WordPress's index.php, which is exactly how a properly configured web server would behave.


Step 5: Start the Server

From inside the wordpress/ directory, run:

php -S localhost:8080 router.php

Now open your browser and go to http://localhost:8080. You should see the WordPress installation wizard. Fill in your site name, admin username, and password, and you're done.

Tip: Save this as a shell script (start-wp.sh) in the folder so you can spin it back up with a single command next time.


Step 6: Set Up Your Plugin

Once WordPress is installed, create your plugin directory and main file:

mkdir wp-content/plugins/my-plugin
touch wp-content/plugins/my-plugin/my-plugin.php

Open my-plugin.php and add the plugin header. WordPress reads this to register the plugin in the admin:

<?php
/**
 * Plugin Name: My Plugin
 * Description: A description of what this plugin does.
 * Version:     1.0.0
 * Author:      Your Name
 */

// Your plugin code starts here

Go to WordPress Admin → Plugins, find your plugin in the list, and click Activate. You're ready to build.


A Few Things Worth Knowing

Permalinks need a nudge. After install, go to Settings → Permalinks in the admin and click Save Changes — even without changing anything. This forces WordPress to regenerate its rewrite rules, which the router script depends on.

PHP version matters more than you think. If you have multiple PHP versions installed (common on macOS with Homebrew), make sure the one that runs php -S matches what you expect. php -v before you start.

Consider WP-CLI. WP-CLI is a command-line tool for managing WordPress that pairs extremely well with this setup. You can install plugins, create users, run database operations, and a lot more without touching the browser. It's optional but once you've used it you won't go back.

This setup is for local development only. PHP's built-in server is single-threaded and not designed for production traffic. Keep it local.


That's the full setup. No extra applications, no menu-driven installers, no port conflicts from apps running in the background. Just PHP, MySQL, and one small router file that makes all the difference.