[Solved] How To Create Aliases In Ubuntu 16 Via The Commandline

How to create an alias in Ubuntu 16 via the commandline

Do you ever get tired of having to type out a long string of Linux commands and options/arguments repeatedly? Well, you can use aliases to either abbreviate those long commands, or simply change them to something that is easier to remember.The alias command does this by replacing of a default system command with a word/string of your choice.

Using aliases is very useful especially when there are default arguments that you always attach to a command. For example, i think it’s always a good idea to create a backup of a file before you edit it, in case something goes wrong and you have to revert to the original. So whenever i use nano (a text-based editor), i add the arguments -B (which backups the original file) and -u (which allows me to undo an edits). Normally, i would have to type out

nano -Bu

every time i edit a file, but that is somewhat laborious (trust me, when you do a lot of file editing, it gets tiring!). I’m also forgetful, so i don’t always remember to do it. Which is why I use aliases. Instead of typing out the nano command and its arguments every time i want to edit a file, i simply create an alias.

To create an alias in Ubuntu 16 via the commandline, do the following:

Open .bashrc

sudo nano -Bu ~/.bashrc

(options – B backups up the file, u is undo)

Scroll down to the bottom of the file and add the desired aliases

#Custom Aliases

alias nano='nano -Bu'  # backup original file and undo changes
alias rm='rm -i' # request confirmation before deleting a file

Save and close the file (Ctrl + O, Enter, then Ctrl + X)

To save the alias and make it permanent, execute the following command [note the space between the first period and the tilde (~) ]
. ~/.bashrc

Test your alias

Running the command nano doof.txt should create a backup file (the backup will have a tilde (~) appended to it). The backup is only created if you save the file.

Running the command rm doof.txt will result in confirmation request “rm: remove regular empty file 'doof.txt'?

And that’s it! This is how you create aliases in Ubuntu 16 via the commandline

[Solved] How To Install Koha on Ubuntu Server 16.04 LTS

[Solved] How To Install Koha on Ubuntu Server 16.04 LTS

Pre-requisites

Add the Koha community repository to your sources

echo deb http://debian.koha-community.org/koha stable main | sudo tee /etc/apt/sources.list.d/koha.list

Add Koha GPG Key

wget -O- http://debian.koha-community.org/koha/gpg.asc | sudo apt-key add -

Update and Upgrade Applications on your server

sudo apt install update

sudo apt install upgrade

sudo apt clean

Install the latest Koha Release

sudo apt install koha-common

Configure the Server

sudo nano –B /etc/koha/koha-sites.conf

(The –B option is for backing up – a backup file of the previous configuration is created every time you save. The backup file will have “ ~ ” appended to it – it’s useful if you need to revert to the original settings)

The actual settings in your configuration file will depend on your server set up (whether you are using an IP based installed or actual domain names etc.). If you are doing an IP-based installation, change the line

INTRAPORT="80"              

To

INTRAPORT="8080"              

The file should look like this:

# Apache virtual hosts creation variables

DOMAIN=".myDNSname.org"

INTRAPORT="8080"               # use 8080 for an IP-based install.

INTRAPREFIX=""

INTRASUFFIX="-intra"

OPACPORT="80"

OPACPREFIX=""

OPACSUFFIX=""

# SQL file to load into new instances

DEFAULTSQL=""

# Zebra global configuration variables

ZEBRA_MARC_FORMAT="marc21"   # or normarc or unimarc.

ZEBRA_LANGUAGE="en"          # match with installation language (e.g. es for Spanish)

BIBLIOS_INDEXING_MODE="dom"

AUTHORITIES_INDEXING_MODE="dom"

 

# Memcached global configuration variables

USE_MEMCACHED="no"

MEMCACHED_SERVERS="127.0.0.1:11211"

MEMCACHED_PREFIX="koha_"

Install Apache

sudo apt install apache2

Install MySQL + Ubuntu 16 Workaround

sudo apt install mysql-server

Koha is not yet fully compatible with Ubuntu 16, so you need to bypass the problem by doing editing the mysqld.conf file as follows:

sudo nano –B /etc/mysql/mysql.conf.d/mysqld.conf

Insert the following in the section [mysqld]

sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Secure MySQL

MySQL comes with some security risks – remote login,  anonymous user and test database. Type the following to secure it:

sudo mysql_secure_installation

Answer “n” (no – case sensitive) to the first question and “Y” (yes) to the rest

Enable the Apache mod_rewrite modules

sudo a2enmod rewrite

sudo a2enmod cgi

sudo service apache2 restart

Create the Library Instance

sudo koha-create --create-db library

“library” can be anything you want (make it short, simple and sensible though). This will be the name of your Koha library instance

Configure Apache

I’m assuming you want an IP-based install such that you will access your OPAC on <ipaddress>:<port#> and Staff page on <ipaddress>:<port#>. If so, configure Apache to listen to the ports (don’t delete any lines that already exist):

sudo nano –B /etc/apache2/ports.conf

Add the following lines underneath “Listen 80”:

Listen <opac-port#>=

Listen <staff-port#>

