Intro to Shell (CLI) for Plesk Linux

plesk-linux-shell

There’s a lot of Linux shell intro guides out there. There’s also a lot of intro to Plesk guides out there. But a reference guide to help you find the most common paths and command line utilities for managing your Linux VPS or dedicated server running Plesk is harder to come by.

Before we get started, if you haven’t got any experience with Linux shell, check out one of the many intro to Linux shell guides you can find with a Google search, then come on back to learn the specifics of exploring Plesk from shell.

Most of what you’ll find in this guide is more helpful to those with their own VPS or dedicated server that runs Plesk Panel, however some of this info will be handy for shared or reseller hosting users as well, like the PHP binary location.

To view these directories or access the files and commands, you’ll need to connect via Secure SHell (SSH):

  • macOS: the Terminal app is built in. Open Terminal and run ssh root@{server_hostname_or_ip} and then enter your root password found in the Client Centre.
  • Windows: most use the PuTTY app. Install it, open it and connect using the server hostname or IP found in the Client Centre along with the root password. Username is ‘root’.

Common Paths / Directories

Plesk User Home Directory: /var/www/vhosts/<primary_domain>

This is the same one you see when you open the File Manager in Plesk. Within that directory will be a few others, such as:

  • httpdocs — the default web root for your primary domain (unless you changed it)
  • A web root folder for each of your subdomains and addon domains that is typically the subdomain or domain itself (like mydomain.com) unless you altered it when you created it.

Note: we recommend sticking with the default path provided by Plesk. For security reasons it’s best to not have web root folders nested within another domain’s web root. Example: don’t put an addon domain’s web root within the httpdocs folder like httpdocs/new_domain

Shell User Configuration File:

  • Shared hosting user: ~/.bash_profile
  • root user (VPS): /var/www/vhosts/<primary_domain>/.bash_profile

Within this file is your PATH variable which is preconfigured to use certain versions of PHP, node and other such utilities. You may adjust the path here, should other versions be available for you to use (binary paths described below in this article).

Plesk Mail Storage Directory: /var/qmail/mailnames/<domain>/<mailname>

Where the mailname is the first part of the email address, such as ‘john’ from john@smith.com.

Even though the directory ‘qmail’ would imply it’s for the qmail mail server, even when you use postfix, Plesk stores messages at this path.

Within the Maildir, your mail folders are hidden folders, meaning they start with a period (.) and will only be visible using the ls -al command. For example, your default Spam folder will be called: .Spam

Plesk Web Server Config Files

These are all fairly standard.

Apache: /etc/httpd/conf/httpd.conf for the core config, and /etc/httpd/conf.d/ for most of the extras.

Plesk stores its specific configs in /etc/httpd/conf/plesk.conf.d/

Nginx: /etc/nginx/nginx.conf and /etc/nginx/conf.d for most of the extras.

Plesk stores its specific nginx configs in /etc/nginx/plesk.conf.d/

But! Each vhost has its own area where you’re expected to add config and make changes:

Apache: /var/www/vhosts/system/<domain>/conf/vhost.conf
Nginx: /var/www/vhosts/system/<domain>/conf/vhost_nginx.conf

These files are also editable from within Plesk (only if you’re an admin) when you choose “Apache and nginx config” under any given domain. Near the bottom of each of the apache and nginx sections are the advanced configurations which edit these files.

You’ll notice that these paths are similar to those to the vhost’s web roots, but are instead contained within the system folder in the vhosts path. In the past few years Plesk moved these config files out of the user root folder and into that system folder for better security and to ensure all configs are available in one spot.

Handy Binaries / Programs

Plesk Tools Directory: /usr/local/psa/bin

In recent versions (12+), the Plesk devs have also provide a shorthand mechanism for accessing Plesk binaries in case you wanted to avoid typing /usr/local/psa/bin. It looks like this:

plesk bin <command>

