Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Setup & site building · Guide

How to Install WordPress From Command Line (Step by Step)

How to Install WordPress From Command Line (Step by Step)

Short answer

Install WP-CLI, create an empty database and user, then run wp core download to get the files, wp config create to write the config file, and wp core install with your URL, title and admin details. Without WP-CLI, download the archive with wget, edit the config file and finish in a browser.

Key takeaways

  • WP-CLI installs WordPress in four main commands.
  • wp config create checks the database connection before writing.
  • Do not run WP-CLI as root; use the site's file owner.
  • Run wp core verify-checksums to confirm clean files.
  • You can install manually with wget and the browser installer.

How do you install WordPress from the command line?

Install WP-CLI, create a database, then run wp core download, wp config create and wp core install to download the files, write wp-config.php and finish the setup in a few commands.

The command line route is faster than the browser installer once you know it. It is also repeatable, so you can script it for every new site. Here is the short version:

wp core download
wp config create --dbname=wpdb --dbuser=wpuser --dbpass='StrongPass' --dbhost=localhost
wp db create
wp core install --url=https://example.com --title="My Site" --admin_user=siteadmin --admin_password='AnotherStrongPass' [email protected]

The rest of this guide explains each step, what you need first, and how to do it without WP-CLI if you prefer.

What do you need before you start?

You need SSH access to a server with a web server, PHP and MySQL or MariaDB installed, plus a domain or local hostname pointing at the site folder.

Check these requirements:

  • SSH access with a user that can write to the web root.
  • A web server such as Apache or Nginx, configured for your domain.
  • PHP at a version WordPress supports. See which PHP version to use for WordPress.
  • MySQL or MariaDB. Our comparison of MySQL vs MariaDB for WordPress covers the differences.
  • Database credentials for a user that can create a database, or an empty database already made.

WordPress lists current minimums on its requirements page. Many hosts already have all of this in place.

Step 1: How do you install WP-CLI?

Download the wp-cli.phar file, check that it runs, make it executable and move it into your PATH so you can type wp from any folder.

Run these commands:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

The second command confirms PHP can run the file. The last one confirms the wp command works.

If you do not have sudo rights, move the file into a bin folder in your home directory and add it to your PATH instead. The official WP-CLI installation guide covers other methods.

Many hosts include WP-CLI already. Type wp --info first to check. If you get an error, our guide on fixing wp command not found helps.

Step 2: How do you create the database?

Create an empty database and a user with full rights on it, either in the MySQL shell or later with wp db create once wp-config.php has the details.

To create both in the MySQL shell, log in as an admin user:

CREATE DATABASE wpdb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPass';
GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace the names and password with your own. Use a long, random password.

If your hosting panel manages databases, create the database and user there instead. Our guide on how to create a database for WordPress covers control panel methods.

Step 3: How do you download WordPress core?

Move into your web root and run wp core download, which fetches the latest WordPress release and unpacks it into the current folder.

cd /var/www/example.com/public_html
wp core download

Useful options:

  • --locale=de_DE downloads WordPress in another language.
  • --version=6.5 downloads a specific version.
  • --path=/some/folder downloads into a different folder.

Do not run WP-CLI as root. If you must, WP-CLI will ask you to add --allow-root, but it is better to switch to the user that owns the site files. Files owned by root can cause permission errors later.

Step 4: How do you create wp-config.php?

Run wp config create with your database name, user, password and host, and WP-CLI writes wp-config.php with fresh security keys.

wp config create --dbname=wpdb --dbuser=wpuser --dbpass='StrongPass' --dbhost=localhost --dbprefix=wp_

WP-CLI checks the database connection before writing the file. If the details are wrong, it stops with an error, which saves you from a broken install.

Tips:

  • Wrap passwords in single quotes so the shell does not misread special characters.
  • Change the table prefix with --dbprefix if you want something other than wp_.
  • Use --extra-php to add constants such as WP_DEBUG.

The config create reference lists every option.

If you skipped Step 2 and your database user has create rights, run wp db create now. It makes the database named in wp-config.php.

Step 5: How do you run the WordPress install?

Run wp core install with your site URL, title and admin account details to create the database tables and finish setup.

wp core install --url=https://example.com --title="My Site" --admin_user=siteadmin --admin_password='AnotherStrongPass' [email protected]

When it finishes, you will see a success message. Your site is live at the URL you gave.

