Ever wished you could set up a WordPress site in minutes, without endless clicks and forms? If you manage multiple websites or crave a faster workflow, installing WordPress from the command line can transform your process.

Command-line installations streamline site setup, save valuable time, and reduce mistakes. Whether you’re a developer or just curious, mastering this skill is a game changer.

In this article, you’ll learn the step-by-step process to install WordPress from the command line, along with tips and helpful insights to make things smooth and simple.

Related Video

How to Install WordPress from the Command Line Interface (CLI): Ultimate Guide

Setting up WordPress using the Command Line Interface (CLI) has transformed the way developers and tech-savvy users deploy websites. With the right commands, you can install, configure, and even manage multiple WordPress sites in a fraction of the time you’d spend using the traditional graphical interface. If you’re curious about how to install WordPress from the CLI, this comprehensive guide will walk you through each step, provide expert tips, and answer your most pressing questions.


What Is WP-CLI and Why Use It?

WP-CLI is the official command-line tool for managing WordPress installations. Think of it as a powerful assistant that lives in your server’s terminal, ready to execute nearly every WordPress management task you can imagine—without clicking a single button. Whether working on shared hosting, a VPS, or local development, WP-CLI can save you hours.

Benefits of Installing WordPress from the CLI

  • Speed: Complete installation and setup in minutes.
  • Automation: Easily script and automate multiple installations.
  • Flexibility: Install themes, plugins, and configure settings without using a web browser.
  • Control: View detailed logs and errors directly in your console.
  • Learning: Understand the inner workings of WordPress and your server better.

Pre-Installation Checklist

Before diving in, make sure you:

  • Have SSH access to your server or local environment.
  • The server meets WordPress requirements: PHP, MySQL/MariaDB, web server (like Apache or Nginx).
  • A database and user are already set up for WordPress (or are ready to create one).
  • The curl or wget and unzip utilities are installed (most environments include these).
  • You have permission to execute commands (sudo/root or your user account is set up appropriately).

Step-by-Step Guide to Installing WordPress from CLI

Let’s break down the installation process so you can get your WordPress site running smoothly.

1. Install WP-CLI

WP-CLI isn’t included by default. You need to install it first.

How to Install WP-CLI (Global Installation)

  1. Download the Phar file:

bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

  1. Check it’s working:

bash
php wp-cli.phar --info

  1. Make it executable:

bash
chmod +x wp-cli.phar

  1. Move it to your path for easy access:

bash
sudo mv wp-cli.phar /usr/local/bin/wp

  1. Test the command:

bash
wp --info

You should see version and environment details.

Tip: Some hosting providers and server panels (like cPanel) already have WP-CLI installed. Type wp --info to check quickly.

2. Download WordPress Core Files

Navigate to the directory where you want your site:

cd /var/www/html/mynewsite

To download the latest WordPress:

wp core download

This will pull down the latest stable version of WordPress to your folder.

3. Create a Database and User (If Needed)

Some hosts require you to manually create a database, but for those with MySQL root access, use the MySQL CLI:

mysql -u root -p

Inside MySQL, run:

CREATE DATABASE mywpdb;
CREATE USER 'mywpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON mywpdb.* TO 'mywpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Security Tip: Always use strong, unique passwords and never share credentials.

4. Configure wp-config.php

Let WP-CLI automatically generate your configuration:

wp config create \
  --dbname=mywpdb \
  --dbuser=mywpuser \
  --dbpass=strongpassword \
  --dbhost=localhost

You can also add unique authentication keys and salts by including --skip-salts (then add securely later) or let WP-CLI fetch them automatically.

5. Install WordPress

Now, install WordPress with your desired settings:

wp core install \
  --url="https://yourdomain.com" \
  --title="Your Site Title" \
  --admin_user="adminuser" \
  --admin_password="anotherstrongpassword" \
  --admin_email="[email protected]"

Output will confirm a successful installation. You’ll see a message with your login credentials.