Plesk PHP Binary Directory: /opt/plesk/php/<version>/bin/php

Example: /opt/plesk/php/7.4/bin/php

Node Binary Directory: /opt/plesk/node/<version>/bin/node

Example: /opt/plesk/node/8/bin/node

Tip: if you’re using shared hosting with Plesk, these PHP binaries are available in the same locations thanks to our optimized chroot configuration.

Server Monitoring Tools

The built in OS binaries are often the default in Plesk, and they’re in the usual place: /bin/php, but the /opt/ dir is where you’ll find the additional PHP version binaries.

htop

We install htop during server-setup for those that opt for our Hands-On Support package. It’s a great utility for easy monitoring of system services. It shows you real-time memory and CPU usage as well as a list of active processes in order (by default) of CPU usage.

lsof -p <process_id>

While most processes make it pretty clear what website they belong to by listing the system user that triggered it, if a process does not have such an indicator, the above lsof command can help to narrow that down by listing all of the files that a process is accessing.

You’ll need to use htop to find the process ID before running this.

It’s going to spit out a comprehensive list of every single file the program uses. Most of the stuff at the top of the list are builtin system libraries that aren’t going to tell you much. You’ll probably find the info you want closer to the bottom of the list of open files, such as the currently active socket file (which often has a path leading to the website’s vhost root) or even more straightforward: an open log file that leads to the vhost system root.

Interacting with Plesk via CLI

Obtaining a list of domains:

plesk bin domain -l

If you read above you’ll know that the ‘plesk bin’ prefix means we’re calling the ‘domain’ tool from Plesk’s binary path via shorthand. domain -l is simply going to pull a list of hosted domains (including subdomains) from Plesk’s database for you.

You can then run plesk bin domain -i <domain> to get more info about the domain.

Finding Logs

Log files are typically in the defaults for your OS, which for most Linux operating systems are in /var/log. Here’s some common examples:

  • /var/log/maillog — for all mail service related logging
  • /var/log/httpd/error_log — for server-level apache logging
  • /var/log/nginx/error.log — for server-level nginx logging

Website specific logs can be easily viewed within Plesk, but you can also access them with Shell here:

/var/www/vhosts/system/<domain>/logs

Monitoring Logs

To live monitor any given log file, run:

tail -f <log_file>

Press Ctrl-C to stop monitoring and return to shell. Or you can search the logs like this: grep "search_word" <log_file>

To monitor all web server / website related error logs server-wide:

tail -f /var/log/nginx/error.log /var/log/httpd/error_log /var/log/plesk-php*/error.log -n 0

To monitor errors on a specific website, including apache, nginx, and php-fpm:

DOMAIN=mydomain.com
tail -f /var/log/plesk-php*/error.log -n 0 | grep $DOMAIN & tail -f /var/www/vhosts/system/$DOMAIN/logs/*error*log -n 0

Notes:

  • grep is super powerful, so if you need to do more advanced searching, look up tutorials on using grep.
  • with tail, the -n is the number of lines to show prior to the moment you started monitoring. It defaults to 10 if you don’t specify.

Looking for a Plesk VPS host with the experience to provide solid support when you need it? Look no further.

If there’s commands or log files on your Plesk VPS that you think we missed, let us know by leaving a comment below! We’re always looking to improve our guides.

Jordan Schelew

Jordan has been working with computers, security, and network systems since the 90s and is a managing partner at Websavers Inc. As a founder of the company, he's been in the web tech space for over 15 years.
WS-Logo-only-image-large

About Websavers

Websavers provides web services like Canadian WordPress Hosting and VPS Hosting to customers all over the globe, from hometown Halifax, CA to Auckland, NZ.

If this article helped you, our web services surely will as well! We might just be the perfect fit for you.

1 Comment

  1. Nasir Mehmood Malik on July 15, 2020 at 12:09 am

    Wonderful, quite helpful article. Keep it up bro.

Leave a Comment