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
hostname
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:
date
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
Output:
Available applications:
OpenSSH
sudo ufw allow OpenSSH sudo ufw enable sudo ufw status
Output:
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/example1.com/html sudo mkdir /var/www/example1.com/logs
Create directory for your second website
mkdir -p /var/www/example2.com/html mkdir /var/www/example2.com/logs
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/example1.com.conf sudo nano /etc/apache2/sites-available/example1.com.conf
Set the following:
ServerAdmin admin@example1.com ServerName example1.com ServerAlias www.example1.com DocumentRoot /var/www/example1.com/html/ ErrorLog /var/www/example1.com/logs/error.log CustomLog /var/www/example1.com/logs/access.log combined
Create Virtual Host for your second domain
sudo nano /etc/apache2/sites-available/example2.com.conf
Set the following:
ServerAdmin admin@example2.com ServerName example2.com ServerAlias www.example2.com DocumentRoot /var/www/example2.com/html/ ErrorLog /var/www/example2.com/logs/error.log CustomLog /var/www/example2.com/logs/access.log combined
Enable Virtual Hosts
sudo a2ensite example1.com.conf sudo a2ensite example2.com.conf
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.pl 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 example1.com
Install certificate for second domain.
sudo certbot --apache -d example2.com
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