Set up WordPress locally with MAMP & WP-CLI

When setting up a local WordPress development environment, most developers (including me) reach for modern tools like wp-env or WordPress Studio. These tools are excellent choices — they’re fast, reliable, and handle all the complexity behind the scenes. I recommend them for most development workflows.

However, I believe there’s real value in understanding how to set up WordPress from scratch using MAMP and WP-CLI. This manual approach teaches you the fundamentals of how WordPress works with web servers, databases, and PHP — knowledge that becomes invaluable when you need to:

  • Troubleshoot complex hosting environments
  • Set up WordPress on a VPS or dedicated server
  • Understand what automated tools are doing under the hood
  • Customize setups for enterprise projects with specific requirements

The skills you learn installing WordPress manually with MAMP mirror what’s required for production server installations. While a VPS might use Apache/Nginx, MySQL/PostgreSQL, and a different PHP setup, the core concepts remain the same: configuring the web server, creating databases, setting up PHP, and connecting all the pieces together.

This guide walks you (and my future self) through installing WordPress with MAMP and WP-CLI on macOS. I consider this to be an interesting learning exercise to help understand the infrastructure that powers WordPress.


Table of Contents

  1. Install & configure MAMP
  2. Install WP-CLI and make it use MAMP’s PHP
  3. Create a fresh local WordPress site
    1. Create the site directory
    2. Download WordPress core
    3. Create WordPress configuration
    4. Create the database
    5. Install WordPress
    6. Verify installation
  4. Verify your environment
  5. Troubleshooting Common Issues
    1. MAMP Issues
    2. WP-CLI Issues
  6. Conclusion

Let’s start these series of articles with this one focused on the installation of WordPress and WP-CLI using MAMP.

Install & configure MAMP

WordPress needs a web server, PHP, and a database and MAMP bundles all three — Apache, MySQL, and PHP — into a single package that’s easy to set up on macOS. Setting up a local development environment for WordPress is essential to experiment freely without risking a live site or needing internet access.

Install MAMP

  1. Download MAMP (free version) from mamp.info
  2. Install the .pkg file and launch MAMP from Applications

Configure MAMP

  1. Open MAMP → Preferences → Ports:
  • Apache Port: 8888 (default)
  • MySQL Port: 8889 (default)
  • Keep Nginx disabled
  1. Go to PHP tab:
  • Choose PHP 8.2 or higher (recommended for modern WordPress development)
  • Note the exact version (you’ll need this for WP-CLI setup)
  1. Set Web Server → Document Root:
  • Default: /Applications/MAMP/htdocs
  • Or choose a custom folder like /Users/yourusername/Sites
  1. Click Start Servers — both Apache and MySQL lights should turn green

Verify MAMP installation

  • Visit http://localhost:8888/MAMP/ — you should see the MAMP start page
Screenshot of MAMP's PHP configuration page showing PHP and MySQL settings, including PHP version and MySQL connection details.
  • Check the phpinfo link to confirm your PHP version
  • Note these MySQL connection details:
Host: 127.0.0.1
Port: 8889
User: root
Password: root

Common MAMP issues

  • Port conflicts: If Apache won’t start, another service might be using port 8888. Change to 8080 in Preferences
  • MySQL won’t start: Check Activity Monitor for existing MySQL processes and quit them
  • Permission issues: Ensure MAMP has permission to access your chosen document root

Install WP-CLI and make it use MAMP’s PHP

A local WordPress site is much easier to manage with WP-CLI, the official command-line tool for WordPress. It lets you install WordPress, scaffold plugins, update the database, run searches, and more — all without touching a browser.

When you run wp inside a WordPress project folder, WP-CLI automatically detects the wp-config.php file in the current directory or a parent directory. It then uses the database credentials, table prefix, and other settings from that file to connect to your site. That means:

  • If you’re in your WordPress root or a subfolder (like wp-content/plugins), WP-CLI connects to that site automatically.
  • You can run WP-CLI from anywhere if you use the --path option:
  wp plugin list --path=/Applications/MAMP/htdocs/mysite
  • Without a wp-config.php (or the --path flag), WP-CLI can still run commands that don’t depend on a specific site.

Because you’re working with MAMP, you want WP-CLI to use MAMP’s PHP binary — otherwise it might use the system PHP, which could be a different version or lack extensions WordPress relies on.

