The panel graphs tell you what happened. The command line tells you what is happening this second, and that is what you want when the phone rings and the site is slow now. This article is a handful of commands worth knowing by heart.
First: do you have SSH?
| 1 |
Open cPanel and look for Terminal. If it is there you need install nothing: it runs in the browser and you are already logged in as your account.
|
|
| 2 |
Or look for SSH Access, which is where you manage keys for logging in from your own computer.
|
|
| 3 |
From your computer, the connection is ssh -p 2299 user@server. The port is 2299, not 22.
|
|
| 4 |
If neither is there, your plan has no shell switched on. Ask us and say what it is for. In the meantime, cPanel’s Resource Usage gives you nearly everything this article gives: see how to monitor your site performance in cPanel.
|
|
|
Do not retry failed logins. The firewall counts failures and after a few locks out the address they came from, which also cuts off your website and your e-mail. Two wrong attempts and you stop and check the details. Already locked out: how to unblock your IP address.
|
The trap that catches everybody
Inside your account, some commands talk about you and others talk about the whole machine, and nothing on screen tells you which is which. Knowing this before you look saves you a wrong conclusion.
| Command |
Who it is talking about |
| ps aux |
Your account. It only shows your own processes, and there are few. It is the right command for how many requests you are serving right now. |
| top |
Your account. The same thing, refreshing itself. Quit with q. |
| free -m |
The whole machine. That is not your memory, it is the server’s. Draw no conclusions from it. |
| uptime |
The whole machine. The load it shows is everybody added together. A high number does not mean the problem is yours. |
| nproc |
The whole machine. Those are the server’s processors, not the slice allotted to you. |
| df -h |
The whole machine. For YOUR space, look at the statistics column in cPanel. |
In short: to find out whether you are at the ceiling, the right place is still cPanel’s Resource Usage, which plots your usage against your limit. The command line is for seeing what is consuming, and that the panel does not show.
The commands worth having
| To find out |
Type |
| How many PHP processes you have running now |
ps aux | grep lsphp | wc -l |
| Which ones, and how long they have been alive |
ps aux | grep lsphp |
| Who asked for the most pages today |
awk '{print $1}' ~/access-logs/yourdomain | sort | uniq -c | sort -rn | head |
| Which page was asked for most |
awk '{print $7}' ~/access-logs/yourdomain | sort | uniq -c | sort -rn | head |
| The most recent PHP errors |
tail -n 50 ~/logs/yourdomain.php.error.log |
| Which folders take the most space |
du -sh ~/public_html/* | sort -h | tail |
| How many files a folder holds |
find ~/public_html -type f | wc -l |
The live logs are in ~/access-logs/, one file per domain, plus one ending in -ssl_log for secure traffic, which today is nearly all of it. Previous months sit compressed in ~/logs/.
|
To watch it arrive, live: tail -f ~/access-logs/yourdomain-ssl_log . Each line is one request, at the moment it happens. During a bad spell, half a minute staring at this usually names whoever is hammering the site. Quit with Ctrl+C.
|
What you will not find here
To save time for anyone arriving from another server: there is no htop, no screen and no tmux on shared accounts. There are no server administration commands either, and that is deliberate: your account is fenced into what is yours, which is the same fence that keeps your neighbour out of your site.
To leave a long job running without keeping the session open, what does exist is nohup, explained in importing a large database over SSH.
|
Careful with heavy commands at peak hours. A du or a find on an account with many files is itself a large consumer, and it runs inside your own limit. If the site is already struggling, you are adding weight to it. Leave those for the quiet hours.
|
Once you know what is consuming, what to do about it is in what eats CPU on a website.
RECOMMENDED PRODUCT VPS server with root access Resources of your own, the OS you choose, reinstall whenever you like. from $12.00/mo See plans |