Install the latest version of Composer on Ubuntu

If you have previously installed composer with command...

sudo apt-get install composer

...it is recommended to uninstall it first. Run the command:

sudo apt-get purge --auto-remove composer

 

Let's install the latest version now. Go to whatever directory you like and follow the instructions for Command-line installation on the official Composer website: https://getcomposer.org/download/

After you run the four commands (copy, verify, install, remove), you should end up with a single file named composer.phar.

All you have to do now is move this file to the appropriate directory with a command:

sudo mv composer.phar /usr/local/bin/composer

Try running this command anywhere...

composer -V

...and you should see the latest version of your freshly installed Composer.

 

Running composer might display this error message (where [user] is your username):

Cannot create cache directory /home/[user]/.composer/cache/repo/https---packagist.org/, or directory is not writable.
Proceeding without cache
Cannot create cache directory /home/[user]/.composer/cache/files/, or directory is not writable.
Proceeding without cache

Set the permissions with these commands (where [user] is your username):

cd ~
 sudo chown [user]:[user] .composer -R

How to remove old kernel versions on Ubuntu Server

It is recommended to remove old kernel version to clean up the boot menu and to get some extra disk space.

1. Check which kernel version you're using:

uname -r

2. List all installed kernels and headers on your system:

dpkg -l | grep linux-image
dpkg -l | grep linux-headers

3. If you're not using the latest kernel version, try rebooting your system first.

4. You can remove old kernel versions automatically:

sudo apt-get autoremove

5.a. Or you can remove them manually one by one:

sudo apt-get purge linux-image-x.x.x.x-generic

Be sure, NOT to remove the version you're using! 

It is also recommended to leave the previous version on your system.

5.b. When you're done, update your Grub:

sudo update-grub2 

6. Reboot your system.

Disk Space and Partitions on Linux and UNIX-like systems

Disk Space

We can check out free disk space on a Linux system with the command:

df -h

or

df -k

These commands are great for checking overall disk space usage, but since we usually want to check which folder (or file) occupies the most disk space, we can run the command:

du -sh * | sort -hr

The first part of the command (left side of the pipe) will return the list of files and folders with corresponding disk usage values.

The second part (right side of the pipe) will sort the results by size (disk space usage) and will put the largest sizes on the top of the list. If you want the largest sizes on the bottom, just remove the 'r' parameter (r - reverse).

This command will list only the files and folders in the path where you are located, when running this command.

A suggestion:

Run the command, then 'cd' into the largest directory and run the command again. By doing that a few times, you will most likely find the source of your largest files and directories.

 

Disk Partitions

List all partitions and check their size:

sudo fdisk -l /dev/sda

Open Linux partition editor in terminal:

sudo cfdisk

Install VMware tools on Ubuntu Server

1. Enable Shared folders

Edit virtual machine settings, go to Options / Shared folders, set to Always enabled and add a host folder to the Folders list. Run virtual machine and login to Ubuntu Server with your username and password.

2. Update package repository

sudo apt-get update

3. Instal dependencies

sudo apt-get install gcc binutils make linux-source

4. Start with the VMware Tools installation

Click "Install VMware Tools..." in the window menu of the virtual machine. If the prompt window appears (Disconnect anyway and override the lock?), click Yes.

5. Create mount directory for CD-ROM

sudo mkdir /mnt/cdrom

6. Mount virtual CD-ROM to created folder

sudo mount /dev/cdrom /mnt/cdrom

7. Extract .tar file

sudo tar xzvf /mnt/cdrom/VMwareTools-?.?.?-???????.tar.gz -C /tmp/

Tar file should be named as the file that is listed in the /mnt/cdrom folder.

8. Navigate to the extracted location

cd /tmp/vmware-tools-distrib

9. Run installation

sudo ./vmware-install.pl -d

10. Reboot the system and the VMware Tools are installed.

sudo reboot

Package repositories on Ubuntu Server

Package repositories

Update the package repositories from sources with the latest versions

sudo apt-get update

A list of repositories, that the server will check for packages, is stored at /etc/apt/sources.list

cat /etc/apt/sources.list

Extra repositories can be added to /etc/apt/sources.list.d

Package information

Search for available packages (eg. mysql); to search only by the package name, use -n tag.

sudo apt-cache search mysql
sudo apt-cache search -n mysql

Get the package information (eg. mysql-server-5.6)

sudo apt-cache show mysql-server-5.6

Install/uninstall a package

Install a package || without prompting use tag -y || for quiet install use tag -qq

sudo apt-get install -y mysql-server-5.6

Uninstall a package ('purge' removes the configuration, 'remove' removes only the package)

sudo apt-get purge mysql-server-5.6

After uninstalling use autoremove to remove any dependencies that are not in use by other packages

sudo apt-get autoremove

List all installed packages

Get a list of packages installed locally (the -v tag "inverts" grep to return non-matching lines)

dpkg --get-selections | grep -v deinstall

Get a list of a specific package installed

dpkg --get-selections | grep mysql

Alternatively, simply use

dpkg -l

Get just the packages which were expressly installed (not just installed as dependencies)

aptitude search '~i!~M'

 

Install & configure Samba Server on Ubuntu VM

1. Install Samba