Install WP-CLI globally (following the official installation guide):

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Set WP-CLI to use MAMP’s PHP:

First, check your exact PHP version in MAMP (e.g., 8.2.0):

ls /Applications/MAMP/bin/php/

Then create the alias with the exact version (replace 8.2.0 with your version):

echo "alias wp='/Applications/MAMP/bin/php/php8.2.0/bin/php /usr/local/bin/wp'" >> ~/.zshrc
source ~/.zshrc

Verify the setup:

wp --info

You should see output similar to:

OS:        Darwin
Shell:     /bin/zsh
PHP binary: /Applications/MAMP/bin/php/php8.2.0/bin/php
PHP version: 8.2.0

Test with a simple command:

wp core version

This should return the latest WordPress version without errors.

Create a fresh local WordPress site

With MAMP running and WP-CLI ready, you can spin up a clean WordPress install in seconds — no manual database creation or zip extractions. This is perfect for creating disposable development environments.

Create the site directory

cd /Applications/MAMP/htdocs
mkdir mysite && cd mysite

Download WordPress core

wp core download

If this fails: Check that WP-CLI can access the internet and that your MAMP PHP has the required extensions (curl, openssl).

Create WordPress configuration

wp config create \
  --dbname=mysite \
  --dbuser=root \
  --dbpass=root \
  --dbhost=127.0.0.1:8889

If this fails: Verify MAMP’s MySQL is running (green light) and accessible on port 8889.

Create the database

wp db create

If this fails: Check MySQL connection with:

mysql -uroot -proot -h127.0.0.1 -P8889 -e "SHOW DATABASES;"

Install WordPress

wp core install \
  --url="http://localhost:8888/mysite" \
  --title="My Dev Site" \
  --admin_user=admin \
  --admin_password=adminpass \
  --admin_email=admin@example.test

Verify installation

  • Visit http://localhost:8888/mysite to see your new site
  • Log in at http://localhost:8888/mysite/wp-admin with:
  • Username: admin
  • Password: adminpass

Common installation errors:

  • Database connection error: Double-check the host includes port :8889
  • URL issues: Ensure MAMP is running on port 8888
  • Permission errors: Check that MAMP has write access to the htdocs folder

Verify your environment

  • Which PHP am I using?
  wp --info
  which php
  • Can I reach the DB?
  mysql -uroot -proot -h127.0.0.1 -P8889 -e "SHOW DATABASES LIKE 'wordpress_test';"

Troubleshooting Common Issues

MAMP Issues

MAMP won’t start:

  • Check for port conflicts (Activity Monitor → search httpd or mysqld)
  • Try different ports in MAMP Preferences (8080 for Apache, 3306 for MySQL)
  • Restart your Mac if processes are stuck

“Connection refused” errors:

  • Verify MAMP shows green lights for both Apache and MySQL
  • Check your URL uses the correct port: http://localhost:8888/
  • For database connections, always include port: 127.0.0.1:8889

WP-CLI Issues

“wp: command not found”:

  • Reload your shell: source ~/.zshrc or restart Terminal
  • Check if WP-CLI exists: ls -la /usr/local/bin/wp
  • Verify your alias points to the correct PHP version

“PHP Fatal error” when running wp commands:

  • Confirm you’re using MAMP’s PHP: wp --info | grep "PHP binary"
  • Check PHP extensions are enabled in MAMP → PHP → php.ini
  • Required extensions: mysqli, curl, zip, openssl

MAMP is slow:

  • Increase PHP memory limit in MAMP → PHP → php.ini: memory_limit = 256M
  • Disable unused PHP extensions
  • Use SSD storage for MAMP document root

Conclusion

Setting up WordPress with MAMP and WP-CLI manually might seem old-school compared to modern tools like wp-env or WordPress Studio, but it’s a great learning exercise. By working through each step — configuring the web server, setting up the database, managing PHP versions, and connecting the pieces — I’ve gained fundamental knowledge about how WordPress actually works. Hope this guide is also helpful for you at some point.

Leave a Reply

Navigation

About

Writing on the Wall is a newsletter for freelance writers seeking inspiration, advice, and support on their creative journey.

Discover more from JuanMa Codes

Subscribe now to keep reading and get access to the full archive.

Continue reading