Setup Virtual Hosts into VPS

Execute the following commands after ssh into vps:

sudo mkdir -p /var/www/example.com
sudo chown -R $USER:$USER /var/www/example.com
cd /var/www/
sudo chown www-data:www-data * -R 
sudo usermod -a -G www-data username-logged-in-as
cd
sudo nano /var/www/example.com/index.html

Add a basic html page for now:

<html>
<head>
<title>www.example.com</title>
</head>
<body>
<h1>Success: You Have Set Up a Virtual Host</h1>
</body>
</html>

Setup sites-available by copying the default setup:

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com
sudo nano /etc/apache2/sites-available/example.com

Next setup the domain virtual hosts file:

ServerAdmin webmaster@localhost
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
Redirect 301 http://www.example.com http://example.com

Make sure we have AllowOverride set to All so .htaccess files work properly and make sure Indexes is removed from Options to prevent directory listing:

<Directory /var/www>
    Options FollowSymLinks MultiViews
    AllowOverride All
</Directory>

Let's also prevent hotlinking of files:

SetEnvIf Referer example\.com localreferer
<FilesMatch \.(jpg|png|gif|css|js|pdf|doc|xls|txt)$>
    Order deny,allow
    Deny from all
    Allow from env=localreferer
</FilesMatch>

Activate and restart:

sudo a2ensite example.com
sudo service apache2 restart

MySQL

Add a new database and user for that database:

CREATE DATABASE example;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON example . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;

Dump a database and import a database:

mysqldump -u [username] -p [database name] > [database name].sql
mysql -u [username] -p newdatabase < [database name].sql

Securely copy files over ssh

You can use scp (secure cp(copy)) to copy files from one server (=remote server) to a other server (=remote server).

Coping files from local server to remote server
scp /source/file/ user@ipaddress:/destination/file/

Coping files from one remote server to another remote server
scp user@ipaddressofserverone:/source/file/ user@ipaddressofserver2:/destination/file/

Where

user : Is the user which have the right to access the file and directory, that is supposed to be copied in the case of the from-host, and the user who has the rights to write in the to-host

ipaddressofserverone : Is the name or IP of the host where the source file is

source/file : Is the file(s) that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory

destination/file : Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to keep its names

SCP Options

-p : Preserves the modification and access times, as well as the permissions of the source-file in the destination-file
-q : Do not display the progress bar
-r : Recursive, so it copies the contents of the source-file (directory in this case) recursively
-v : Displays debugging messages