How To Install WP-CLI on Debian 12 and Setup a New WordPress Website via SSH

WP-CLI further streamlines WordPress management on Debian, simplifying tasks through command line instructions.

Publish date: 10/7/2023

Debian is the preferred choice of Linux distribution for many people.

It makes sense when you give it a spin and realize how incredibly lightweight and efficient it is; plus, you can count on it being here five years from now.

It simply does its job and stays out of the way for the most part -- which is exactly what you want from a Linux distribution.

Debian Bookworm (12) is the latest release. You can expect it to be supported until at least 2027, probably later, but they haven't released the official long-term support policy just yet.

That means if you're interested in installing WordPress on Debian 12, you can count on being supported and not having to touch anything besides basic updates for at least four years.

Why not just use a shared host?

If you install your WordPress website on a premium VPS or dedicated provider (cough, cough, like us -- see this for VPS, or, this for dedicated), you'll have a much better experience than you would on a standard shared hosting service.

Plus, you'll not only have more functionality but more power.

Why?

Well, shared hosting tends to be pretty limited because, well... it's a shared environment; they limit it intentionally.

Shared hosts tend to pack lots of websites onto one server.

With VPS, it's still a shared environment, but you tend to have fewer neighbors, especially when it's KVM VPS like we offer over at V.PS because it's simply harder to oversell and cram a bunch of people onto one server.

Of course, with dedicated, you're guaranteed 100% of your resources at any given time, so if being able to access the entirety of your resources at any given time is important to you, and you're not willing to share sometimes with your neighbors, dedicated might be right for you over VPS.

Regardless, either will provide you with a better experience than shared hosting.

Even better? With tools like WP-CLI, this doesn't have to be difficult.

But before we get into installing WP-CLI, let's talk about why you should use WordPress for your website first.

What is WordPress? Why use it for your website?

WordPress is a free and open-source content management system (CMS) that powers over 40% of the web.

It's loved by many for its flexibility, user-friendly interface, and vast ecosystem of plugins and themes.

Whether you're a blogger, business owner, or developer, WordPress offers a free platform to bring your digital visions to life.

The biggest reason to use it to run your website is because it's widely used and open-source, so you can trust the code.

The only thing you can't trust is random plugins, so while there's a plugin that can do everything for you, and WordPress is very powerful -- it's essentially a game of balance.

Why to not use WordPress

Probably the biggest complaint against WordPress is the fact it's not static, so it's storing, pulling/pushing information to a database.

This can lead to more resources used and slower page loading times (but you can also use a static caching plugin and other optimization methods to help this).

But, in return, you gain the convenience WordPress provides as an easy central platform to post a lot of content and store a lot of information, and you can trust your platform to still be supported years from now.

Also, I've tested other static content management systems out there, like Ghost, Grav, and beyond; I've always found myself missing WordPress and coming back to it.

Then, when you compare WordPress to other dynamic content management systems out there like Joomla, it isn't even a fair comparison.

It's WordPress all day. Give WordPress a shot first before you try other content management systems.

If you hate it, you can always switch later. Most of these alternative CMS platforms have 1:1 WordPress migration solutions.

Why Use WP-CLI?

WP-CLI, or WordPress Command Line Interface, is a free command-line tool for managing WordPress installations. It's open-source and currently maintained by Alain Schlesser.

It provides you an incredibly simple way to install and manage your WordPress sites.

There is no need for any complex or bloated panels, and it simplifies the WordPress management process from the command line.

It's a win/win scenario, really; now that being said, let's get started with the installation!

Step 1: Preparing Debian 12

First, you'll need to use your choice of SSH tool and connect to your Debian 12 server.

Then you'll want to ensure your Debian system is up-to-date:

sudo apt update && sudo apt upgrade -y

(If you receive "sudo: command not found", install sudo by running "apt install sudo".)

Step 2: Installing WP-CLI

Next, to install WP-CLI, we must first download it:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

(If you receive "curl: command not found", install curl by running "apt install curl".)

Then we need to install PHP and our web server (Apache, because of PHP):

sudo apt install php php-mysql apache2

And now, verify the installation:

php wp-cli.phar --info

You should see something like this returned:

Installing WordPress via SSH

Next, run the following commands:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

You should now be able to type wp --info, and see the same thing returned.

Step 3: Setting Up a Database for WordPress

WordPress needs a database to store its content. Let's set one up:

sudo apt install mariadb-server

Now, create a database and user for WordPress:

sudo mysql -u your_user -p

Then run the following commands (replacing with your desired information):

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

You now have a database setup for your WordPress website.

Step 4: Installing WordPress

Now, we'll install WordPress.

(Note: You will receive a warning if you try to run any WP-CLI commands as root, and will need to use the --allow-root tag to proceed as root.)

First, we'll navigate to the web root (e.g., /var/www/html) and use WP-CLI to download the latest WordPress version:

cd /var/www/html wp core download

Now, configure WordPress with the database details:

wp config create --dbname=wordpress_db --dbuser=wordpress_user --dbpass=your_password

Finally, install WordPress:

wp core install --url=your_url.com --title="Your Blog Title" --admin_user=admin_username --admin_password=admin_password --admin_email=your_email@example.com

Step 5: Celebrate!

Congratulations! You've successfully installed WordPress on Debian 12 using WP-CLI:

WordPress successfully installed

See? That wasn't as hard as you thought it would be, was it?

It's now time to start building your dream website

WordPress offers a world of possibilities, and with tools like WP-CLI, managing your site becomes even more efficient.

We hope this guide has been helpful, and as always, if you're looking for a reliable hosting provider, consider choosing xTom.

Our self-service VPS option is available here, and you could create a WordPress website within fifteen minutes using it.

Alternatively, for dedicated servers, check out this page, and if you're looking for a custom tailored solution, you can reach out to our global sales department here.

Thanks for reading & happy WordPress-ing!