Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 68 ยท Getting Started

Setting Up a Local WordPress Site

Set up WordPress on your own computer. Learn the PHP and database requirements, local tools, installing with WP-CLI, wp-config.php, salts and table prefixes.

You should never experiment on a live website. Develop on your own computer first, where a broken plugin costs you nothing and you can reset the whole site in a minute. This lesson explains what WordPress needs to run, the main ways to get a local site, how to install it, and what every important line of wp-config.php does.

Nothing in this lesson can be executed on this site, because WordPress needs a web server and a database. Shell commands and WordPress files are shown read-only. The runnable examples are plain-PHP stand-ins that parse and check a wp-config.php-style file, which is a useful skill in itself.

What WordPress needs

A WordPress site needs three things:

  • A web server: Nginx or Apache, or PHP's built-in server for quick tests.
  • PHP: a currently supported version. WordPress 6.x runs on modern PHP 8.x; check the official requirements page for the exact minimum and recommended versions of your release.
  • A database: MySQL or MariaDB. WordPress talks to it through mysqli, so that PHP extension must be enabled.

HTTPS is recommended even locally, because some browser features and plugins behave differently over plain HTTP.

flowchart LR
    B["Browser"] --> W["Web server<br/>Nginx or Apache"]
    W --> P["PHP<br/>runs WordPress"]
    P --> M[("MySQL or MariaDB")]
    P --> F["Files<br/>themes, plugins, uploads"]

A local WordPress site is the same stack as production, just on your machine.

Ways to get a local site

You do not have to assemble that stack yourself. Common options:

Option What it is Good for
Local (by WP Engine) Free desktop app that creates a site in a few clicks Beginners, client work
Laravel Herd Fast PHP environment for Windows and macOS with WordPress support PHP developers who also use Laravel
XAMPP, MAMP, Laragon All-in-one Apache, PHP and MySQL bundles Simple setups
wp-env Docker-based environment driven by a JSON file, from the WordPress project Plugin and theme developers, testing in CI
Docker Compose Your own containers for web server, PHP and database Matching production exactly

Pick whichever you can get running fastest. Everything in this course works the same on all of them.

Installing from the zip file

The classic manual install has four steps:

  1. Create an empty database and a database user.
  2. Download the latest WordPress zip from WordPress.org and unpack it into your web root.
  3. Open the site in the browser. WordPress offers to create wp-config.php for you and asks for the database name, user, password and host.
  4. Fill in the site title and an administrator account. WordPress creates its tables and you can log in at /wp-login.php.

You can also copy wp-config-sample.php to wp-config.php and edit it yourself, which is what the installer does for you.

Installing with WP-CLI

WP-CLI is the official command-line tool for WordPress. It turns the whole install into a script. These commands are real and read-only here; run them in your own terminal inside an empty folder:

Terminal
# Download core and create the config file
wp core download
wp config create --dbname=wp_dev --dbuser=root --dbpass=secret --dbhost=127.0.0.1

# Create the database, then install the site
wp db create
wp core install \
  --url="http://wp-dev.test" \
  --title="My Dev Site" \
  --admin_user="admin" \
  --admin_password="use-a-strong-password" \
  --admin_email="[email protected]"

wp config create writes wp-config.php and, helpfully, generates fresh security keys. You will meet WP-CLI again in WP-CLI.

Reading wp-config.php

wp-config.php sits in the root of the install and holds the settings WordPress needs before it can even reach the database. It is plain PHP made of define() calls and a few ordinary variables. Here is a trimmed real example, read-only:

PHP
<?php
define( 'DB_NAME',     'wp_dev' );
define( 'DB_USER',     'root' );
define( 'DB_PASSWORD', 'secret' );
define( 'DB_HOST',     '127.0.0.1' );
define( 'DB_CHARSET',  'utf8mb4' );
define( 'DB_COLLATE',  '' );

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
// ... four more keys and four salts ...

$table_prefix = 'wp_';

define( 'WP_DEBUG', false );

if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}

require_once ABSPATH . 'wp-settings.php';

The pieces:

  • Database settings (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST). DB_HOST may include a port, such as 127.0.0.1:3306.
  • DB_CHARSET and DB_COLLATE: leave them at utf8mb4 and empty unless you know why you are changing them.
  • Authentication keys and salts: eight long random strings that WordPress mixes into login cookies and nonces. If two sites share them, or they are the placeholder text, cookies are easier to attack. Generate unique values with wp config shuffle-salts or WordPress's online salt generator. Changing them later logs everyone out, which is a handy response to a suspected break-in.
  • $table_prefix: a string put in front of every table name, so wp_posts becomes site2_posts with the prefix site2_. It lets several installs share one database. A custom prefix is not a real security measure, but it avoids clashes.
  • WP_DEBUG: switches debugging on; see Debugging WordPress.
  • The last lines: define ABSPATH, the filesystem path of the install, and load wp-settings.php, which starts WordPress. Put your own constants above the line that loads wp-settings.php, or they will have no effect.

Never commit real passwords or salts to a public repository. On production, many teams read secrets from environment variables instead.

Try it: parse a config file

The stand-in below reads a wp-config.php-style text, extracts the constants with a regular expression and prints them as a table, hiding secrets. It does not execute the file, which is the safe way to inspect an unknown config. See Regular Expressions for the pattern syntax.

PHP Extract constants from a config file

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

The output lists six constants with the password masked, then shows that the prefix site2_ turns the posts table into site2_posts.

Try it: check a setup before installing

Good installers verify the environment first. This stand-in checks a PHP version, required extensions, and the quality of salts and prefix, then reports each problem. The numbers are examples, not WordPress's official requirements.

PHP A tiny environment checker

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Fix the sample values one by one (upgrade php, add mysqli, replace the placeholder, use the prefix wp_) and the checker reports zero problems.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which database systems can WordPress use?

    WordPress uses MySQL or MariaDB through the mysqli PHP extension. Other databases need special plugins or drop-ins.
  2. 2. What is the purpose of the authentication keys and salts in wp-config.php?

    Keys and salts strengthen cookies and nonces. They must be unique and secret, and changing them logs all users out.
  3. 3. Where must your own constants go in wp-config.php?

    wp-settings.php boots WordPress. Constants defined after it is loaded come too late to influence the boot.
  4. 4. What does $table_prefix = 'site2_' change?

    The prefix is put in front of every table name, which lets several installs share one database.

Summary

  • WordPress needs a web server, a supported PHP version and MySQL or MariaDB.
  • Local, Herd, XAMPP, wp-env and Docker are all fine; develop locally before touching a live site.
  • Install from the zip with the browser installer, or script it with WP-CLI (wp core download, wp config create, wp core install).
  • wp-config.php holds database settings, unique salts, the table prefix and debug flags, and ends by loading wp-settings.php.
  • Keep secrets out of public repositories and put your own constants above the wp-settings.php line.

Next up: Anatomy of a WordPress Install.