What is WP-CLI?
WP-CLI (WordPress Command Line Interface) is a command-line tool for WordPress website administration tasks. It offers a convenient alternative to the WordPress admin, allowing you to update plugins, configure multisite installations, and execute various tasks efficiently without using a web browser.
Before installing WordPress using WP-CLI, you need to install the LEMP stack.
A LAMP stack is a collection of open-source software commonly installed to allow a server to host dynamic websites. The acronym LAMP stands for the Linux operating system, Apache web server, MySQL database, and PHP for processing dynamic content.
You can skip the installation if you have already installed the LEMP stack.
Install LEMP Stack for WordPress:
Install Apache Web Server:
First, install the Apache web server by executing the following command:
yum install httpd httpd-tools
Once the installation is complete, enable Apache to start automatically upon system boot, start the web server, and verify the status using the commands below:
systemctl enable httpd
systemctl start httpd
systemctl status httpd
To make the website available to the public, edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
systemctl restart httpd
Verify that the web server is running and accessible by accessing your server’s IP address or domain name. Then, restart the web server to reflect the changes made.
Install PHP:
Enable the EPEL and REMI repositories which provide the latest PHP packages:
sudo dnf install -y epel-release
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Enable the PHP 8.0 module using the dnf module command:
sudo dnf module enable php:remi-8.0
Install PHP 8 and the required extensions. You can add or remove extensions as per your requirement:
sudo dnf install -y php php-cli php-fpm php-mysqlnd php-zip php-gd php-mbstring php-xml php-json php-curl php-opcache php-intl php-soap php-xmlrpc php-pecl-imagick
Verify the PHP installation by executing the following command:
php -v
Restart the Apache server:
sudo systemctl restart httpd
Install MariaDB Server:
MariaDB is a popular database server. Execute the following command to install MariaDB:
yum install mariadb-server mariadb
Once the installation is complete, enable MariaDB to start automatically upon system boot, start MariaDB, and verify the status using the commands below:
systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb
Secure the MariaDB installation by issuing the following command:
sudo mysql_secure_installation
You will be prompted to enter a password for the MariaDB root user and answer a few questions to secure your installation.
Log in to the MariaDB command line as the root user and create a database and database user for WordPress:
sudo mysql -u root -p
Create the database for WordPress by executing the following command:
CREATE DATABASE wordpress;
Create a database user and grant them privileges for the newly created wordpress database, replacing wpuser and password with the username and password you wish to use:
CREATE USER 'wpuser' IDENTIFIED BY 'FBPeny13116';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser';
FLUSH PRIVILEGES;
Now, we are ready to install WordPress using WP-CLI.
Install WordPress via WP-CLI:
Download WP-CLI:
We can Download the WP-CLI Phar file using curl. Execute the following command to install WP-CLI.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Make the downloaded file executable by executing the following command.
chmod +x wp-cli.phar
Move the executable to a directory that is in your system's PATH. /usr/local/bin is a common choice:
sudo mv wp-cli.phar /usr/local/bin/wp
Verify the Installation using the following command:
wp --info
Install WordPress:
Navigate to the web directory where you want to install WordPress. This is usually the web root directory, like /var/www/html:
cd /var/www/html
Download the latest version of WordPress using WP-CLI:
wp core download
Generate the wp-config.php file with your database details:
wp config create --dbname=wordpress --dbuser=wpuser --dbpass=FBPeny13116 --dbhost=localhost --dbprefix=wp_
Replace wordpress, wpuser, and FBPeny13116 with your actual database details.
Run the installation command with your site details:
wp core install --url="http://neiltestweb.com" --title="Your Blog Title" --admin_user="admin" --admin_password="FBPeny13116" --admin_email="[email protected]"
Replace http://neiltestweb.com with your domain name, and fill in the other details as appropriate.
That's all. WordPress has been installed successfully. You can verify it by accessing your domain name or server IP address.
Conclusion:
In conclusion, installing WordPress via WP-CLI on AlmaLinux is a streamlined process that offers significant advantages for web developers and administrators. By using the command line interface, users can bypass the traditional web-based installation method, resulting in a faster and more controlled setup.
By following this article, you can quickly get your WordPress site up and running, allowing you to focus more on customization and content creation. WP-CLI not only simplifies the installation process but also provides powerful tools for managing your WordPress site, making it an essential tool for any WordPress user on AlmaLinux.