How to install WordPress using WP-CLI on Ubuntu 22.04

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to install WordPress using WP-CLI on Ubuntu 22.04 The process is simple, so let’s go for it.

As we all know, WordPress is a CMS tool that allows you to quickly deploy dynamic websites without too much effort. Although it mostly works on blogs, also with certain plugins you can do anything with it.

It is in the plugins and the large number of themes that WordPress excels. Making with a few clicks your site entirely different from the previous one.

Today, we will install it, but using a tool that will help us to make the process even easier.

Install LAMP on Ubuntu 22.04

First, we have to prepare the whole system. Log in via SSH to your server and update it.

sudo apt update
sudo apt upgrade

Then install LAMP. That are Apache, PHP (and its modules) and MariaDB.

sudo apt install apache2 mariadb-server php-{curl,imagick,mbstring,mysql,xml,zip} libapache2-mod-php unzip

Configure and set a root password for MariaDB using mysql_secure_installation.

sudo mysql_secure_installation

Press ENTER and then, you will be able to define a strong root password. In that same script, answer Y to each of the configuration questions.

Now access the MariaDB console

sudo mysql -u root -p

And start creating the database, the user, and the password. Also set appropriate permissions.

CREATE DATABASE wordpressdb;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser@localhost;
FLUSH PRIVILEGES;
exit

Install WP-CLI on Ubuntu 22.04

Now it’s time to install WP-CLI. For this, we leave you the post where I explain it step by step.

How to install WP-CLI on Ubuntu 22.04

When it is complete, you can continue.

Install WordPress on Ubuntu 22.04 using WP-CLI

Now create the folder where the WordPress installation is and access it.

sudo mkdir -p /var/www/wordpress 
cd /var/www/wordpress 

Set the owner to Apache.

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

Thanks to sudo install WordPress as if it were the www-data user like this

sudo -u www-data wp core download

The functional command is wp core download but with sudo you will make it www-data so we save permissions and commands.

The next step is to create a WordPress configuration file.

sudo -u www-data wp core config --dbhost=localhost --dbname=wordpressdb --dbuser=wordpressuser --dbpass=pass
Install WordPress using WP-CLI on Ubuntu 22.04
Install WordPress using WP-CLI on Ubuntu 22.04

Of course, replace the respective values with the ones you have created.

Now, install WordPress.

sudo -u www-data wp core install --url=https://blog.unixcop.com/ --title="Welcome to this test for Unixcop" --admin_name=admin --admin_password=angelo [email protected]

Again, replace the values with your own. You will see an output screen like this:

Success: WordPress installed successfully

Now create a new Virtualhost for WordPress.

sudo nano /etc/apache2/sites-available/wordpress.conf

And add the following content

<VirtualHost *:80>
     ServerAdmin [email protected]
      DocumentRoot /var/www/html/wordpress
     ServerName your-domain.com

     <Directory /var/www/html/wordpress>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
     CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Again, replace the ServerName value with the value of your valid domain. Please don’t hesitate to make other modifications.

Then, enable the new site, the rewrite module and restart Apache to complete the process.

sudo a2ensite wordpress
sudo a2enmod rewrite
sudo systemctl restart apache2

Normally, you install certificates to enable HTTPS.

First, install Cerbot

sudo apt install cerbot python3-cerbot-apache

And to install them, just run

sudo cerbot --apache -d [your-domain]

Follow the instructions and when you are done, you will be able to access https://your-domain to view your site.

Wordpress installed
WordPress installed

Conclusion

In this post, you have learned how to install WordPress but using WP-CLI. It is interesting to do, so I invite you to try it.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook