Featured Image



Installing WordPress via SSH using WP-CLI is one of the fastest, most secure, and efficient methods available for developers and system administrators. Whether you’re setting up a new website, migrating an existing one, or managing multiple WordPress installations, WP-CLI allows you to complete the process in minutes—without ever leaving the command line. This guide covers everything you need to know to install WordPress via SSH using WP-CLI, including prerequisites, step-by-step instructions, best practices, and troubleshooting tips.

Why Use WP-CLI to Install WordPress via SSH?

is a powerful tool that allows you to manage WordPress installations directly from the command line. When combined with SSH (Secure Shell), it provides a secure, remote connection to your server, enabling you to install, configure, and manage WordPress without relying on a web browser or control panel like cPanel. Here’s why this method is preferred:

  • Speed: WP-CLI executes commands instantly, reducing the time it takes to install and configure WordPress.
  • Security: between your local machine and the server, protecting sensitive information like passwords and database credentials.
  • Automation: , allowing you to automate repetitive tasks like installations, updates, and backups.
  • Remote Management: SSH allows you to manage your server from anywhere in the world, making it ideal for remote teams and distributed workflows.
  • No Browser Dependency: You don’t need to open a web browser or log into a control panel, which is especially useful for headless servers or environments without a GUI.

Prerequisites for Installing WordPress via SSH Using WP-CLI

Before you begin, ensure you have the following:

  • SSH Access to Your Server: You need a server with SSH enabled. Most Linux-based hosting providers (e.g., DigitalOcean, Linode, AWS, or Vultr) offer SSH access by default. If you’re using shared hosting, check with your provider to confirm SSH access is available.
  • User with Sudo Privileges: You need a user account with sudo privileges to install software and make system-level changes.
  • WP-CLI Installed on Your Server: WP-CLI must be installed on the server where you plan to install WordPress. If it’s not already installed, don’t worry—we’ll cover how to install it in the next section.
  • Domain Name Pointing to Your Server: While not strictly necessary for the installation, you’ll need a domain name configured to point to your server’s IP address if you want to access your WordPress site via a URL.
  • Database Credentials: You’ll need a MySQL or MariaDB database and user credentials for WordPress to store its data.

Step 1: Connect to Your Server via SSH

To get started, open your terminal (or command prompt if you’re on Windows) and connect to your server using SSH. Replace username with your server’s username and server_ip with your server’s IP address:

ssh username@server_ip

If this is your first time connecting to the server, you may be prompted to verify the server’s fingerprint. Type yes to continue. You’ll then be prompted to enter your password. Once authenticated, you’ll have access to the server’s command line.

Step 2: Install WP-CLI on Your Server

If WP-CLI isn’t already installed on your server, you can install it with the following commands:

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

To verify that WP-CLI is installed correctly, run:

wp --version

You should see the installed version of WP-CLI, confirming that the installation was successful.

Step 3: Create a Database for WordPress

WordPress requires a database to store its content, settings, and user information. You can create a database and user using MySQL or MariaDB. Log in to your MySQL server as the root user:

mysql -u root -p

Enter your MySQL root password when prompted. Once logged in, run the following commands to create a database and user for WordPress. Replace database_name, database_user, and password with your desired values:

CREATE DATABASE database_name;
CREATE USER 'database_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Write down the database name, user, and password, as you’ll need them in the next step.

Step 4: Download and Configure WordPress Using WP-CLI

Now that your database is ready, you can use WP-CLI to download and configure WordPress. Navigate to the directory where you want to install WordPress. For most servers, this will be the public_html or www directory:

cd /var/www/html/

Use WP-CLI to download the latest version of WordPress:

wp core download

Next, create a wp-config.php file with your database credentials:

wp config create --dbname=database_name --dbuser=database_user --dbpass=password --dbhost=localhost

Replace database_name, database_user, and password with the values you created in Step 3.

Step 5: Install WordPress Using WP-CLI

With WordPress downloaded and configured, you can now install it using WP-CLI. Run the following command, replacing the placeholders with your site’s details:

wp core install --url=your_domain.com --title="Your Site Title" --admin_user=admin_username --admin_password=admin_password --admin_email=your_email@example.com
  • url: The domain name or IP address of your WordPress site.
  • title: The title of your WordPress site.
  • admin_user: The username for the WordPress admin account.
  • admin_password: The password for the WordPress admin account.
  • admin_email: The email address associated with the WordPress admin account.

Once the installation is complete, you’ll see a success message confirming that WordPress has been installed.

Step 6: Secure Your WordPress Installation

