linode

  • ssh root@192.12.345.67
    
    apt-get update
    
    apt-get upgrade
    
    dpkg-reconfigure tzdata
    
    date
    
    hostnamectl set-hostname classic
    
    nano /etc/hosts
    
    	192.12.345.67	classic
    	2400:8904::f03c:92ff:fe6a:58cd/64	classic
    
    hostname
    
    adduser admin
    
    adduser admin sudo
    
    exit
    
    ssh-keygen -b 4096
    
    ssh-copy-id admin@192.12.345.67
    
    ssh admin@192.12.345.67
    
    sudo nano /etc/ssh/sshd_config
    
    	PermitRootLogin no
    	PasswordAuthentication no
    
    sudo service ssh restart
    
    sudo ufw app list
    
    sudo ufw allow OpenSSH
    
    sudo ufw enable
    
    sudo ufw status
    
    sudo apt install nginx
    
    sudo systemctl start nginx
    sudo systemctl enable nginx
    
    sudo nano /etc/nginx/nginx.conf
    
    	server_names_hash_bucket_size 128;
    	client_max_body_size 100m;
    	server_tokens off;
    
    
    sudo ufw app list
    sudo ufw allow 'Nginx Full'
    sudo ufw enable
    sudo ufw status
    
    sudo apt install mariadb-server
    
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    
    sudo mysql_secure_installation
    
    sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-soap php-mbstring php-zip php-imagick php-xml php-xmlrpc
    
    sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.4/fpm/php.ini
    
    sudo nano /etc/php/7.4/fpm/php.ini
    
    	post_max_size = 100M
    	upload_max_filesize = 100M
    
    sudo service php7.4-fpm restart
    sudo service nginx restart
    
    sudo mkdir -p /var/www
    sudo rm -rf /var/www/html
    sudo wget https://wordpress.org/latest.zip
    sudo apt install unzip
    sudo unzip latest.zip
    sudo cp -R wordpress/* /var/www/
    sudo rm latest.zip
    sudo rm -rf wordpress
    
    sudo mysqldump -u root wbxpress > wbxpress.sql
    
    sudo scp -v -r admin@192.46.212.51:/home/admin/wbxpress.sql /home/admin/
    sudo scp -v -r admin@192.46.212.51:/var/www/wp-config.php /var/www/
    sudo scp -v -r admin@192.46.212.51:/var/www/ads.txt /var/www/
    sudo scp -v -r admin@192.46.212.51:/var/www/wp-content/* /var/www/wp-content/
    
    sudo chown -R www-data:www-data /var/www
    sudo find /var/www -type d -exec chmod 755 {} \;
    sudo find /var/www -type f -exec chmod 664 {} \;
    sudo chmod 444 /var/www/wp-config.php
    sudo chown admin:admin /var/www/wp-config.php
    
    sudo nano /etc/nginx/sites-available/default
    
    sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wbxpress.net.conf
    
    sudo nano /etc/nginx/sites-available/wbxpress.net.conf
    
    	location / { try_files $uri $uri/ /index.php$is_args$args; }
    	location ~ \.php$ { include snippets/fastcgi-php.conf;
    	fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; }
    
    
    sudo ln -s /etc/nginx/sites-available/wbxpress.net.conf /etc/nginx/sites-enabled/
    
    sudo rm /etc/nginx/sites-enabled/default
    
    sudo service nginx restart
    
    sudo mysql -u root
    
    show databases;
    
    CREATE DATABASE wbxpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    GRANT ALL ON wbxpress.* TO 'wbUser1'@'localhost' IDENTIFIED BY 'wbPass2';
    flush privileges;
    
    
    
    sudo mysql -u root wbxpress < wbxpress.sql
    
    sudo nano /var/www/wp-config.php
    
    sudo apt install certbot python3-certbot-nginx
    
    sudo certbot --nginx -d wbxpress.net -d www.wbxpress.net
    
    sudo crontab -e
    
    	15 3 * * * /usr/bin/certbot renew --quiet
    
  • Host Multiple Sites with SSL in Ubuntu 20.04

    ·

    Prerequisite

    A VPS account which starts from $5 per month from any reputed company. (We prefer Linode)

    You can host as many websites you like in this account.

    We will show only the commands necessary for hosting website. We will also show how to use https i.e. SSL for the websites. Your website can be of any type. We are showing WordPress installation although the commands are almost same.

    Technology Used

    OS: Ubuntu 20.04
    Web Server: NginX
    Database: MariaDB
    PHP: PHP FPM 7.4
    Application: WordPress
    SSL: Lets’ Encrypt

    1. Install Ubuntu 20.04 LTS

    From the dash board of VPS the first thing is to install an operating system. We use Ubuntu 20.04 LTS. Set Root password.

    2. Access Root

    From the dashboard Copy the IP address of your VPS. From your own computer Run Putty to login as root user to the IP address.

    3. Set Timezone

    Execute:

    dpkg-reconfigure tzdata

    Check with:

    date

    It will show you exact current date and time.

    4. Create a Non-Root User

    Execute:

    adduser admin
    usermod -aG sudo admin

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

    5. System Update

    sudo apt update
    sudo apt upgrade

    6. Secure with SSH Key Pair

    Open puTTYgen from your own computer. Generate a Public/ Private key pair. Save Private key in your PC.

    Copy Public key. Login to the VPS using Putty as admin.

    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

    7. Disable root login

    sudo nano /etc/ssh/sshd_config

    Set:PasswordAuthentication no
    PermitRootLogin no

    Restart SSH

    sudo service ssh restart

    Now you can not login with root account or using password. You only need to the private key to login. This is a great way to secure the server.

    8. Setup a Firewall

    sudo ufw app list

    Output:
    Available applications:
    OpenSSH

    sudo ufw allow OpenSSH
    sudo ufw enable
    sudo ufw status

    Output:
    Status: active

    9. Install Nginx

    sudo apt install nginx
    sudo systemctl start nginx
    sudo systemctl enable nginx
    sudo nano /etc/nginx/nginx.conf

    Set: server_names_hash_bucket_size 128;
    Add: client_max_body_size 100m;
    Set: server_tokens off;

    If you would like to also install SSL, then also add:

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers off;

    Save and Exit.

    sudo ufw app list
    sudo ufw allow 'Nginx Full'
    sudo ufw enable
    sudo ufw status

    10. Install MariaDB

    sudo apt install mariadb-server
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    sudo mysql_secure_installation

    11. Install PHP-FPM

    sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip php-bcmath php-imagick
    sudo systemctl restart php7.4-fpm
    sudo nano /etc/php/7.4/fpm/php.ini

    Set: post_max_size = 100M
    upload_max_filesize = 100M

    sudo service php7.4-fpm restart
    sudo service nginx restart

    12. Create directory for Websites

    sudo mkdir -p /var/www/website1
    sudo mkdir -p /var/www/website2

    etc.
    If you are installing a fresh WordPress site then:-

    sudo wget https://wordpress.org/latest.zip
    sudo apt install unzip
    sudo unzip latest.zip
    sudo cp -R wordpress/* /var/www/website1/
    sudo rm latest.zip
    sudo rm -rf wordpress

    If you are transferring existing website from other host to the new host the:-

    sudo scp -v -r admin@172.105.43.12:/var/www/oldhost/* /var/www/website1/

    Replace the IP address of your old host. Take similar action for website2.

    13. Set Proper File Permission

    sudo chown -R www-data:www-data /var/www/website1
    sudo find /var/www/website1 -type d -exec chmod 775 {} \;
    sudo find /var/www/website1 -type f -exec chmod 664 {} \;

    Similar action for website2.

    14. Create Virtual Hosts

    sudo rm /etc/nginx/sites-enabled/default
    sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/website1.com
    sudo cp /etc/nginx/sites-available/default
    sudo nano /etc/nginx/sites-available/website1.com

    Remove all except the following lines:-

    server {
    	root /var/www/website1;
    	index index.php index.html index.htm;
    	server_name website1.com www.website1.com;
    
    	location / {
    		try_files $uri $uri/ /index.php$is_args$args;
    	}
    
    	location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    	}
    
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    	expires max;
    	log_not_found off;
    }
    }
    

    Similarly, for second website create another virtual host.

    sudo cp /etc/nginx/sites-available/website1 /etc/nginx/sites-available/website2.com
    sudo nano /etc/nginx/sites-available/website2.com

    Change to:

    server {
    	root /var/www/website2;
    	index index.php index.html index.htm;
    	server_name website2.com www.website2.com;
    
    	location / {
    		try_files $uri $uri/ /index.php?args;
    	}
    
    	location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    	}
    
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    	expires max;
    	log_not_found off;
    }
    }
    

    15. Enable Virtual Hosts

    sudo ln -s /etc/nginx/sites-available/website1.com /etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/website2.com /etc/nginx/sites-enabled
    sudo service nginx restart

    16. Create Database

    CREATE DATABASE website1 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    GRANT ALL ON website1.* TO 'wp1User'@'localhost' IDENTIFIED BY 'wp1Pass';
    
    CREATE DATABASE website2 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    GRANT ALL ON website2.* TO 'wp2User'@'localhost' IDENTIFIED BY 'wp2Pass';
    

    If you are transferring your site from old host create a database backup from old host:

    sudo mysqldump -u root olddbsite1 > olddbsite1.sql
    

    Then copy the back up file to new host.

    sudo scp -v -r admin@172.105.43.12:/home/admin/olddbsite1.sql /home/admin/
    

    17. Update DNS Settings

    Set DNS of all the domains point to the correct IP address. You need to add A/AAAA records pointing to the IP address of the VPS.

    18. Test Run Websites

    Now that your site has both filesystem and database it should be viewable at this point. So try hitting the browser:-

    http://website1.com/

    Congrats, your website1 is live now. Now, we shall install SSL so that the site can be accessed securely as follows:-

    http://website1.com/

    19. Create SSL Certificates

    sudo apt update
    sudo apt upgrade
    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d website1.com -d www.website1.com
    sudo certbot --nginx -d website2.com -d www.website2.com

    You can check all existing SSL certificates.

    sudo ls /etc/letsencrypt/live

    To delete any Execute:

    sudo certbot delete

    20. Automatic Renewal of SSL Certificates

    Execute:

    sudo crontab -e

    Add At the end:

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

    That’s it. Hope you have successfully host websites in your own VPS. If you still have any query, you are free to ask. We surely get back to reply.

  • Host Multiple Sites with SSL in Ubuntu 18.04

    ·

    In this tutorial we shall share all the commands necessary to host multiple websites in a VPS server. We used VPS servers from Linode and Digital Ocean. Both are excellent and best value for money.

    This is a comprehensive guideline to host following domains:

    1. http://domain1.com
    2. http://www.domain2.com
    3. https://www.domain3.com
    4. https://domain4.com
    5. https://subdomain1.domain4.com
    6. https://www.subdomain2.domain4.com

    In the above examples 3, 4, 5 and 6 will use SSL provided by Let’s Encrypt for free.

    Proper redirection rules will also be applied. E.g.:

    1. http://www.domain1.com will be redirected to http://domain1.com
    2. http://domain2.com will be redirected to http://www.domain2.com
    3. https://domain3.com will be redirected to https://www.domain3.com
    4. https://www.domain4.com will be redirected to https://domain4.com
    5. https://www.subdomain1.domain4.com will be redirected to https://subdomain1.domain4.com
    6. https://subdomain2.domain4.com will be redirected to https://www.subdomain2.domain4.com

    All the above sites will be hosted in high performance secured web server named Nginx.

    We will also share WordPress specific configuration and optimization of the performance to achieve a very good score in GTMetrix. In addition to the fresh installation guide, we will also discuss how to transfer your websites from existing host to the newly created host of high performance.

    1. Initial Server Setup

    From the dash board of VPS the first thing is to install an operating system. We prefer Ubuntu 18.04LTS because it’s simple and easy to use. Copy the IP address of your VPS. Run Putty to login as root user to the IP address.

    1.1 Set Hostname

    Set a hostname for your VPS e.g. “supercomputer”. Execute the following commands:

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

    Add: IP address <space> supercomputer

    hostname

    will give output “supercomputer”.

    1.2 Set Timezone

    Execute:

    dpkg-reconfigure tzdata

    Check with:

    date

    It will show you current date and time.

    1.3 Create a Non-Root User

    Execute:

    adduser admin
    usermod -aG sudo admin

    1.4 Logout from Root

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

    1.5 System Update

    Execute:

    sudo apt update
    sudo apt upgrade

    2. Secure Server

    2.1 Secure with SSH Key Pair

    Open puTTYgen from your own Windows PC.

    Generate a Public/Private key pair.

    Save Private key in your PC.

    Copy Public key.

    Login to the VPS using Putty as admin.

    Execute:

    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 or using password. You only need to the private key to login.

    2.2 Firewall Setup

    sudo ufw app list

    Output:
    Available applications:
    OpenSSH

    sudo ufw allow OpenSSH
    sudo ufw enable
    sudo ufw status

    Output:
    Status: active

    3. Install LEMP Stack

    3.1 Install Nginx

    sudo apt install nginx
    sudo nano /etc/nginx/nginx.conf

    Add: server_names_hash_bucket_size 128;

    3.2 Add Exception to Firewall

    sudo ufw app list
    sudo ufw allow 'Nginx Full'
    sudo ufw enable
    sudo ufw status

    3.3 Install MySQL

    Execute:

    sudo apt install mariadb-server php-mysql
    sudo mysql_secure_installation
    sudo mysql -u root -p
    CREATE DATABASE testdb;
    CREATE USER 'testuser' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON testdb.* TO 'testuser';
    quit;

    3.4 Install PHP

    sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
    sudo systemctl restart php7.2-fpm

    3.5 Increase File Upload Limit

    sudo nano /etc/php/7.2/fpm/php.ini

    Change: post_max_size = 200M
    upload_max_filesize = 200M

    sudo nano /etc/nginx/nginx.conf

    Add: client_max_body_size 200m;

    sudo service php7.2-fpm restart
    sudo service nginx restart

    4. Host Multiple Websites

    4.1 Create directory and sub-directory for all the Domains and Sub-Domains

    Execute:

    sudo mkdir -p /var/www/html/domain1
    sudo mkdir -p /var/www/html/domain2
    sudo mkdir -p /var/www/html/domain3
    sudo mkdir -p /var/www/html/domain4
    sudo mkdir -p /var/www/html/domain4/subdomain1
    sudo mkdir -p /var/www/html/domain4/subdomain2

    4.2 Create Virtual Hosts

    Execute:

    sudo nano /etc/nginx/sites-available/domain1.com.conf

    Add:

    server {
        server_name    domain1.com www.domain1.com;
        root           /var/www/html/domain1;
        index          index.html index.php;
    
        location / {
          try_files $uri $uri/ /index.php?$args;
        }
    
        location ~* \.php$ {
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    Execute:

    sudo nano /etc/nginx/sites-available/domain2.com.conf

    Add:

    server {
        server_name    www.domain2.com domain2.com;
        root           /var/www/html/domain2;
        index          index.html index.php;
    
        location / {
          try_files $uri $uri/ /index.php?$args;
        }
    
        location ~* \.php$ {
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    Execute:

    sudo nano /etc/nginx/sites-available/domain3.com.conf

    Add:

    server {
        server_name    www.domain3.com domain3.com;
        root           /var/www/html/domain3;
        index          index.html index.php;
    
        location / {
          try_files $uri $uri/ /index.php?$args;
        }
    
        location ~* \.php$ {
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    Execute:

    sudo nano /etc/nginx/sites-available/domain4.com.conf

    Add:

    server {
        server_name    domain4.com www.domain4.com;
        root           /var/www/html/domain4;
        index          index.html index.php;
    
        location / {
          try_files $uri $uri/ /index.php?$args;
        }
    
        location ~* \.php$ {
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    Execute:

    sudo nano /etc/nginx/sites-available/subdomain1.domain4.com.conf

    Add:

    server {
        server_name    subdomain1.domain4.com www.subdomain1.domain4.com;
        root           /var/www/html/domain4/subdomain1;
        index          index.html index.php;
    
        location / {
          try_files $uri $uri/ /index.php?$args;
        }
    
        location ~* \.php$ {
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    	
        if ($host ~* ^www\.(.*)) {
          set $host_without_www $1;
          rewrite ^(.*) http://$host_without_www$1 permanent;
        }
    }

    Execute:

    sudo nano /etc/nginx/sites-available/subdomain2.domain4.com.conf

    Add:

    server {
        server_name    www.subdomain2.domain4.com subdomain2.domain4.com;
        root           /var/www/html/domain4/subdomain2;
        index          index.html index.php;
    
        location / {
          try_files $uri $uri/ /index.php?$args;
        }
    
        location ~* \.php$ {
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          include         fastcgi_params;
          fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
          fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }

    4.3 Enable Virtual Hosts

    Execute:

    sudo ln -s /etc/nginx/sites-available/domain1.com.conf /etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/domain2.com.conf /etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/domain3.com.conf /etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/domain4.com.conf /etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/subdomain1.domain4.com.conf /etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/subdomain2.domain4.com.conf /etc/nginx/sites-enabled
    sudo service nginx restart

    4.4 Check LEMP Working Status

    Our LEMP system (Linux, Nginx, MySQL, PHP) is now ready to rock. However, we should to cross check whether everything so far is good.
    Execute:

    sudo nano /var/www/html/domain1/test.php

    Add:


    You should get, “You have connected successfully.”

    Execute:

    sudo rm /var/www/html/domain1/test.php
    sudo mysql -u root -p
    show databases;
    use mysql;
    select user, host from mysql.user;
    delete from mysql.user where user='testuser';
    drop database testdb;
    exit;

    4.5 Delete Virtual Hosts

    Execute:

    sudo ls /etc/nginx/sites-enabled

    Check which vhost to delete and execute:

    sudo rm -f /etc/nginx/sites-enabled/default
    sudo rm -f /etc/nginx/sites-available/default
    sudo service nginx restart

    5. Install Let’s Encrypt SSL

    5.1 Create SSL Certificates

    sudo apt update && sudo apt upgrade
    sudo add-apt-repository ppa:certbot/certbot
    sudo apt update
    sudo apt install certbot python-certbot-nginx
    sudo ufw allow 80
    sudo certbot --nginx -d www.domain3.com -d domain3.com
    sudo certbot --nginx -d domain4.com -d www.domain4.com
    sudo certbot --nginx -d subdomain1.domain4.com -d www.subdomain1.domain4.com
    sudo certbot --nginx -d www.subdomain2.domain4.com -d subdomain2.domain4.com

    Check all existing SSL certificates.

    sudo ls /etc/letsencrypt/live

    To delete any of the above, Execute:

    sudo certbot delete

    5.2 Automatic Renewal of SSL Certificates

    Execute:

    sudo crontab -e

    Add At the end:

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

    6. Few Additional Steps

    6.1 Leverage Browser Caching

    Execute:

    sudo nano /etc/nginx/sites-available/domain1.com.conf

    Inside the Server block, Add:

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
        expires 7d;
    }

    6.2 Set Proper file and folder Permission

    Execute:

    sudo chown -R www-data:www-data /var/www/html
    sudo find /var/www/html -type d -exec chmod 775 {} \;
    sudo find /var/www/html -type f -exec chmod 664 {} \;

    6.3 Create Database for the Websites

    Execute:

    sudo mysql -u root -p
    show databases;
    CREATE DATABASE domain1 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    GRANT ALL ON domain1.* TO 'd1username'@'localhost' IDENTIFIED BY 'd1password';
    CREATE DATABASE domain2 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    GRANT ALL ON domain2.* TO 'd2username'@'localhost' IDENTIFIED BY 'd2password';
    CREATE DATABASE domain3 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    GRANT ALL ON domain3.* TO 'd3username'@'localhost' IDENTIFIED BY 'd3password';
    FLUSH PRIVILEGES;
    EXIT;

    6.4 Transfer Existing Sites from Old Host

    To Export database from Old host, Execute:

    mysqldump -u root -p databasename > dbname.sql

    To Export selected tables, Execute:

    mysqldump -u root -p databasename tablename1 tablename2 tablename3 > dbname.sql

    Copy files from Old host to New host:

    sudo scp -v -r admin@123.456.78.90:/home/admin/dbname.sql /home/admin/

    To Import database in New host, Execute:

    sudo mysql -u root -p newdbname < dbname.sql

    You may also need to copy old files from old host to new host. Execute:

    sudo scp -v -r admin@123.456.78.90:/var/www/domain1/* /var/www/html/domain1/

    If old host is secured with SSH key pair, then Execute:

    sudo nano /etc/ssh/sshd_config

    Change:

    PasswordAuthentication yes

    Execute:

    sudo service ssh restart

    6.5 WordPress Installation

    Execute:

    sudo wget https://wordpress.org/latest.zip
    sudo apt install unzip
    sudo unzip latest.zip
    sudo cp -R wordpress/* /var/www/html/domain1/
    sudo rm latest.zip
    sudo rm -rf wordpress
    cd /var/www/html
    chown -R www-data:www-data domain1

    6.6 MyBB Installation

    Execute:

    sudo wget https://resources.mybb.com/downloads/mybb_1817.zip
    sudo apt install unzip
    sudo unzip mybb_1817.zip
    sudo cp -R Upload/* /var/www/html/domain2/
    sudo rm mybb_1817.zip
    sudo rm -rf Upload
    sudo rm -rf Documentation

    6.7 Update DNS Settings

    Set DNS of all the domains point to the correct IP address. You need to add A/AAAA records pointing to the IP address of the VPS.

    That’s it. Hope you have successfully host websites in your own VPS. If you still have any query, you are free to ask. We surely get back to reply.

     

  • Linode provides unmanaged VPS hosting. Linode 1GB (1024) 2GB (2048) costs 10USD per month. You may host unlimited websites in a Linode. Here we will describe the steps involved to host many websites in a single Linode 2048.

    1. Create an Account with Linode

    Goto Linode.com and create an account. you need to provide your credit card details.

    2. Add a Linode

    Select a plan and add a linode as follows:

    add-linode

    From your Dashboard copy the IP of your Linode and note down some place else.

    3. Install OS e.g. Debian 8.1

    The process is called Rebuild. Rebuild you Linode with Debian 8.1.

    debian-rebuild

    Choose a Password for Root.

    4. Boot Linode

    Click the Boot button and your linode will start.

    linode-boot

    you will see your linode booting

    linode-booting

    5. Run Putty in Windows

    Run Putty with the IP address you copied in step 2.

    run-putty

    A security alert will pop up. Click Yes.

    Login with your root password, you already set in step 3.
    You will see a command prompt in black screen.

    6. Set a Hostname

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

    hostnamectl set-hostname supercom

    Check whether the hostname has been set properly. Run:

    hostname

    You will get supercom as output.

    Again Run the following to set hostname in everywhere:

    nano /etc/hosts

    Now change the text debian to supercomp.

    etc-hosts

    Save and Exit by Pressing Ctrl+X and y.

    7. Set the 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.

    8. Install software Updates

    Run the following to update your system softwares:

    apt-get update
    apt-get upgrade

    During upgrade you need to press y to continue.

    9. Create User

    adduser admin

    add-admin

    usermod -a -G sudo admin

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

    10. Secure Linode with SSH Key Pair

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

    puttygen
    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.

    11. Create a Firewall

    Run the following:

    sudo nano /etc/iptables.firewall.rules

    Paste the following into this file.

    *filter
    
    -A INPUT -i lo -j ACCEPT
    -A INPUT -d 127.0.0.0/8 -j REJECT
    
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    
    -A OUTPUT -j ACCEPT
    
    -A INPUT -p tcp --dport 80 -j ACCEPT
    -A INPUT -p tcp --dport 443 -j ACCEPT
    
    -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
    
    -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
    
    -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
    
    -A INPUT -j DROP
    -A FORWARD -j DROP
    
    COMMIT

    Activate the rules:-

    sudo iptables-restore < /etc/iptables.firewall.rules

    Make sure the rules always activate while you restrat linode

    sudo nano /etc/network/if-pre-up.d/firewall

    Paste the following script.

    #!/bin/sh
    /sbin/iptables-restore < /etc/iptables.firewall.rules

    Run this:

    sudo iptables -L

    If everything is OK, you will find the following output.

    iptables

    12. DDOS Protection

    Run the following commands:

    sudo apt-get install fail2ban
    sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    sudo nano /etc/fail2ban/jail.local

    Set “enabled” to “true” in the [ssh-ddos] section. Then restart Fail2ban.

    ssh-ddos

    sudo service fail2ban restart

    13. Install Nginx Web server

    Run the following command:

    sudo apt-get update
    sudo apt-get install nginx

    After successful instal open your browser and type the IP address. You will see the following:

    nginx

    To configure Nginx according to your hardware specification, run:

    sudo nano /etc/nginx/nginx.conf

    Change worker_processes value to 1. To further optimize nginx configuration is out of the scope of this guide. It will be posted some other day.

    To prepare Nginx to run PHP, you need to edit default values. Run

    sudo nano /etc/nginx/sites-available/default

    And uncomment by removing # from the following segment

    location ~ \.php$ {
    include snippets/fastcgi-php.conf
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    

    Restart Nginx Server by typing the following:

    sudo service nginx restart

    14. 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

    15. Install PHP

    Run the following command:

    sudo apt-get install php5-fpm php5-mysql

    Change Configuration

    sudo nano /etc/php5/fpm/php.ini

    Find cgi.fix_pathinfo inside the configuration file and make it like

    cgi.fix_pathinfo=0

    You need to remove initial ; from the above line.

    Save and Exit. Restart PHP5

    sudo service php5-fpm restart

    To check whether php successfully installed you need to run:

    sudo nano /var/www/html/info.php

    Type the following code:

    phpinfo

     

    Now type the following in your browser:

    http://your_server_IP/info.php

    Replace your_server_IP with your actual IP.
    You will see the following output.
    phpinfo
    At this point, your server is ready to host as many websites as you like. All you need is to create different nginx virtual hosts for different websites.

    16.Host Multiple Websites

    In this example we will show how to host 2 websites. For multiple websites you just need to repeat the process as described.
    Suppose we want to host example1.com and example2.com

    At first create content directories for websites. Run:

    sudo mkdir /var/www/html/example1
    sudo mkdir /var/www/html/example2

    Now create virtual host for example1.com

    sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example1
    sudo nano /etc/nginx/sites-available/example1

    This file looks like the following after removing unnecessary comments.

    server {
    	listen 80 default_server;
    	listen [::]:80 default_server;
    	root /var/www/html;
    	index index.html index.htm index.nginx-debian.html;
    	server_name _;
    	location / {
    		try_files $uri $uri/ =404;
    	}
    	location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/var/run/php5-fpm.sock;
    	}
    }
    

    Now change the above file to host example1.com

    server {
    	listen 80;
    	listen [::]:80;
    	root /var/www/html/example1;
    	index index.php index.html index.htm;
    	server_name example1.com;
    	location / {
    		try_files $uri $uri/ /index.php?$args;
    	}
    	location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/var/run/php5-fpm.sock;
    	}
    }
    

    Now enable example1.com and restart nginx.

    sudo ln -s /etc/nginx/sites-available/example1.com /etc/nginx/sites-enabled
    sudo service nginx restart

    If you have already changed your DNS settings for your domain name example1.com as

    ns1.linode.com
    ns2.linode.com
    ns3.linode.com
    ns4.linode.com
    ns5.linode.com
    

    You should see example1.com in your browser in action. Hurray, you just successfully hosted your first website example1.com.
    Again to host example2.com, first copy the vhost file:

    sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example2
    sudo nano /etc/nginx/sites-available/example2

    Now change the above file to host example2.com like this:

    server {
    	listen 80;
    	listen [::]:80;
    	root /var/www/html/example2;
    	index index.php index.html index.htm;
    	server_name example2.com;
    	location / {
    		try_files $uri $uri/ /index.php?$args;
    	}
    	location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/var/run/php5-fpm.sock;
    	}
    }
    

    Now enable example2.com and restart nginx.

    sudo ln -s /etc/nginx/sites-available/example2.com /etc/nginx/sites-enabled
    sudo service nginx restart

    Similarly, you should see example2.com in your browser in action. So go ahead and repeat the process to host unlimited websites in Linode.

  • Google announced to rank better, a website which loads faster.
    So, Website Developers are trying to make their sites speedy by various techniques. The key points are:-

    • Use a Fast Hosting Service
    • Choose a Data Center which is nearest to your visitors.
    • Install a fast performance based web server.
    • Use minimal theme and avoid too many graphics.
    • Use less plugins.
    • Cache your site content.

    Now we like to address the above issues in short. We choose Linode as our hosting provider, because it is solid, stable, proven for years.

    Choosing data centers is often a vital issue. There are 7 data centers of linode:-

    1. Newark
    2. Fremont
    3. Atlanta
    4. Dallas
    5. London
    6. Tokyo
    7. Singapore

    Data centers are geographical location where your site content are kept. For one of our client site of which the visitors are all from India, we first thought of Singapore would be the best choice as it is nearest geographically with India. Our second choice was Tokyo. But surprisingly, this proved to be wrong. We found London serves faster than Singapore and Tokyo.

    We tested with a small file uploaded to three different data centers and found that:-

    Data Center at Singapore
    singapore
    Data Center at Tokyo
    tokyo
    Data Center at London
    london

    You can see that the page loading time is minimum in case of London data center  in comparison with Singapore and Tokyo. So for Indian websites we recommend to use a london data center.

    We rely on NGINX web server. It is relatively new compared to the popular Apache web server. Nginx can handle huge number of traffics compared to apache and it consumes less memory. Nginx has built in caching capability which performs excellent. So no need to install plugin.


    Update: To differentiate the page load time between Tokyo, Japan and London, U.K. we actually hosted our full site. We noticed that inspite of Tokyo is nearer to India than London, we got better result in London.

    WBXPress Home Page hosted at London:-

    wbxpress-home-london

    WBXPress Home Page hosted at Tokyo:-

    wbxpress-home-tokyo

    WBXPress Single Post Page hosted at London:-

    wbxpress-single-london

    WBXPress Single Post Page hosted at Tokyo:-

    wbxpress-single-tokyo

  • Linode Upgraded its Virtualization Platform

    ·

    We are at Linode. Linode is the biggest VPS provider. Recently Linode upgraded its virtualization platform from Xen to KVM.

    kvm-upgrade

    What is this?

    KVM is a virtualization technology that is an alternative to Xen. Its benefits include much greater performance (less overhead), and the ability to run weird OSs. It is the future here at Linode.

    How much faster?

    • 300% improvement in UnixBench score, with a KVM Linode vs a Xen Linode
    • 28% faster at compiling a Linux kernel with a KVM Linode vs a Xen Linode
    • Boot and shutdown times are greatly improved

    Will this break stuff?

    Probably not. Upgrading an existing deployment to KVM requires that the “Distro Helper” is enabled in your configuration profile. This will happen automatically.

    Specific changes from Xen to KVM will be detailed in our upcoming KVM guide…

    And We just Upgraded to KVM

    xen-kvm
    And It was Smooth!!