How to install WordPress on macOS
I have been creating a Website Development Environment on my Mac, which is currently running macOS Sonoma. I have added a MAMP (LAMP when running on Linux) stack to support various website development tools, such as WordPress. A MAMP stack is based on the macOS operating system, the Apache 2 web server, the MySQL database management system, and the PHP scripting language. You can easily install a MAMP stack by installing a MAMP App as described by the WordPress Codex, Installing WordPress Locally on Your Mac with MAMP . However, I chose to manually install my MAMP stack because I wanted to learn more about the technology.
Installing the MAMP Stack
I have written several posts that detail installing all of the components of my MAMP stack. Here, I will describe the components and what they do.
macOS Sonoma – Of course, this is the operating system that I am using. Under the hood, it is very Unix-like, so if you are familiar with Linux (or other Unix-like OSs), you should be able to follow along. You need to be familiar and comfortable with using the Terminal and command line:
One noticeable change in macOS from earlier macOS releases is that the Terminal has switched from the bash shell to zsh as the default shell command environment. At first, I resisted this change, but I have since adopted zsh on my Mac (I still use bash on my Pair Networks shared host). Out of the box, zsh is a bit raw, so I installed the Oh My Zsh framework to enhance my zsh experience. Oh, I also want to note that bash scripts mostly work with zsh. I have occasionally had to tweak them to work.
Apache and PHP – I talk about setting up both of these in my Configure Apache and PHP-FPM on macOS post because that’s what you need for creating websites that don’t require the use of a full-fledge database management system. I also describe using Dnsmasq to support named virtual hosts on your local machine. And I describe how to set up SSL (TLS) to test SSL enabled virtual hosts. While macOS comes with fairly up-to-date versions of Apache and PHP, I describe how I used Homebrew to install and configure this software. Actually, the next version of macOS, after Big Sur, will not even include PHP:
$ /usr/bin/php --version
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Feb 28 2021 09:53:14) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
MySQL – I describe how I installed and configured MySQL in my Configure MySQL on macOS post. I specifically describe using MySQL 8.x because that’s the version that I am using on my Pair Networks virtual host.
Send-Only SMTP Server – This is not part of the MAMP stack, but I include it because you will need it when you want to test web server Apps that generate email, such as a WordPress contact form. WordPress generates an email message after a successful installation. Mail servers can be very complicated to set up, however, I really only need to send system-generated email. I don’t need a full-fledge mail server. I wrote a post about how to Create a Send-Only SMTP Server on macOS . With this setup, I am routing system-generated email out of my Mac and sending it to my Pair Networks SMTP server that relays the email for me. It is very simple to set up on a Mac. Perfect for my development environment.
With the above software installed (or your own MAMP/Web Server stack), I am ready to install WordPress. I am going to describe installing WordPress via the Command Line. Or more specifically, I am going to use the command line interface for WordPress, WP-CLI . This is a very handy tool to use for working with WordPress from the command line. You can do a lot more than just install WordPress.
Installing WordPress using WP-CLI
The first step is to install WP-CLI if it’s not already installed. This can be easily done with Homebrew :
$ brew install wp-cli
$ wp --info
OS: Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 arm64
Shell: /opt/homebrew/bin/bash
PHP binary: /opt/homebrew/Cellar/php@8.2/8.2.18/bin/php
PHP version: 8.2.18
php.ini used: /opt/homebrew/etc/php/8.2/php.ini
MySQL binary: /opt/homebrew/bin/mysql
MySQL version: mysql Ver 8.3.0 for macos14.2 on arm64 (Homebrew)
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /Users/george
WP-CLI packages dir:
WP-CLI cache dir: /Users/george/.wp-cli/cache
WP-CLI global config: /Users/george/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.10.0
As shown, the WP-CLI functions are executed via the wp command. Use wp help
to see a list of subcommands.
Create the WordPress Database
I am using MySQL to create a WordPress database. You will need to create the database user and grant permissions for the user to access the database. Here’s an example, which also shows how to use pwgen to generate a user password for the database:
$ brew install pwgen
$ pwgen -s 20 1
Bbdl0OerbaWXOa5oUaM6
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.3.0 Homebrew
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE mac1_aptstdb;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER 'gw509adm'@'localhost' IDENTIFIED BY 'Bbdl0OerbaWXOa5oUaM6';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL ON mac1_aptstdb.* TO 'gw509adm'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
$
Verify Your Virtual Host
Before you continue with installing WordPress, you need to verify that you have set up a working Virtual Host. For example, all of my Virtual Hosts live under my ~/Sites directory. I am going to install WordPress for my https://altoplace.tst Virtual Host test domain.
Install WordPress using the WP-CLI download, config create, and Install Commands
If you have created your database and verified that your Virtual Host is working, you are ready to install WordPress using three WP-CLI commands to download WordPress, create the WordPress user configuration, and then do the install. Here is an example:
$ cd ~/Sites/altoplace.tst
$ l
index.html info.php
$ mkdir -p ~/orig/Sites/altoplace.tst
$ cp index.html info.php ~/orig/Sites/altoplace.tst
$ rm index.html info.php
$ wp core download
Downloading WordPress 6.5.2 (en_US)...
md5 hash verified: b27d910fa66f1fcc1a0916d711bcddf3
Success: WordPress downloaded.
$ wp config create --dbhost=localhost --dbname=mac1_aptstdb --dbuser=gw509adm --dbpass='Bbdl0OerbaWXOa5oUaM6' --dbprefix=ap_
Success: Generated 'wp-config.php' file.
$ pwgen -s 20 1
4ot4h6Ifw9bfZshsh6eS
$ wp core install --url=https://altoplace.tst --title="Altoplace" --admin_user=georgew509 --admin_password='4ot4h6Ifw9bfZshsh6eS' --admin_email="george@altoplace.net"
Success: WordPress installed successfully.
After downloading WordPress, the wp config create command uses the database and user credentials that I just created. Before executing the install command, I generated a password for the WordPress admin user that is created by the install command. If all went well, the core install reports Success. Also, if you previously created a send-only SMTP server per my post that I referenced earlier, you should receive an email from your WordPress site that you just installed:
My new WordPress site has been successfully set up at:
https://altoplace.tst
https://altoplace.tst/wp-login.php
I can log in to the administrator account with the following information:
Username: georgew509
Password: The password you chose during installation.
Log in here: https://altoplace.tst/wp-login.php
We hope you enjoy your new site. Thanks!
--The WordPress Team
https://wordpress.org/
You can click on the Site URLs in the email to verify that your new WordPress install is working. You should see something similar to the following image at the top of your browser:
Final Thoughts
Assuming that you had a working MAMP stack with at least one SSL-enabled virtual host and followed my WordPress installation description, you should have a complete working WordPress installation on your Mac.