Virtualmin hosting on Ubuntu 16.04 x64

The following commands and ideas are useful in creating an Ubuntu hosting server using Virtualmin as a main administration interface.

As obvious, Ubuntu is one of the most popular Linux distributions. And lately Virtualmin has done some big steps towards looking great – and sometimes this is an important criteria in picking your hosting helper interface.

This installation – with small modifications – should soon apply to Ubuntu 18.04. Due to some changes in the new version, Virtualmin still needs to receive some updates and patches until it’ll work as expected.

Prerequisites and notes

  • A clean Ubuntu 16.04 x64 install;

Conventions

  • In the following commands, your sudo user will be sudouser
  • The address of your server is example.com

The Setup

Ideas on what to put in your server and commands for how to get them in:

Setup the main sudoer

The following commands will add a new user, give sudo priviledges, disable the root account and switch to the newly added user:

  • adduser sudouser
  • usermod -aG sudo sudouser
  • passwd -l root
  • su - sudouser

Set your locales

  • sudo apt-get install language-pack-en-base
  • sudo locale-gen
  • sudo dpkg-reconfigure locales
  • exit and log back in

The following might also help:

  • edit /etc/default/locale and add:
    LANG=en_US.UTF-8
    LANGUAGE=en_US.UTF-8
    LC_ALL=en_US.UTF-8
    LC_TYPE=en_US.UTF-8

Enable swap

  • sudo swapon --show
  • sudo fallocate -l 4G /swapfile
  • ls -lh /swapfile
  • sudo chmod 600 /swapfile
  • ls -lh /swapfile
  • sudo mkswap /swapfile
  • sudo swapon /swapfile
  • sudo swapon --show

Make swap permanent

  • sudo nano /etc/fstab
    and add at the end:
    /swapfile none swap sw 0 0

Add nvm for all users

Node.js and npm are pretty popular nowadays. Therefore, it would be nice for all users to have access to their own version and to the npm command.

  • sudo apt-get install build-essential libssl-dev
  • sudo nano /etc/profile.d/nvm.sh and add:
    #!/bin/bash
    if [ ! -f ~/.nvm/nvm.sh ]; then
        # May need to be updated with the latest nvm release
        wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
    fi
    source ~/.nvm/nvm.sh
  • sudo chmod +x /etc/profile.d/nvm.sh
  • For each of the users who will run it do:
    source /etc/profile.d/nvm.sh

The above is a method that seems (almost) clean and works. However, I think it could get some improvements in the future, as this is a programmer’s solution to getting some useful tools. ?

Add oh-my-zsh to your shell

This is not a mandatory step. However, oh-my-zsh provides a nicer interface to your shell together with some useful features (e.g. better command history and autocomplete)

  • sudo apt install zsh
    You might also need to install git.
  • sudo git clone https://github.com/robbyrussell/oh-my-zsh.git /etc/oh-my-zsh
  • sudo cp /etc/oh-my-zsh/templates/zshrc.zsh-template /etc/skel/.zshrc
  • sudo mkdir -p /etc/skel/.oh-my-zsh/cache
  • sudo nano /etc/skel/.zshrc
    Replace: export ZSH=$HOME/.oh-my-zsh
    With:
    export ZSH=/etc/oh-my-zsh
    export ZSH_CACHE_DIR=~/.oh-my-zsh/cache
  • In the same file, at ZSH_THEME you can change your theme. My personal preference is bira;
  • sudo nano /etc/default/useradd and set SHELL=/bin/zsh
  • cp /etc/skel/.zshrc ~/.zshrc and chsh -s $(which zsh)
    for each of the existing users
  • sudo reboot

Add zsh-autosuggestions to your files

  • sudo git clone https://github.com/zsh-users/zsh-autosuggestions /etc/oh-my-zsh/plugins/zsh-autosuggestions
  • sudo nano /etc/skel/.zshrc
    and append:
    source /etc/oh-my-zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

Add zsh-syntax-highlighting to your files

  • sudo git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /etc/oh-my-zsh/plugins/zsh-syntax-highlighting
  • sudo nano /etc/skel/.zshrc
    and append:
    source /etc/oh-my-zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Add Composer

  • sudo apt-get update
  • sudo apt-get install curl php-cli php-mbstring git unzip
  • cd ~
  • curl -sS https://getcomposer.org/installer -o composer-setup.php
  • sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Add Sqlite

  • sudo apt-get install sqlite3 libsqlite3-dev

Install Virtualmin

  • sudo apt-get update
  • sudo apt-get upgrade -y
  • wget https://software.virtualmin.com/gpl/scripts/install.sh
  • sudo /bin/sh ./install.sh --minimal --force

At the end of the install script, you will get a link to the Virtualmin interface. Do access it as soon as possible and fix the settings in there towards more security (e.g. change the access port).

One idea could be installing multiple php versions.

Another could be switching the default Mysql database to MariaDB or something more “funky”.

wp-cli

  • curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  • chmod +x wp-cli.phar
  • sudo mv wp-cli.phar /usr/local/bin/wp

Sources