So if you want your OPAC port to be 7777 and your staff page port to be 7778, enter the following beneath “Listen 80”:

Listen 7777

Listen 7778

Setup Your Library Instance’s Apache Configuration

sudo nano –B /etc/apache2/sites-enabled/library.conf

where library corresponds with the name of the library instance you created above

Enable Modules and Site

sudo a2enmod deflate

sudo a2ensite library

sudo service apache2 restart

Web Installation

The rest of the installation will be completed on the staff page via a web-browser.

Open a web-browser on another computer (if you installed it on the server version, or on the local browser if you are using a desktop version) and go to the address <ipaddress>:<staff-port#>. If you the IP address of your Koha server is 192.168.1.4 and your staff page port number is 7778, enter this

192.168.1.4:7778

You will be asked for a username and password. Your password will be koha_library, where library is the name of the library instance which you created earlier.

To find the username, go back to the terminal on your Koha server and enter the following command and copy the password (make sure you change library to the name of your Koha instance:

sudo xmlstarlet sel -t -v 'yazgfs/config/pass' /etc/koha/sites/library/koha-conf.xml

Complete the web install, after which you will be redirected to the staff login page.

Create A New Library

Go to Home > Administration > Libraries and Group > New Library

Create A Staff Patron With Super-User Permissions

Go to Home > Patrons > New Patron > Staff

After creating the patron,

Click on More > Set Permissions > Select “Super-librarian” > Save

Log out, then log in with the user which you just created. Enjoy!

 

[Solved] How to Backup Files and Folders using Tar and 7z in Ubuntu

Backups tend to take up a lot of space, especially if you have a large database, such as a Koha SQL database with thousands of items and records. To save space, you can easily compress the file (or any folder) using one line on the Ubuntu Commandline.

If you don’t know how to backup, please read this article first. If you’ve already done your backup, do the following to compress your backup file or folder using tar and 7z. The reason we have to tar first is because 7z does not preserve permissions and owner/group info.

$ tar cf - #file-to-be-compressed| 7za a -si #archive.tar.7z  

where:

#archive.7z is the name of the new archive you are creating. Don’t forget to put the 7z extension

#file-to-be-compressed is the name of the file or folder you want to compress. If it is in a different folder to the one you are in, include the path.

 

[Solved] How to Compress Large Files and Folders in Ubuntu with 7zip

Backups tend to take up a lot of space, especially if you have a large database, such as a Koha SQL database with thousands of items and records. To save space, you can easily compress the file (or any folder) using one line on the Ubuntu Commandline.

If you don’t know how to backup, please read this article first. If you’ve already done your backup, do the following to compress your backup file or folder to the smallest possible size using 7zip. We recommend you compress using Tar first since 7z does not preserve

$ 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on #archive.7z #file-to-be-compressed

where:

#archive.7z is the name of the new archive you are creating. Don’t forget to put the 7z extension

#file-to-be-compressed is the name of the file or folder you want to compress. If it is in a different folder to the one you are in, include the path.

The ultra settings are explained as follows:

-t7z

7z archive

-m0=lzma

lzma method

-mx=9

level of compression = 9 (Ultra)

-mfb=64

number of fast bytes for LZMA = 64

-md=32m

dictionary size = 32 megabytes

-ms=on

solid archive = on

So if you want to compress a SQL file called koha-backup.sql and name it koha-backup.sql.7z you would do the following:

$ 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on koha-backup.sql.7z  koha-backup.sql
 

[Solved] How to Backup Your Koha MySQL Database

Backing up is a must-do for server administrator, and especially when you are running Koha. Your server could crash and in an instant, you could lose your entire database. So this is how you can protect yourself, and your clients from data loss.

Backup your entire MySQL database

You can backup your entire MySQL database, including your Koha instance databases, using this command

$ mysqldump -u #username -p --all-databases > #any-name-for-your-backup.sql
 where:

#username is the username for your MySQL database. Unless you changed this, it is usually root.

#any-name-for-your-backup.sql is the name for your backup. You can choose any name for this, just make sure you add the .sql extension.

You will be prompted to enter your password.

Use the following command to verify your backup is there

$ ls

You should see #any-name-for-your-backup.sql in your folder

Use the following command to see the size of your backup

$ du -h #any-name-for-your-backup.sql

Backup a Single Koha Instance Database

First, you need to see what your Koha instance database is called. Log in to MySQL as follows

$ mysql -u #username -p
 

where #username is the username for your MySQL database. This is usually root.

mysql> show databases;

All the databases in MySQL will be listed. Make note of the one(s) which you want to backup. The Koha databases will have a “koha_” prefix. If your Koha instance is called “library” for example, you should see the entry “koha_library” in the output. Exit MySQL as follows

mysql> quit;

Now backup your desired Koha database

$ mysqldump -u #username -p koha_library > library.sql
 

where:

#username is your MySQL admin/root username

koha_library is the name of your Koha database

library.sql is whatever name you choose to give to your backup. Make sure to include the “.sql” extension.

You will be prompted for your MySQL password.

Verify that the SQL file exists

$ ls

You can view its size using the following command

$ du -h #name-of-database.sql

You can proceed to download your backup or save it to a service like DropBox or GoogleDrive. If you have a large backup file, its usually a good idea to compress it, as we show here:

How to Compress Large Files Using 7zip.

Any comments or questions? Let us know down below!

[Solved] How to Upgrade from Ubuntu 14.04 LTS to Ubuntu 16.04 LTS (on a server running Koha ILS)

[Solved] How to Upgrade from Ubuntu 14.04 LTS to Ubuntu 16.04 LTS (on a server running Koha ILS)

Upgrading to Ubuntu 16.04 LTS from 14.04 LTS on a server running Koha Integrated Library System

So the new Ubuntu 16 Server OS is out, and perhaps you like new and shiny things (kinda like the “niffler”, that cross between a platypus and a mole in Fantastic Beasts and Where You Can Find Them).

But upgrading is not always the easiest, or indeed, the best thing to do. Unless your release is coming to its end-of-life (I was on Ubuntu 14.04 LTS, which still has another 2 years) , or you are running software that can’t update unless you upgrade, I’d recommend not rushing upgrades. If it ain’t broke, don’t fix it. And waiting allows others to go through the teething problems, and, just like I am doing, tell you about all their chaos, struggles and victories.

I needed to upgrade because to run the latest version of one my programs, they needed dependencies that are only available in Ubuntu 16. This tutorial is based on what I experienced as I was upgrading my development servers in preparation to do the same on my production servers.

That last line might have got you thinking – development server? Yep, I’ve found out (quite painfully) that it is always a good idea to test things out before you roll them out into a production environment. If something goes wrong, you can work out the kinks, otherwise all your important websites and programs will stop working, and I don’t need to explain the rest. I don’t think a development or testing server needs to be particularly fancy – a cheap desktop running the same server OS and same software as you have on your production server is sufficient. Trust me, it’s a investment.

Disclaimer: Yep, I have to say this. I’ve been using Linux long enough to know that catastrophes happen. So, don’t take this tutorial for gospel! I’m not responsible for anything that might go wrong. If, on the other hand, it all works great, then, that’s a different story…

The Server

Both my development and production servers had the following:

  • Ubuntu Server 14.04 LTS
  • Koha Integrated library system – which is the most important program that I’m running on my system. It’s an open source system. You can read about it here.

There are other programs, like apache, php etc., that are running on it as well.

Pre-upgrade Prep

Backup

That’s the most important thing you can do before an upgrade. There are lots of software that you can use to make backups of your entire system or particular programs. I used mysqldump to backup my databases and Rsync to backup important documents and folders. Another good one is Bacula.

The most important things to back up for me were:

  1. MySQL databases – I did a single dump of the entire database and then individual ones as well. Learn how to do so in this article
  2. Configuration files – all the custom configuration files, especially for backups, and those in /etc/ and /etc/apache and /var/www
  3. Documents – I don’t have a lot of these, but whatever I needed, I backed up.
  4. And just to be sure, I backed up the entire root directory ( / )

Your backups are likely going to take up space, so it’s a good idea to compress them. I recommend 7zip using ultra settings – you can read the instructions here.

Update and Upgrade

$ sudo apt-get update
 

Make sure your system is up-to-date by doing the following:

$ sudo apt-get upgrade
 

$ sudo apt-get dist-upgrade

Reboot

Reboot your system to finish installing the updates

Upgrading to Ubuntu 16.04 LTS

Running the upgrade

If you don’t already have the update-manager-core package, then go ahead and install it

$ sudo apt-get install update-manager-core
 

Make sure the line “Prompt=lts” is present in the file /etc/update-manager/release-upgrades. If not, insert it after the last line of text in the file.

$ sudo nano –b –u /etc/update-manager/release-upgrades

Now you can start the upgrade

$ sudo do-release-upgrade

I encourage you to do this whilst directly connected to your system. If you are upgrading via SSH, a new port will open on 1022 just in case you lose connectivity and need to access SSH.

Enter “y” or “yes” when prompted if you want to continue with the upgrade.

Restarting Services

Some services will need to restart and a prompt will come up. Answering “yes” should be ok.

New vs. Old Configuration Files

In some cases, you will be asked whether you want to replace the old configuration files with the new ones. Read these prompts carefully, you will have to make a judgment call for each of them. If you don’t have custom configurations then “yes” should be ok, otherwise I recommend sticking with your old configuration. At least that’s what I did 🙂

Obsolete packages

When the new packages have finished installing, you will be asked whether or not you want to remove the obsolete packages. Be very careful here as well. If you have customized your system, read through carefully which programs will be removed. I didn’t and I got into quite a bit of trouble later. Note which packages you might need to re-install.

The upgrade will take quite a long time, even if you have a fast connection. So it needs patience. Grab a coffee. Or some roobois tea…

Restart

When everything is done, you will be asked to restart the system. Say yes and if all went well, you will be running Ubuntu 16.04 LTS Xernial Xerus!

Did you encounter problems? Did we miss anything out? Let us know below!