Security is critical for any WordPress site. Here are some essential steps to secure your installation:

  • Update File Permissions: Ensure that your WordPress files and directories have the correct permissions. Run the following commands to set secure permissions:
    find /var/www/html/ -type d -exec chmod 750 {} \;
    find /var/www/html/ -type f -exec chmod 640 {} \;
  • Disable File Editing: Prevent users from editing WordPress files directly from the dashboard by adding the following line to your wp-config.php file:
    define('DISALLOW_FILE_EDIT', true);
  • Install a Security Plugin: Use WP-CLI to install a security plugin like Wordfence or iThemes Security:
    wp plugin install wordfence --activate
  • Enable SSL: If you haven’t already, install an SSL certificate to encrypt data transmitted between your server and users. , and you can install one using Certbot:
    sudo apt-get install certbot
    sudo certbot --apache -d your_domain.com

Pro Tips for Installing WordPress via SSH Using WP-CLI

Here are some expert tips to help you get the most out of WP-CLI and SSH:

  • Use WP-CLI Aliases: If you manage multiple WordPress sites, create aliases for common commands to save time. For example, you can create an alias for updating all plugins:
    alias wp-update-all='wp plugin update --all'
  • Automate Installations with Scripts: Write bash scripts to automate the entire WordPress installation process. This is especially useful if you frequently set up new sites or manage client projects.
  • Monitor Server Resources: Use tools like htop or glances to monitor your server’s resource usage during and after the installation. This helps you identify potential performance bottlenecks.
  • Backup Your Site Regularly: Use WP-CLI to create backups of your WordPress site and database. For example, you can export your database with:
    wp db export backup.sql
  • Optimize Your Database: Over time, your WordPress database can become cluttered with unnecessary data. Use WP-CLI to optimize your database:
    wp db optimize
  • Use WP-CLI for Multisite Installations: If you’re setting up a , WP-CLI can simplify the process. Use the following command to enable Multisite:
    wp core multisite-install --url=your_domain.com --title="Your Network Title" --admin_user=admin_username --admin_password=admin_password --admin_email=your_email@example.com
  • Leverage WP-CLI for Debugging: WP-CLI provides several commands for debugging, such as wp doctor, which checks your WordPress installation for common issues.
  • Stay Updated: with new features and bug fixes. Keep it updated to ensure you have access to the latest tools and improvements:
    wp cli update

Frequently Asked Questions

1. What is WP-CLI, and why should I use it?

WP-CLI is a command-line tool for managing WordPress installations. It allows you to perform tasks like installing WordPress, updating plugins, and managing users without using a web browser. WP-CLI is faster, more secure, and ideal for automating repetitive tasks.

2. Can I install WordPress via SSH on shared hosting?

It depends on your hosting provider. Some , while others do not. Check with your provider to confirm whether SSH access is available. If it is, you can follow the steps in this guide to install WordPress using WP-CLI.

3. What if I get a “Permission Denied” error when running WP-CLI commands?

This error typically occurs if the user you’re logged in as doesn’t have the necessary permissions to execute WP-CLI commands. Try running the commands with sudo, or switch to a user with the appropriate privileges.

4. How do I update WordPress using WP-CLI?

To update WordPress to the latest version, run the following command:

wp core update

5. Can I use WP-CLI to install themes and plugins?

Yes! WP-CLI makes it easy to install and manage themes and plugins. For example, to , run:

wp theme install astra --activate

6. What should I do if my WordPress site isn’t loading after installation?

If your site isn’t loading, check the following:

  • Ensure your domain name is correctly pointing to your server’s IP address.
  • Verify that your web server (e.g., Apache or Nginx) is running.
  • Check your wp-config.php file to ensure the database credentials are correct.
  • Review your server’s error logs for clues about what might be wrong.

7. Is it safe to install WordPress via SSH?

Yes, installing WordPress via SSH is safe and secure. SSH encrypts all data transmitted between your local machine and the server, protecting sensitive information like passwords and database credentials.

8. Can I use WP-CLI to manage multiple WordPress sites?

Absolutely! WP-CLI is an excellent tool for managing multiple WordPress sites. You can use it to update plugins, themes, and WordPress core across all your sites simultaneously.

Conclusion

Installing WordPress via SSH using WP-CLI is a game-changer for developers and system administrators. It offers speed, security, and efficiency, allowing you to set up and manage WordPress sites with ease. By following the steps in this guide, you can install WordPress in minutes, secure your installation, and leverage WP-CLI to automate repetitive tasks. Whether you’re managing a single site or a network of WordPress installations, WP-CLI is an invaluable tool that streamlines your workflow and enhances your productivity.

With the right knowledge and tools, you can take full control of your WordPress installations and ensure they run smoothly, securely, and efficiently.