Host Multiple Sites with SSL in LAMP


Install Ubuntu 16.04 LTS

From the dashboard of your VPS hosting provider, you will find how to install/ deploy operating system. Create Password for root user.

Login to your VPS

Run Putty to login with the host IP address as shown below:


A security alert will pop up. Click Yes. Login as: root.

Set Hostname

Set a hostname for your VPS. hostname is anything you like to name your VPS server. e.g. “hydrogen”.
Execute the following command:

echo "hydrogen" > /etc/hostname
hostname -F /etc/hostname
nano /etc/hosts

Add: IP address <space> hydrogen


will give output “yourhostname”

Set Timezone

Run the following command to setup your local time.

dpkg-reconfigure tzdata

To check it shows proper date and time run:


It will show you current date and time.

System Update

Run the following to update your system softwares:

apt-get update
apt-get upgrade

During upgrade you need to press y to continue.

Create User

adduser admin


usermod -aG sudo admin

Now logout of root account. Run putty again and login as admin.

Secure with SSH Key-Pair

Now login your VPS as admin

Open puTTYgen in your own Windows PC. Generate a Public/Private key pair.

Save Private key in your PC.
Copy Public key.

Now run the following commands with admin user in your linode terminal.

mkdir .ssh
sudo nano .ssh/authorized_keys

Paste the copied public key into this file.
Save and Exit.

sudo chown -R admin:admin .ssh
sudo chmod 700 .ssh
sudo chmod 600 .ssh/authorized_keys
sudo nano /etc/ssh/sshd_config

Now disable root login by changing the following value:

PasswordAuthentication no
PermitRootLogin no

Restart SSH

sudo service ssh restart

Now you can not login with root account. Also you can not login with password. admin user can only login with the private key. Open the private key you saved and you can login with admin user.

Set up a Firwall

sudo ufw app list

Available applications:

sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Status: active
And few lines.

Install Apache

sudo apt-get install apache2
sudo ufw allow "Apache Full"
sudo nano /etc/apache2/apache2.conf

Optimize Apache

KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 5
sudo nano /etc/apache2/mods-available/mpm_prefork.conf

Adjust inside mpm_prefork_module for 2 GB VPS

StartServers 4
MinSpareServers   3
MaxSpareServers   40
MaxRequestWorkers 200
MaxConnectionsPerChild 10000

Disable event module and enable prefork

sudo a2dismod mpm_event
sudo a2enmod mpm_prefork

Restart Apache

sudo service apache2 restart

Create directory for your first website

sudo mkdir -p /var/www/
sudo mkdir /var/www/

Create directory for your second website

mkdir -p /var/www/
mkdir /var/www/

You may host as many websites as you wish in a single VPS. So, carry on.

Create Virtual Host for your first domain

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
sudo nano /etc/apache2/sites-available/

Set the following:

DocumentRoot /var/www/
ErrorLog /var/www/
CustomLog /var/www/ combined

Create Virtual Host for your second domain

sudo nano /etc/apache2/sites-available/

Set the following:

DocumentRoot /var/www/
ErrorLog /var/www/
CustomLog /var/www/ combined

Enable Virtual Hosts

sudo a2ensite
sudo a2ensite

Disable default Virtual Host

sudo a2dissite 000-default.conf
sudo service apache2 restart

Install MySQL

Run the following commands one by one.

sudo apt-get install mysql-server
sudo mysql_install_db
sudo mysql_secure_installation

You will be prompted a series of questions after you enter root password. Just type y or n as required.

Change the root password? [y/n]: n
Remove anonymous users? [y/n]: y
Disallow root login remotely? [y/n]: y
Remove test database and access to it? [y/n]: y
Reload privilege tables now? [y/n]: y

Refer: MySQL Commands for Hosting Websites in Linux VPS

Install PHP

sudo apt-get install php7.0 libapache2-mod-php7.0 php7.0-mysql
sudo apt-get install php7.0-curl php7.0-json php7.0-cgi
sudo nano /etc/apache2/mods-enabled/dir.conf

Add the following:

DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

SSL Certificates for all Domains

sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-apache

Install certificate for first domain.

sudo certbot --apache -d

Install certificate for second domain.

sudo certbot --apache -d

SSL Auto Renewal

sudo crontab -e

At the end of line add:

15 3 * * * /usr/bin/certbot renew --quiet

Copy Files from Old Host to New Host

Check this: Copy Files from Old Host to New Host


Leave a Reply

Your email address will not be published. Required fields are marked *