How to install WordPress on macOS
I have been creating a Website Development Environment on my Mac, which is currently running macOS Big Sur. 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 Big Sur -- 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:
macOS terminal window running "Oh My Zsh"
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:
1$ /usr/bin/php --version 2WARNING: PHP is not recommended 3PHP is included in macOS for compatibility with legacy software. 4Future versions of macOS will not include PHP. 5PHP 7.3.24-(to be removed in future macOS) (cli) (built: Feb 28 2021 09:53:14) ( NTS ) 6Copyright (c) 1997-2018 The PHP Group 7Zend 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 5.7.x because that's the version that I am using on my Pair Networks shared 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, we really only need to send system-generated email. We don't need a full-fledge mail server. I wrote a post about how to Create a Send-Only SMTP Server on macOS Using Gmail. With this setup, we are routing system-generated email out of our Mac and sending it to a Gmail SMTP server that relays the email for us. It is very simple to set up on a Mac. This is a free service for low-volume email. Perfect for our development environment.
With the above software installed (or your own MAMP/Web Server stack), we are 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:
1$ brew install wp-cli 2 3$ wp --info 4OS: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64 5Shell: /bin/zsh 6PHP binary: /usr/local/Cellaremail@example.com/7.4.19_1/bin/php 7PHP version: 7.4.19 8php.ini used: /usr/local/etc/php/7.4/php.ini 9WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli 10WP-CLI vendor dir: phar://wp-cli.phar/vendor 11WP_CLI phar path: /Users/george 12WP-CLI packages dir: 13WP-CLI global config: /Users/george/.wp-cli/config.yml 14WP-CLI project config: 15WP-CLI version: 2.4.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. We also 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:
1$ brew install pwgen 2 3$ pwgen -s 20 1 4Bbdl0OerbaWXOa5oUaM6 5 6$ mysql -u root -p 7Enter password: 8Welcome to the MySQL monitor. Commands end with ; or g. 9Your MySQL connection id is 2 10Server version: 5.7.34 Homebrew 11 12Copyright (c) 2000, 2021, Oracle and/or its affiliates. 13 14Oracle is a registered trademark of Oracle Corporation and/or its 15affiliates. Other names may be trademarks of their respective 16owners. 17 18Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 19 20mysql> CREATE DATABASE imac1_aptstdb; 21Query OK, 1 row affected (0.00 sec) 22 23mysql> CREATE USER 'gw509adm'@'localhost' IDENTIFIED BY 'Bbdl0OerbaWXOa5oUaM6'; 24Query OK, 0 rows affected (0.01 sec) 25 26mysql> GRANT ALL ON imac1_aptstdb.* TO 'gw509adm'@'localhost'; 27Query OK, 0 rows affected (0.00 sec) 28 29mysql> q 30Bye 31$
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.
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, we are ready to install WordPress using three WP-CLI commands to download WordPress, create our WordPress user configuration, and then do the install. Here is an example:
1$ pwd 2/Users/george/Sites/altoplace.tst 3 4$ wp core download 5Downloading WordPress 5.7.2 (en_US)... 6md5 hash verified: 5493c7abf5317889af2bcd885d352823 7Success: WordPress downloaded. 8 9$ wp config create --dbhost=localhost --dbname=imac1_aptstdb --dbuser=gw509adm --dbpass='Bbdl0OerbaWXOa5oUaM6' --dbprefix=ap_ --dbcharset=utf8mb4 10Success: Generated 'wp-config.php' file. 11 12$ pwgen -s 20 1 134ot4h6Ifw9bfZshsh6eS 14 15$ wp core install --url=https://altoplace.tst --title="Altoplace" --admin_user=georgew509 --admin_password='4ot4h6Ifw9bfZshsh6eS' --admin_email="firstname.lastname@example.org" 16Success: WordPress installed successfully. 17$
After downloading WordPress, the wp config create command uses the database and user credentials that we 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:
Your new WordPress site has been successfully set up at:
You can log in to the administrator account with the following information:
1Username: georgew509 2Password: The password you chose during installation. 3Log in here: https://altoplace.tst/wp-login.php 4 5We hope you enjoy your new site. Thanks! 6 7--The WordPress Team 8https://wordpress.org/
You can click on the Site URLs in the email to verify that your new WordPress install is working.
Example WordPress installation.
Assuming that you had a working MAMP stack with at least one SSL-enabled virtual host and followed my WordPress install description, you should have a complete working WordPress installation on your Mac.