Install WordPress locally on Mac without XAMPP or Mamp

You can install WordPress on Mac locally without XAMPP or Mamp.

To run a WordPress, you need two things:

  • PHP make WordPress possible to interact with the database and fetch data.
  • MySQL is where data is being stored and retrieve by PHP when WordPress runs SQL queries.

To install php and mysql, you need homebrew to install this packages on Mac. Please check my post about how to install homebrew.

How to install PHP on Mac

Once homebrew is installed, you can now install PHP. As of this date, PHP is included in macOS . But if your mac don’t have php, open the Terminal and paste this command:

brew install php

To check the version:

php --version

Let’s write a php code to test.

cd
cd Documents
mkdir website
cd website

nano phpinfo.php

Copy and paste this code on the Terminal

<?php
phpinfo(); 
?>

To save, press control + o

To exit, press control + x

While you are on the directory Documents/website, type this command on Terminal to run PHP service

php -S 127.0.0.1:8080

Open Safari and type this url:

127.0.0.1:8080/phpinfo.php

You should see the details of PHP.

To stop the php service, go back to the Terminal and press control + x

How to install MySQL on Mac

On your terminal, execute this command to install MySQL

brew install mysql

MySQL server user is root and no password.

To start the server

mysql.server start

Create a database for WordPress website. On the terminal,

mysql -uroot

create database wpdb;

exit

Now that we have PHP, MySQL and a database, we are now ready to install WordPress

How to install WordPress on Mac

First we have to download WordPress to your website folder

cd
cd Documents
cd website

curl -OL http://wordpress.org/latest.tar.gz

Extract the downloaded file

tar -xf latest.tar.gz

Rename the folder to mywebsite

mv wordpress mywebsite

Let’s start configuring mywebsite

cd mywebsite
cp wp-config-sample.php wp-config.php

nano wp-config.php

Find this and change accordingly:

define( 'DB_NAME', 'database_name_here' );

define( 'DB_USER', 'username_here' );

define( 'DB_PASSWORD', 'password_here' );

define( 'DB_HOST', 'localhost' );

Change it to this:

define( 'DB_NAME', 'wpdb' );

define( 'DB_USER', 'root' );

define( 'DB_PASSWORD', '' );

define( 'DB_HOST', '127.0.0.1' );

Save it by pressing control + o

To Exit press control + x

To start MySQL and PHP, run the following command:

#if MySQL is not running, run this:
mysql.server start

#To run php service:
php -S 127.0.0.1:8080

Open Safari and go to this URL:

127.0.0.1:8080

Fixing WordPress Errors on Mac

Error establishing a database connection

To solve this, go back to MySQL

mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

This fix could work also on this error:

MySQL said: Authentication plugin ‘caching_sha2_password’ cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found

Once the error is fix, you should have this screen and continue install WordPress on Mac without using Xampp or Mamp

Leave a Comment

Your email address will not be published. Required fields are marked *