A few notes:

  • Avoid admin as the username. It is the first name attackers guess.
  • Use https in the URL if your certificate is already set up.
  • Add --skip-email if the server cannot send mail yet.

The core install reference shows all options.

Step 6: How do you check and finish the setup?

Verify the core files, set the right file ownership, and log in to confirm the site works before adding themes and plugins.

Run these checks:

wp core verify-checksums
wp option get siteurl
wp user list

verify-checksums confirms the downloaded files match the official release. The other commands confirm the URL and admin user are correct.

Next, fix ownership if needed. The web server user (often www-data) usually needs to read the files and write to wp-content. WordPress explains safe settings in its file permissions guide.

Finally, open https://example.com/wp-admin in your browser and log in.

How do you install WordPress without WP-CLI?

Download the latest archive with curl or wget, unpack it, copy wp-config-sample.php to wp-config.php, add your database details, then finish in the browser.

cd /var/www/example.com
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* public_html/
cd public_html
cp wp-config-sample.php wp-config.php
nano wp-config.php

In wp-config.php, fill in DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Replace the security key lines with fresh values from the WordPress secret key generator.

Then visit your domain in a browser. The WordPress installer asks for the site title and admin account, and creates the tables.

WP-CLI vs manual install: which should you use?

Use WP-CLI when you set up sites often or want to script installs, and use the manual method when you cannot install WP-CLI on the server.

FactorWP-CLIManual (wget and browser)
SpeedFastest, a few commandsSlower, includes browser steps
RepeatableEasy to scriptHard to automate
Security keysAdded automaticallyYou paste them in
Connection checkChecks before writing configFails at the browser step
Extra tools neededWP-CLINone

WP-CLI is also useful after install. Our list of useful WP-CLI commands covers plugins, users, updates and search and replace.

How do you turn the install into a reusable script?

Put the commands in a small shell script with variables for the site name, database and admin details, so every new site is set up the same way in seconds.

Scripting is where the command line really pays off. Instead of typing each command, you set a few values at the top and run one file.

A simple script usually does these jobs in order:

  1. Download core into the target folder.
  2. Create wp-config.php with the database details.
  3. Create the database.
  4. Run the install with the site URL and admin user.
  5. Set permalinks, for example with wp rewrite structure.
  6. Remove default content you never use, such as the sample post.
  7. Install and activate your standard plugins and theme.

Keep passwords out of the script itself where you can. Read them from environment variables or prompt for them when the script runs, so they do not end up in your shell history or a shared repository.

Test the script on a throwaway site first. Once it works, it becomes the fastest way to start client projects, staging copies and test sites.

What are common errors and how do you fix them?

The most common errors are database connection failures, permission problems and running commands in the wrong folder, and each has a quick fix.

  • Error establishing a database connection: check the database name, user, password and host. Some hosts use a host other than localhost. See fixing the database connection error.
  • This does not seem to be a WordPress installation: you are in the wrong folder. Use cd to move to the web root or add --path.
  • Permission denied: the current user cannot write to the folder. Run as the site owner or fix ownership.
  • PHP memory errors: run with a higher limit, for example php -d memory_limit=512M followed by the path to WP-CLI.
  • Site shows the default server page: your web server is not pointed at the right folder.

Once the site works, consider adding an SSL certificate and a backup routine. If you later move the site, our guide on how to migrate WordPress with WP-CLI uses the same tools.

Frequently asked questions

Do I need root access to install WordPress from the command line?

No. You need SSH access as a user who can write to the web root and a database user with the right privileges. Root is only needed to install system software or move WP-CLI into a system folder, which you can avoid with a home bin folder.

Can I install WordPress with WP-CLI on shared hosting?

Often, yes. Many shared hosts include WP-CLI and SSH access on their plans. Check with your host. If SSH is not available, use the host's one-click installer or upload the files by FTP and run the browser installer.

How do I install a specific WordPress version from the command line?

Add the version option to the download command, for example wp core download with version set to the release you need. This is useful for testing older sites, but use the latest release for live sites because it includes security fixes.

How do I install plugins and themes after a command line install?

Use WP-CLI. The plugin install command with the activate flag installs and turns on a plugin in one step, and the theme install command does the same for themes. You can add these lines to your install script.

Sources

  1. Installing WP-CLI WP-CLI Handbook
  2. wp core install WordPress Developer Resources
  3. wp config create WordPress Developer Resources
  4. Requirements WordPress.org
  5. File Permissions WordPress Developer Resources

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.