For troubleshooting purposes, you may sometimes need to check your site’s error logs and access logs to get more information as to why a problem may occur. This article explains how to view these logs through SFTP and Shell.
Viewing the logs via SFTP
As mentioned previously, the logs are inside the /logs/example.com/http directory under your username on the server.
To view the logs:
- Make sure your user is an SFTP or Shell user. Visit the Enabling Shell Access article for instructions.
- Log into your server using your client. Visit the FTP article for details.
- Click into the /logs directory.
- Click into the appropriate site from this next directory.
- Click into the http directory.
Note: Once in the /http directory, you'll notice that your remote site looks different at the top, which shows that your selected directories have changed – this is fine.
- Right click on the log file and open with your text editing program.
Viewing logs via SSH
- View the SSH article for instructions on how to log in to your server.
- Type in the following to change your directory to your user’s /logs directory:
- Type in the following to view all of the domains under the user:
- cd into the desired domain’s folder.
- cd into the domain’s /http folder.
- Type in the following to view a list of your log files:
Reading the most recent errors using the "tail" command
The following shows various uses of the "tail" command that you can run within the appropriate directory to read specific parts of the log.
Use the command "tail" to read the last lines from a file. For example:
tail -n 10 error.log
|Shows the last 10 lines from an error log.|
tail -f error.log
|Shows all newly added lines from a log file in real-time on the shell.|
tail -n 100 error log | more
|Shows the last 100 lines a single line at a time using the "more" command.
|ctrl + c||Quits tail and returns to the command line.|
Searching for a specific term using the "grep" command
You can use the grep command to search for a specific term within files. This is particularly helpful since looking through an error log can be tedious if a certain errors need to be seen and others can be ignored.
For example, if you only wanted to see errors related to the Testing2.jpg you can run this command:
cat error.log | grep “Testing2.jpg”
cat error.log command lists everything within the log. You may notice that several entries show “File does not exist” which are often irrelevant and can be ignored. You should always ensure that this is the case, however; If you’re sure they are not important, filter them out by running the following:
cat error.log | grep -v “exist”