The first thing we need to do is to update the package repositories and then install Samba.

sudo apt-get update
sudo apt-get install samba

2. Configure Samba

Now we'll have to add a few lines to the Samba configuration file /etc/samba/smb.conf to make everything work.

[global]
# The following property ensures that the existing files do not have their
# permissions reset to the "create mask" (defined below) if they are changed
map archive = no

# Notify upon file changes so that Windows can detect such changes
change notify = yes

# Configure shared folder for your user where "developer" is your Linux username
[developer]
comment = Developer Files
path = /home/shared
guest ok = no
browseable = yes
writable = yes
create mask = 0664
directory mask = 0775

Save and close the config file and then add a Samba user and password identical to your Linux user account.

sudo smbpasswd -a developer

Restart Samba so that the config can be re-read.

sudo service smbd restart

Your Windows host should now have access to the shared folder. To access the shared folder, open a folder browser and type in:

\\*ubuntu-local-ip-address*\developer (e.g. \\192.168.1.100\developer)

To find out what your local IP address is, got to your Ubuntu server terminal and type:

ifconfig

 

 

Apache2 - Configure multiple websites (virtual hosts)

1. Login to your Ubuntu Server, navigate to and list »sites-available« directory

cd /etc/apache2/sites-available 
ll

2. You should see the files:

000-default.conf
default-ssl.conf

3. Disable the default site configuration

sudo a2dissite 000-default.conf 

4. Create a copy of the default configuration file and open it for edit

sudo cp 000-default.conf yourdomain-com.conf 
sudo nano yourdomain-com.conf 

5. Enter the configuration (you can delete the comments) in this manner

<VirtualHost *:80>
ServerName yourdomain.com
ServerAdmin info@yourdomain.com

DocumentRoot /var/www/yourdomain.com

ErrorLog ${APACHE_LOG_DIR}/yourdomain.com-error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com-access.log combined
</VirtualHost>

6. Save and exit the file edit mode

7. Enable the yourdomain.com site configuration

sudo a2ensite yourdomain-com.conf 

8. Be sure to create appropriate directory and set permissions

cd /var/www/
sudo mkdir yourdomain.com
sudo chown username:username yourdomain.com -R

(use your own Ubuntu Server username)

9. Reload Apache2 server

sudo service apache2 reload

Configure SSH to connect to a Remote Ubuntu Server

1. On your Windows machine I suggest installing Cmder console emulator, visit http://cmder.net/ and then download and install the Full package (with git-for-windows)

2. Open Cmder or other console software on your Windows machine, navigate to root directory, create .ssh directory and enter it

cd ~
mkdir .ssh
cd .ssh

3. Create SSH key pair id_rsa & id_rsa.pub (-t is type, -b is bytes, -f is filename)

ssh-keygen -t rsa -b 4096 -f id_rsa -C "email@domain.com"

4. Display the public key on the screen, select the printed text and copy it to clipboard

cat id_rsa.pub

5. Login to your Ubuntu Server and install OpenSSH in case you don't have it yet

sudo apt-get install openssh-server

Before you do that, don't forget to update the repositories with:

 sudo apt-get update

6. On your Ubuntu Server machine, navigate to root directory, create .ssh directory and enter it

cd ~
sudo mkdir .ssh
cd .ssh 

7. Create a file authorized_keys and open it for edit

touch authorized_keys 
nano authorized_keys 

6. Paste previously copied public key and paste it to this file

7. Logout from Ubuntu Server and try to login from your Windows machine

ssh username@192.168.1.100

(use your own Ubuntu Server root username & IP address)

8. If you're connecting to eg. GitHub via SSH, test your connection with this command:

ssh -T git@github.com

Copy public SSH key to your server

When you create SSH key pair on your computer, you can copy the public key to your server via terminal (console).

cat ~/.ssh/id_rsa.pub | ssh username@192.168.1.100 'cat >> .ssh/authorized_keys && echo "Key copied"'

Configure static local IP on Ubuntu Server

1. Login to your Ubuntu Server and check your networking

ifconfig
eth0 Link encap:Ethernet         HWaddr 00:0c:29:7c:05:22 
     inet addr:192.168.1.123     Bcast:192.168.1.255  Mask:255.255.255.0
     inet6 addr: fe80::20c:29ff:fe7c:522/64 Scope:Link

2. Edit the network config file »interfaces«

sudo nano /etc/network/interfaces

3. You will see these two lines

auto eth0 
iface eth0 inet static

4. Change the lines to this configuration (don't mind the comments)

auto eth0 
iface eth0 inet static            #dynamic is changed to static
address 192.168.1.100            #your custom local IP
netmask 255.255.255.0             #same as on ifconfig Mask
gateway 192.168.1.1               #default local network IP
broadcast 192.168.1.255           #same as on ifconfig Bcast
dns-nameservers 8.8.8.8 8.8.4.4   #Google's DNS servers

5. Save the file and restart networking

sudo /etc/init.d/networking restart

6. Check your local static IP

ifconfig
eth0 Link encap:Ethernet          HWaddr 00:0c:29:7c:05:22 
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe7c:522/64 Scope:Link

7. Important: if you're doing this on virtual machine (VirtualBox, VMware), you may have to reboot

sudo reboot