Debian: updating system and application software using SSH

This tutorial will present the main package management tools that help to install any package, software or system update on a server.

APT package management tool

The Advanced Package Tool, or APT, is the user interface that works on your server to handle the installation and removal of software. The command apt-get calls to dpkg internally. If you do not have any .deb files on your server, it is recommended to use apt-get or apt to install an application. Apt does not need to know the .deb file name since it uses the file extension instead of the file name.

Before running an apt-get installation, you will need to run the following command;

# apt-get update

The update command downloads the package lists from the repositories and provides information on the newest versions of applications and their dependencies. It is recommended that you run this command before any upgrade or application installation.

If you need to install the application nano editor you can use the command:

# apt-get install nano

If you need to remove the nano editor application you can use the following command:

# apt-get remove nano

You will see in your terminal window that Apt-get provides to you the list of packages that to be removed. Before anything is deleted, you will have to confirm that you wish the action to take place by typing “Y.” After you confirmed it the applications are removed from the server.

If you wish to remove the nano application and all of its configuration files from your server you can using the following command:

#  apt-get purge nano

Debian system upgrade

Using SSH, you have the ability to perform updates to your Debian operating system. Before you upgrade Debian, you should use the following command to review what version you are currently running on your server.

# cat /etc/debian_version

To update Debian on your server, you will use the apt-get command. You should execute the command below to resynchronize index files from their sources:

# apt-get update

It is recommended that you regularly update your package list for security and server performance.

You can also upgrade your current packages without installing extra packages or removing any packages using the command:

# apt-get upgrade

Using apt-get, you have the ability to upgrade your server and install all new required packages and remove all obsolete packages from your server. To run this update on your server, use the following apt-get command:

# apt-get dist-upgrade

The main package management program: dpkg

Dpkg can be used as a powerful tool to manage Debian packages. It allows you to install, build, remove, and purge them from your server. Dpkg can also be useful if you have a file on your server with .deb extension. In the example below, we are going to download the nano text editor using wget and then install it to your server using dpkg. First, download the nano text editor using the following command:

# wget http://ftp.br.debian.org/debian/pool/main/n/nano/nano_2.2.6-1+b1_amd64.deb

Next, install the package using either the ‘-i” or “–install” option:

# dpkg -i nano_2.2.6-1+b1_amd64.deb

Now, thanks to dpkg, nano text editor has been installed on your server. Feel free to open files on your server using the command:

# nano <file_name>

Dpkg can also allow you to view a list of all installed applications on your server. To see the list of applications use the dpkg command:

# dpkg -l

Dpkg also allows you to review if an application is installed using the following command and the name of the package:

# dpkg -l nano

Dpkg lets you remove packages from your system as well. With removing packages, you have the option to keep or remove the configuration files on the server.

To uninstall a package using dpkg and remove the configuration files, you can use the option ‘-p’ or ‘–purge’.

# dpkg -r nano

To uninstall a package but leave all of the configuration files, use the option‘-r’ or ‘–remove’.

# dpkg -r nano

If you ever run into trouble, the “-help” can provide you all available options.

# dpkg –help

Common stand-alone web/db/mail configs and log files locations

Apache Web Server

On Debian, Apache package is installed into /etc/apache2/. This directory contains Apache configuration files as well as websites configuration files.

  • apache2.conf: This is the main configuration file for the Apache server. It contains the default settings for Apache2.

  • ports.conf: This file contains the configuration of the ports that virtual hosts should be listed on.

  • sites-available/: This directory contains the files for Apache2 Virtual Hosts. Apache2 can be used and configured for multiple sites which will each have separate Virtual Hosts files. The folder contains the available configurations, but not will not display the active configurations.

  • sites-enabled/:  The Virtual Host files in this directory are just symlinks to files defined in the /etc/apache2/sites-available directory. These are the active configurations that are being used by the server.

  • mods-available/: This directory is similar to the sites-available/ directory, but it contains all modules that can be enabled and used on the Apache server.

  • mods-enabled/: this folder contains symlinks to the modules listed under the mods-available/ folder. It defines which modules are currently active on the Apache.

Apache sets the default document root folder to /var/www. The error log file is created at /var/log/apache2/error.log and can be read using either “vim’ or ‘nano’ on your server.

If your error log file is incredibly large, you can read the last 10 lines using the following command:

# tail  /var/log/apache2/error.log

If you need more than the last 10 lines of the error log, you can use the following command to review the last 30 lines instead:

#tail -30  /var/log/apache2/error.log

In the command above you can exchange the “-30” with any number to review that specific number of lines from the error log.

#tail -50  /var/log/apache2/error.log

MySQL service

We already went through the process of starting, stopping and restarting the MySQL service. The default configuration file of MySQL is located in /etc/mysql/

To find the main MySQL config file, you can run the command # mysql –help and find the line:

“Default options are read from the following files in the given order:

/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

These are the default locations that MySQL looks at.

In most cases MySQL configuration file is located at /etc/mysql/my.cnf

The MySQL configuration file contains all settings for the MySQL service.

Some of the useful settings inside the file are as follows:

  • bind-address  = 127.0.0.1

The bind-address is the MySQL host server IP address and should be used as the MySQL host for any web application that uses MySQL on the server.

# Basic Settings

  • port = 3306:  This is the default port used by the MySQL server.
  • datadir = /var/lib/mysql : This is a location of the MySQL databases.
  • general_log_file = /var/log/mysql/mysql.log : This is the default MySQL log file location.

The /var/log/mysql/ folder is the default logs folder, but it may not contain the  error log file. If the directory is missing the error.log, review the the my.cnf file. Inside the my.cnf file you need to find the following line of code:

log_error = /var/log/mysql/error.log

If you do not see this line or another line that contains the “log_error” parameter, under the ‘[mysqld]’ section add:

log_error = /var/log/mysql/error.log

After adding the line to your my.cnf file, save the file and restart MySQL on your server using the following command:

# service mysql restart

Recheck the /var/log/mysql/ directory to see the error.log file.

Mail Server – Exim4

On Debian systems, Exim4 mail service is installed by default. Exim’s default directory can be found at /etc/exim4/.

The following files can be found in your Exim4 directory.

  1. config.d/ is a directory that defines the configuration snippets, separated by config area.

  2. exim4.conf.template – This is the basic configuration file of the Exim4 service.

  3. update-exim4.conf – The update-exim4.conf file contains all parameters and settings setup during the configuration of Exim.

If you need to re-configure Exim, you do so using the command:

# dpkg-reconfigure exim4-config

After you have entered the command in Exim, the configuration interface will be displayed for you to make changes to based on your needs.

The default Exim mail log file has been named mainlog and can be found here  /var/log/exim4/

To read the log file, you will need to use any text editor tool installed to your server. The default text editor tool is vi, but you can install the nano text editor using SSH if needed.

If you are receiving error messages regarding Exim, you can review the last 10 lines of the error log using the command:

# tail /var/log/exim4/mainlog

Exim stores the Mail queue in the /var/spool/exim4/ directory.

If you need to see the number of messages currently being queued on the server use the command:

# exim -bpc

You can also print a full listing of the messages being queued by the server. The list will provide you the time the message was queued, the size of the message, the message id, who sent it, and who the intended recipient is for each message. To print the list, use the command:

# exim -bp

Was this article helpful?

Yes (0)
No (0)

We're sorry you didn't find this article very helpful. Please help us improve it by leaving your feedback below.

Error