6. Customize Your Site With Themes and Plugins

Install and activate a theme:

wp theme install astra --activate

Add a plugin:

wp plugin install wordpress-seo --activate

You can add as many themes and plugins as you need using similar commands.


Practical Tips and Best Practices

  • Automate Repetitive Tasks: Use bash scripts and WP-CLI together to deploy multiple sites quickly.
  • Version Control: Keep track of your wp-config.php (without sensitive details) in your git repository for easy replication.
  • Keep WP-CLI Updated: Regularly update WP-CLI to benefit from improvements and security fixes.
  • Use Environment Variables: Instead of hardcoding passwords, consider exporting them as environment variables.
  • Staging with CLI: Set up staging sites rapidly, making it easier to test changes before pushing them live.

Challenges and Considerations

  • Learning Curve: If you’re new to the terminal and command-line tools, expect a brief period of adjustment.
  • Access Level: Not all shared hosts provide SSH or command-line access.
  • Typos Matter: Be cautious; a small typo can result in errors or misconfigurations.
  • Password Security: Avoid using easily guessable passwords, even for local sites.
  • Backups: Before making big changes, back up your files and database. The CLI can also help with this!

Cost Tips Related to Using the CLI

  • No Extra Software Cost: WP-CLI is completely free and open-source.
  • Avoid Premium Installers: Many “auto-installers” from hosting companies bundle extra costs—WP-CLI bypasses these.
  • Faster Deployments Saves Money: The speed and ability to batch tasks means less billable hours or staff time spent.
  • Resource Usage: Command-line tasks are lighter on server resources compared to browser installers, which can lower hosting costs slightly for high-volume tasks.

Quick Start Commands Reference

Here’s a handy reference for your installation journey:

Task Command Example
Download WP-CLI curl -O https://.../wp-cli.phar
Make Executable chmod +x wp-cli.phar
Move to /usr/local/bin sudo mv wp-cli.phar /usr/local/bin/wp
Download WP wp core download
Create Config wp config create --dbname=db --dbuser=user --dbpass=pass
Install WordPress wp core install --url=... --title=... ...
Install Theme wp theme install themename --activate
Install Plugin wp plugin install pluginname --activate
Update WordPress wp core update

Summary

Installing WordPress from the CLI is a game-changer for developers and power users. With just a handful of commands, you can launch, configure, and maintain WordPress sites faster and more reliably than ever before. While there’s a small learning curve, the payoff is immense in speed, automation, and flexibility.

By following the step-by-step instructions above, you’ll have a secure, up-to-date, and fully customized WordPress site up and running—all from your terminal window. If you ever need to manage, update, or troubleshoot your site, WP-CLI remains an invaluable tool in your arsenal.


Frequently Asked Questions (FAQs)

1. Do I need coding skills to install WordPress from the CLI?

Not necessarily. While familiarity with the command line helps, you don’t need to know code. If you’re comfortable navigating folders and typing commands, you can follow guides and reference documentation.


2. What should I do if WP-CLI commands return permission errors?

Permission errors typically mean your user account lacks the rights to write or execute files in the chosen directory. Try using sudo for administrative tasks or check your directory permissions with ls -la.


3. Does WP-CLI work on shared hosting?

Many shared hosting providers now support WP-CLI. If SSH access is enabled, chances are WP-CLI will work. Contact your host or check the documentation to confirm.


4. Is it possible to migrate or clone a WordPress site using WP-CLI?

Yes! WP-CLI can export/import databases, install plugins, and manage content, making migrations and cloning much faster. Combine it with other tools for seamless transfers.


5. How do I keep my CLI-installed WordPress site secure?

Always use strong, unique passwords, ensure all software is current (including WordPress core, plugins, themes, and WP-CLI itself), limit public SSH access, and back up regularly via CLI or your hosting panel.


Embrace the power of the command line and take full control of your WordPress installations today!