There are many guides out there that will help you setup Wordpress in your localhost. I’ve tried them and faced some issues (and eventually solved them).
Here is the step by step guide for a layman.
- Install Homebrew
- Install PHP (get the right version)
- Install MySQL and setup your database
- Download Wordpress and copy to development folder
- Configure Wordpress
Step 1: Install Homebrew
Installing homebrew is very simple and all it takes is you open a terminal by pressing (Space + Enter) and typing Terminal. It should open a black window:
Copy paste the following:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once the installation is complete, you can proceed to the next step. If you’re prompted for a password, please provide it. This installs Homebrew on your local machine.
Step 2: Install PHP
This is the tricky part. As of writing this article (Dec 2021), the latest version of PHP is not supported. Unfortunately, very little literature deals with this. You should opt for a lower version of PHP (ideally 7.4), and run it as the default PHP version. To install firstname.lastname@example.org, all you need to do is copy paste & run the following command:
brew install email@example.com
It should take a couple of mins to install:
You need to do a couple of things once that’s done:
Step 2.1: Load PHP@7.4 as the default PHP version
You might have a new version of PHP installed in your system. If you get the following message while installing (just scroll up)
If that’s the case, all you need to do is to let MacOS know that the 7.4 version is the latest one when you type php in your terminal:
echo 'export PATH="/firstname.lastname@example.org/bin:$PATH"' >> ~/.zshrcecho 'export PATH="/email@example.com/sbin:$PATH"' >> ~/.zshrc
Step 2.2: [Optional] Update php.ini to allow for bigger file uploads
This is a pre-emptive step that allows you to test new themes without running into errors for uploads. Do not do this on a production environment.
Type the following sequentially:
Once the vim editor is open:
- Type /upload_max_filesize and navigate with your keyboard to where it says 2M:
- Press i to get into edit mode.
- Remove 2M and replace with 10M — this sets the maximum file upload size for the PHP server.
- Press the escape key and type wq — this writes and quits the editor.
Your php.ini file should have this:
Step 3: Install MySQL
MySQL is the database that you’ll use for Wordpress. It’s where the information that Wordpress needs to function is stored. To install, in the same terminal window, type:
brew install mysql
Once the installation is complete, type:
brew services start mysql
which will start the mysql service.
For Wordpress, we’ll have to create a new database to put all that information in… you can choose to call the database whatever you want. We’ll stick to the standard wordpress database name for now, but you can choose a different one.
To create a new database, type the following:
mysql -u root
This opens the mysql prompt, where you can create a new database:
CREATE DATABASE wordpress;
Tip: You can see all your databases by type SHOW DATABASES;
Remember the name you’ve given to the database.
Step 4: Download Wordpress to the right folder
It is important for you to know where you’re downloading the actual wordpress file. I prefer to create a Development folder to keep a track of all my projects — but that’s a personal preference. You can create a new folder in your Documents folder by either creating it from the UI, which you should know, or via command line. To do that, first exit from mysql by typing exit, and follow the below instructions.
Step 4.1: Create/Go to the right folder
You can use pwd to find where you are in the terminal. PWD stands for Present Working Directory — so that’ll be easy to remember.
Step 4.2: Install WGET
Before you continue, you have to install WGET. WGET is a command-line tool for downloading files. You can do a lot more, but we’ll use it for this. To install, simply type:
brew install wget
It will take a few seconds.
Step 4.3: Download Wordpress and uncompress
Finally, it’s time to download wordpress:
You’re downloading a tar.gz file which is a highly compressed zip file. To extract it:
tar xfz latest.tar.gz
This creates a new folder in your new-site folder called wordpress. Which we don’t want… we want to get the wordpress files inside the new-site folder. To do that:
mv wordpress/* ./
which moves all the content from the wordpress folder to the current folder. * denotes all files and the ./ path returns the current working directory.
Once that’s done, you’re on your way to configure and start using Wordpress.
Step 5: Configure and start Wordpress
To start using wordpress, you’ll need to start a PHP server:
php -S localhost:8000
This starts a server on your localhost on the port 8000. You can change the port to whatever you want, but 8000 is usually safe. You should see this:
Open your browser and navigate to localhost:8000. If you’ve followed the above instructions you should see:
Let’s start configuring:
First, select your language and proceed to the second step. Here you can simply press “Let’s go” to get to this screen:
The following values should work:
Database Name: <the name of the mysql database you gave>
Password: <clear the input>Leave everything else as it is...
It should look like this:
Submit and you should be ready with your own localhost installation of Wordpress!
Thank you for reading!