This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How tmux Helps You Manage Your Cloudways Server via SSH

Updated on December 20, 2021

8 Min Read
tmux

This article complements and extends a video I’ve created on using SSH and tmux for managing my Cloudways servers. In the video, you can watch me use tmux to manage SSH connections to multiple Cloudways servers and use the command-line tool htop to analyze the server load.

You can watch the full video here:

Since there is a lot more to this conversation than just what I covered in the video, I wanted to write this complimentary article and give more insights on why I’m using tmux and why I rely on SSH for server administration.

To give you a bit of background, I am no server administrator by training – not even a trained web developer. Everything I do is self-taught. For me, learning by doing is my favorite approach to acquire skills or tackle the challenges I’m facing. I’m not a friend of formal education anymore (I quit a master’s degree in IT Security) and instead believe in getting involved with technology to gain an understanding of how it works.

Please keep this approach in mind while watching the video and reading through this article. As you will see, I’ve divided the article into two sections. Each could be a really long article or probably multiple articles on their own, but I thought they go nicely together in this context.

Managing Your Server via SSH

One of the advantages of using Cloudways for hosting is that you have command-line access to your servers and your applications. While it’s not root access, you can do a lot of things on the command-line.

From my perspective, it’s reasonable that I don’t get root access to my Cloudways servers. Imagine what maintaining 20k servers look like if every server admin installs their own tools and packages. That is an impossible feat to achieve. With this being said, Cloudways gives us access to WP-CLI and many other standard tools. And that’s plenty to work with in maintaining your servers and staying informed of what the servers are doing.

It took me a while to understand the benefits of managing my servers via SSH but now I don’t see any other way of handling this matter. My main reasons to go onto the command-line are:

  • I don’t have to wait on a web application to load to see what I want to see.
  • The login is managed via SSH keys, so I don’t have to enter my password unnecessarily.
  • I can keep SSH sessions running and don’t have to worry about logging in and logging out.
  • I have access to WP-CLI and can do things that I cannot do in the regular WP Admin dashboard.
  • I can automate task execution using cron jobs and scripts.
  • I don’t have to move my hands away from the keyboard to use the mouse and can keep them relaxed.

Please note that as prerequisites, you should have some form of SSH client installed. If you’re on Linux or Mac, you can simply use the pre-installed Terminal applications. If you’re a Windows user like myself, you can either install PuTTY or use the Bash that comes with the Windows Subsystem for Linux (which is what I prefer).

If you don’t feel like installing any additional software, you can also open an SSH terminal from the Cloudways Console but that is no solution I’d recommend for everyday use. As you’ll see, the beauty in using a command-line interface is to not have to log in to a web application like the Cloudways Console.

Why Should You Use Command-Line?

Using the command-line felt very intimidating at first. That is as true for server administration as it is for using the command-line on my local PC or Mac. Most of my knowledge about the command-line comes from tutorials I read on the Internet or a friend of mine who’s working at Cisco. It’s all learning by doing.

Especially when configuring a server or a service like a web server or server-side cache, it’s easy to break things. Not knowing what I was doing and not having any experience with using command-line tools didn’t necessarily inspire confidence in me to try managing my servers via SSH.

I eventually got the hangover it and discovered the benefits of using the command-line by following three rules:

  1. Always take one step at a time and try to understand exactly what you’re doing in this step.
  2. Always have a restore point or backup in case you break things.
  3. Always test in a safe environment and never execute a command-line tool on a live website for the first time.

With those rules, I knew that nothing really could go wrong. I created a staging-version of my live website on Cloudways using the “Clone” functionality and just followed their tutorial of logging in via SSH. Once logged in, I began playing around with WP-CLI and other simple server management tools like htop.

If you follow a similar approach, you should be in a good position to learn safely how to use the command-line. It helps to have a background in development or IT but I don’t think that it is necessary. Simply think about the command-line as a way to interact with your computer, just as you’re doing with your mouse on the desktop. Especially with WP-CLI, it’s easy to take the first steps on the command-line and see the results on your WP Admin dashboard.

Use Case: Debugging Server Load Using htop

In the video, you’ll see that I am using the tool htop to analyze the server resource usage. htop is a standard tool that gives you insights on what’s currently happening on your server in real-time. Considering that the Cloudways Platform monitoring data sometimes has slight delays, it is extremely useful to learn more about using htop.

Whenever the Cloudways bot notifies me that the CPU or RAM usage spikes, I log in to the respective server via SSH and run htop. Within seconds, I can identify the process and application that takes up the resources. What would take me a minute or two using the Cloudways web platform is done within 10-20s.

This is what htop looks like in practice:

htop

The debug process then is to identify the application that takes up unusual amounts of server resources via htop and examine that application in greater detail. If you see a PHP process of that application taking up the CPU or RAM, you know that it’s likely something related to a WP plugin or your theme. It’s often the case that processes scheduled through WP-Cron have piled up and now get executed all at once, thus overloading your server.

If you see a MySQL or MariaDB process taking up the server resources, you know that you don’t have to look into the plugins or the theme but into the database. I’ve seen databases lose their indices and thus cause SQL queries to run extremely slow. It can take ages for you to identify the sources of the problem if you don’t know whether it’s PHP or MySQL causing the problems.

