Installing WordPress Using Command Line Interface (CLI)

Humayun Ahmed
2 min readSep 22, 2023

--

Introduction

In this tutorial, we’ll walk you through the process of installing WordPress using the Command Line Interface (CLI). This method is efficient and allows for greater control over your WordPress installation. Let’s get started!

Prerequisites

Before you begin, make sure you have the following prerequisites:

  1. A server: You can use a local development environment (e.g., XAMPP or MAMP) or a remote server (e.g., AWS, DigitalOcean) where you have SSH access.
  2. SSH Access: You need SSH access to your server.
  3. MySQL Database: Create a MySQL database and have the credentials ready.

Step 1: Connect to Your Server

Open your terminal and connect to your server using SSH. Replace your-username and your-server-ip with your actual server username and IP address:

ssh your-username@your-server-ip

Enter your password when prompted.

Step 2: Update Your Server

Before installing WordPress, it’s a good practice to update your server to ensure you have the latest software packages. Run the following commands:

sudo apt update 
sudo apt upgrade

Step 3: Install LAMP Stack

WordPress requires a LAMP (Linux, Apache, MySQL, PHP) stack. Install these components on your server:

sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql

Step 4: Secure MySQL

Run the MySQL security script to set a root password and remove test databases:

sudo mysql_secure_installation

Step 5: Create a MySQL Database

Log in to MySQL and create a new database, replacing your-database, your-username, and your-password with your desired values:

mysql -u root -p
CREATE DATABASE your-database;
CREATE USER ‘your-username’@’localhost’ IDENTIFIED BY ‘your-password’;
GRANT ALL PRIVILEGES ON your-database.* TO ‘your-username’@’localhost’;
FLUSH PRIVILEGES;
EXIT;

Step 6: Download and Configure WordPress

Download the latest version of WordPress and extract it:

cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo rm latest.tar.gz

Create a WordPress configuration file:

cd /var/www/html/wordpress
sudo cp wp-config-sample.php wp-config.php

Edit the configuration file with your database information:

sudo nano wp-config.php

Replace the database name, username, and password with your own:

define(‘DB_NAME’, ‘your-database’);
define(‘DB_USER’, ‘your-username’);
define(‘DB_PASSWORD’, ‘your-password’);

Step 7: Set Permissions

Set the correct permissions for WordPress:

sudo chown -R www-data:www-data /var/www/html/wordpress

Step 8: Enable Apache Rewrite Module

Enable the Apache rewrite module to allow for pretty permalinks:

sudo a2enmod rewrite

Step 9: Restart Apache

Restart Apache to apply the changes:

sudo systemctl restart apache2

Step 10: Complete WordPress Installation

Open a web browser and navigate to your server’s IP address or domain name. You should see the WordPress installation page. Follow the on-screen instructions to complete the installation.

Conclusion

Congratulations! You’ve successfully installed WordPress using the Command Line Interface. You can now start customizing your website and publishing your blog posts.

--

--

Humayun Ahmed

Front-end developer passionate about crafting captivating digital experiences with clean code and the latest design trends.