How to install WordPress through WP-CLI on AlmaLinux

December 5, 2024 / Sales FAQ WordPress

This article will walk you through installing WordPress through WP-CLI on AlmaLinux.

WP-CLI is a powerful command-line tool for managing WordPress. It enables users to perform tasks like installation, updates, and configuration from the terminal.

Prerequisites:

  1. AlmaLinux Server with root or sudo access.
  2. PHP installed (WordPress requires PHP 7.4 or higher).
  3. MySQL/MariaDB database and a database user for WordPress.
  4. Nginx or Apache web server installed and running.

Follow the steps:

  1. Update Your Server:
    Update all packages to ensure compatibility:

    sudo dnf update -y
  2. Install PHP and Required Extensions
    If PHP is not installed, install it along with the required extensions:

    sudo dnf install -y php php-mysqlnd php-json php-curl php-gd php-mbstring php-xml php-zip
  3. Install WP-CLI
    1. Download WP-CLI:
      curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
    2. Make WP-CLI executable:
      chmod +x wp-cli.phar
    3. Move it to a global location:
      sudo mv wp-cli.phar /usr/local/bin/wp
    4. Verify the installation:
      wp --info
  4. Create a Database for WordPress
    Log in to MySQL or MariaDB and create a database and user for WordPress:

    sudo mysql -u root -p
    

    Then, run the following commands in the MySQL prompt:

    CREATE DATABASE wordpress_db; CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'secure_password'; GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
    

    Replace wordpress_db, wordpress_user, and secure_password with your chosen values.

  5. Set Up the WordPress Directory
    1. Navigate to the web root (usually /var/www/html):
      cd /var/www/html
    2. Create a directory for WordPress:
      sudo mkdir wordpress && cd wordpress
  6. Download and Configure WordPress with WP-CLI
    1. Download WordPress:
      wp core download
    2. Configure the wp-config.php file:
      wp config create --dbname=wordpress_db --dbuser=wordpress_user --dbpass=secure_password --dbhost=localhost --dbprefix=wp_
      

      Replace the database name, user, and password with the details you created in Step 4.

  7. Install WordPress
    1. Run the installation command:
      wp core install --url="http://your-domain.com" --title="Your Site Title" --admin_user="admin_user" --admin_password="admin_password" --admin_email="[email protected]"
    2. Replace:
      1. your-domain.com with your domain name.
      2. Your Site Title with the desired site title.
      3. admin_user, admin_password, and [email protected] with the desired admin credentials.
  8. Set Permissions for WordPress Files:
    Set the correct permissions to allow the webserver to write to WordPress files:

    sudo chown -R apache:apache /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress
    

    If you are using Nginx, replace apache:apache with nginx:nginx.

  9. Finalise the Setup
    Once installed, navigate to http://your-domain.com/wp-admin in a browser to access the WordPress dashboard. Log in with the admin credentials you set in Step 7.

You have successfully installed WordPress on AlmaLinux using WP-CLI. This setup provides a faster and more efficient way to manage WordPress installations

Spread the love