As you can imagine, this is just the tip of the iceberg of what htop can do. Here’s a list of practical htop examples that take my example up to the next level.

Use Case: Using WP-CLI on Cloudways Servers

Knowing how to use WP-CLI can be a true game-changer for your daily development approach. Installing a vanilla WP without moving the mouse? No problem. Deleting all transients with installing an additional plugin? Easy. Analyzing which hooks slow down the loading time of your website the most? You can do that with WP-CLI too.

It’s truly amazing that Cloudways gives us access to WP-CLI over the command-line. You can easily build tools that install your default WordPress plugin stack and theme. Or you can use WP-CLI to download a database backup of your site within seconds or minutes (well, that depends on the size of your database).

Here’s the catch: you have to use the command-line to access WP-CLI. And thus you have to log in to your server via SSH in order to execute WP-CLI commands on your Cloudways-hosted websites.

If there is no other reason for you to familiarize yourself with the command-line and to start using SSH to manage your servers, WP-CLI should be it. Let me give you just three examples that will be worth trying out:

1. Optimizing and Repairing Your Database

As we don’t get PhpMyAdmin on Cloudways, having the option to optimize and repair your WordPress database using WP-CLI is handy. By using wp db optimize and wp db repair, you can get your database up to speed and stabilize its processes.

2. Creating a Child Theme Within Seconds

Yes, you could create a child theme by manually creating and uploading a new directory with the respective style.css and functions.php into wp-content/themes – but why bother if you can run a simple command that handles everything for you?

No more looking at the Codex to check if specifications changed, no more SFTP logins and file transfers. Just run the following command in the command-line and your child theme is ready to be used:

wp scaffold child-theme SLUG –parent_theme=SLUG –theme_name=TITLE –author=FULL-NAME –author_uri=URI –theme_uri=URI –activate –force

Note that this command will activate the child theme by default. If you don’t want to do that, omit “–activate –force” at the end of the command.

3. Create Dummy Content for Development Purposes

All developers need data to work with during their development phases. What if you didn’t have to manually create and duplicate posts and pages in the WP Admin dashboard? What if WP-CLI could create any amount of dummy data for you with a simple command?

By running wp post generate –count=10 you can generate ten demo posts in seconds. The same functionality works for creating pages, WooCommerce dummy data and even lets you add lorem ipsum contents to the posts.

Simply using curl http://loripsum.net/api/4 | wp post generate –post_content –count=10 will create 10 posts that each have four paragraphs of Lorem Ipsum text.

Why Did I Recommend tmux?

I hope, the examples I’ve given above are enough to get you excited about trying SSH to maintain your Cloudways servers. Let me take this article a bit further and talk about why I’m using tmux to manage my SSH sessions.

In short, tmux lets you manage multiple terminal sessions at once. Meaning, when you do something in the terminal while you’re in a tmux session, tmux will keep track of what you’re doing. Even if you accidentally close the terminal, your session will not be lost. You can simply go back to where you left off with one command and continue working.

tmux also lets you script sessions. For example, if you tend to execute the same commands for setting up development environments over and over again, you could automate those commands using tmux.

To be frank, I’m not sure if I will ever learn all tmux has to offer – simply because it is so much. It is similar to Google Spreadsheets or MS Excel – we all know how powerful those tools are but use possibly 5% of their functions on a daily basis. However, I know enough to use tmux in my daily WordPress development.

As you can see in the video, I use tmux to keep track of my SSH sessions. That saves me from logging in to my Cloudways servers again and again. I just re-attach to the tmux session called “Cloudways” and continue working on my servers. No magic involved, but even this small tweak saves me time every day. I do the same for my private Raspberry Pi’s at home (I’m a smart home nerd in my free time).

tmux is cool because it allows you to save time, become more productive and reduces your hand movements throughout the day. If you’re like me, you easily get wrist pain from long days at the PC. Even with an ergonomic mouse, it wouldn’t go away for me. What worked though, was reducing the movements I was making with my hands.

Switching the right hand from keyboard to mouse every so often always felt like an interruption in flow. I had to think about where to put my right hand, there was a slight strain on the wrist and I got out of the flow of writing. With tmux, you can achieve almost mouse-free productivity once you get the hang of it.

I would love to dive deeper into tmux, but that is outside the scope of this article. Instead, I’ll give you a few articles that’ll help you get started with tmux or improve your skills: Getting started with tmux by Linuxize, Benefits of using tmux by Keegan Lowenstein, and A minimalist guide to using tmux by Peter Jang.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Beautifully optimized hosting for WordPress and Magento”

Arda Burak [Agency Owner]

Jan Koch

Jan Koch run the WordPress agency WP Mastery and is a WP developer. He loves scaling WP agencies, using technology to automate processes, writing code for WordPress and contributes to the community by sharing his experience online.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Unleash The Cloud.
Not Budgets.

For 4 Months +
Up To 30 Free Migrations

Cyber Week

SAVINGS
Time Left In Offer
  • 0

    Days

  • 0

    Hours

  • 0

    Minutes

  • 0

    Seconds

40% OFF

On All Plans

GET THE DEAL NOW