How to setup a web server on a virtual private server

June 22, 2016

Are you disappointed with functionality of a shared hosting? Does your growing web-project demand for more resources? The optimum solution for young and prospective websites, gaining ground on the net, is the switch from shared hosting to virtual private server.

VPS/VDS is a Virtual Private (Dedicated) Server. As a rule, this service includes access to a part of physical server hardware resources (configuration and performance of which depend on the plan you choose). It is a real quantum leap in the field of online resource development.

VPS/VDS hosting combines flexible dedicated server configuration, individual IP address, ports, ability for user to choose a software and means of developing. All the services are available for a reasonable price, not much higher than the price of a shared hosting.

Still, leasing a virtual server requires your own configuration and software optimization. However, that should not discourage you - the devil is not so black as he is painted. This article is a guide through the installation the necessary software and maintenance of stable web server operation. All the settings below are valid for the Linux Debian platform – one of the most secure operating systems, providing a high performance with minimum resources consumption.

Optimum VPS configuration

The major problem of any shared hosting is that one physical server may contain 50-100 websites on average. The idea is that the load is distributed evenly through the day, as long as users donХt visit sites simultaneously. In theory each site should successfully cope with several thousand users per day, nevertheless, in practice everything often goes sideways.

Usually popular online resources occupy RAM and some web applications engage the most part of the computing resources, as a result loading time of slack projects increases gradually. In effect, during the peak time server simply fails to cope with higher load and the majority of the websites and web applications on the server become not reachable at best. In the worst case, none of them are accessible.

However, if you lease a virtual server, this isnХt a problem for you anymore. You have a certain amount of hardware resources at your disposal that none else can use. Therefore, even at peak times your site will work stably, and during the slow periods no other application would be able to occupy the RAM or CPU time. The question is which configuration would fit you best?

Small project

If you switch from a shared hosting or just set up a project, which has high security requirements, the minimal characteristics are enough:

  • 512 MB of RAM;
  • 5 - 10 GB of disk space;
  • 1,5 - 2 GHz CPU.

The resources are enough to cope with up to 10 thousand users a day. Moreover, it is possible to reach the number of 20-25 thousand users, if webmaster makes optimization correctly. Further, as the number of users will increase, you may broaden the potential of the system by changing your plan for more expensive one.

Rapidly growing website, forum or small online-shop

  • 1 - 2 GB of RAM;
  • 20 - 30 GB HDD;
  • 2 cores of 2-2,5 GHz.

It is a good variant for popular websites, news portals, blogs with the audience of 20-30 thousand visitors a day.

Thriving website, small game server (Minecraft, Mu, Lineage, etc.)

  • From 4 GB of RAM;
  • 30-50 GB HDD;
  • 2 - 3 cores of 3 - 3,5 GHz.

The best solution for successful web projects with the audience of about 50 thousand users. The hardware is enough to process multimedia content and develop online-game servers.

The characteristics are valid for Linux Ubuntu and Linux Debian distributions. They are particularly stable and provide high performance with the minimum resources consumption.

Connection to a server via SSH

To connect to a VPS SSH protocol is used. SSH (Secure Shell) is a secure protocol purposed for remote control of an operating system, software and file transfer. SSH uses reliable encryption algorithms and provides secure connection to a server.

To get the SSH protocol work you need a server, installed on a host, and a client. Control over the VPS/VDS server is implemented through the command line interface.

There are quite a few client applications suitable for various operating systems. The most simple, reliable and popular among them are Bitvise SSH Client and PuTTY. In the case below weХll use the second one.

In the ЗHost NameИ field you should enter the IP-address of the virtual server, switch the "connection type" radiobox to SSH, value of ЗPORTИ field should remain 22, in ЗSaved SessionsИ choose random session name. Now you should press ЗOPENИ at the bottom of the window.

After that youХll see the console window, looking similar to the Windows command line. The system will ask you to enter a login – root by default.

Pay attention! ЗRootИ stays for the super user with the superior privileges in Linux system, which is the same to ЗAdministratorИ in Windows system. Further youХll be able to create a separate user with limited privileges for each website.

Next you should enter the password (in PuTTY you may simply copy it with a right mouse click) and then pressEnter.

Now connection is established!

For security purposes you may add a user with the limited privileges before continue. To do that you should enter the command:

adduser john_doe

where john_doe may be changed for any other username.

In the dialogue box that will appear, you should enter a new password. You may also fill in the fields with the additional information about the user.

Then you should allow the new user to implement commands of the super user. To do that youХll need a sudo utility.

Pay attention! Sudo is an utility that allows a user to administer a system with root privileges. It is activated by entering "sudo" at the beginning of a command.

Installation of any software in Linux operating systems always starts with packet index updating. During the packet index updating your system accesses repository (where the main part of software for your distribution is held) and "checks out" the latest versions of the software and interdependence of software packages.

You should begin with the command:

apt-get update

Once the index is updated, you should install the sudo utility:

apt-get install sudo

Then allow john_doe to implement the sudo command:

usermod -a -G sudo john_doe

Now you can enter the system and continue configuring it as the new user. Enter the command:

ssh john_doe@хх.ххх.xx.xx

where хх.ххх.xx.xx is the IP-address of the server.

You will be asked whether you want to make a connection. In the console you should enteryesand pressEnter.

There you may see some useful commands for work with the command console:

  • ls -lha - show a list of files, downloaded to a server, and data about their size and access rights;
  • cd [directory name] - go to the chosen directory;
  • mv - change the name/transfer;
  • rm - delete;
  • cp - copy;
  • chmod - settle access rights to the file or directory;
  • cat - show the file;
  • mc - start the integrated file manager, similar to the Norton Commander;
  • mkdir [random_name] - create a new directory.

Now you are ready to start installation of the necessary software.

LAMP installation and configuration

In order to launch and configure a web server you will need to install basic software: LAMP (Linux+Apache+MySQL+PHP). You can start the installation of the LAMP set and phpMyAdmin panel by entering:

sudo apt-get install apache2 apache2-doc mysql-server mysql-client php5 php5-mysql libapache2-mod-php5 phpmyadmin

Then youХll see the dialogue box, where you will be asked to confirm the installation of the chosen files. To confirm enterYand pressEnter.

In the next dialogue box you should create a password for MySQL data base (later you will be able to change the password):

To confirm enter the password once again:

Then the system requests a server type to make an automatic configuration of phpMyAdmin. You should choose apache2:

In the next dialogue box youХll have to confirm the standard settings for phpMyAdmin and automatic creation of a system data base (pressYandEnter):

Create a password for phpMyAdmin and repeat it:

Now you need to correct the Apache configuration. Open the configuration file:

sudo nano /etc/apache2/apache2.conf

Go to the end of the file and enter on the new line:

ServerName localhost:80

To quit the editor pressCtrl+Xand confirm the changes by pressingYandEnter.

How to add websites to VPS: Apache and DNS configuration

Apache allows creating an endless number of virtual hosts, which makes it possible to link several sites to a single IP-address. Nevertheless, you shouldnХt forget about hardware resource limits. The process of hosting for several sites includes a number of steps.

Step 1. Creation of separate websitesХ directories

First of all, you should create the directories, which Apache will access. All the files of your websites and web applications will be held there. In the command console you should enter:

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

mkdir is a command which creates a directory (folder); З-pИ parameter is defined for recursive folder creation: firstly, Зmysitename1.orgИ directory is created; secondly - Зpublic_htmlИ directory, where the content of the web resources, you are going to place, will be held. З/var/www/И is a path to create new directories. Names of the folders may be random.

Please, note, that Apache has access only to the /var/www directory and the folders and files within.

Step 2. Setting file permissions

All the permissions for directories belong to the root-user by default. It is necessary to define the owner(s) for security purpose. To do this you should enter:

sudo chown -R john_doe:john_doe /var/www/
sudo chown -R john_doe:john_doe /var/www/

where john_doe is the name of a user, who is presumed to have access to public_html directories, where websiteХs files are held.

To edit access permissions enter:

sudo chmod -R 755 /var/www

Pay attention!Access permissions in Linux systems are set in numbers for all users: file-/directory-creator, ownerХs user group and other users.

For example, 755 means:


7 5 5
All rights: reading, executing and writing Reading and executing Reading and executing

In the following table you may see the variants of entitling access permissions:

ValueAccess rights to the fileAccess rights to the directory

0 No No
1 Executing Reading files, viewing file properties
2 Writing No
3 Writing, Executing All, except viewing list of files
4 Reading View file names
5 Reading, Executing Access, Reading
6 Reading, Writing Access, Reading
7 Full rights Full rights

Step 3. Test pages

In order to verify server configurations, it is necessary to create test pages. Here is an example for a first website. This procedure is similar for all the resources that are to be installed on the server.

Firstly, you should create index.html:

nano /var/www/

Within the file you should create a simple html document:



	<title>Welcome to!</title>



	<h1>Virtual hosting works!</h1>



Then you should save the document.

YouХll have to do the same procedure for all other sites. Still, you can save time by simply copying the contents of the first document into the second website directory:

cp /var/www/ /var/www/

Step 4. Apache virtual hosts configuration

Right out of the box web server Apache has a file default with virtual hosting configuration. You only have to edit the source document.

Firstly you should copy the file:

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

Then you should edit it with your root-privileges:

sudo nano /etc/apache2/sites-available/

Next the file contents should be changed with the following minimum configuration:

<VirtualHost *:80>



    DocumentRoot /var/www/

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined


Now you can save the document and do the same to the rest of domains.

Step 5. Turn on the hosts

In order to apply new configuration you should enter:

sudo a2ensite mysitename1_org.conf

sudo a2ensite mysitename2_org.conf

Then restart the server to activate the changes:

sudo service apache2 restart

Step 6. NS domain records configuration

Another important point is changing NS records for your domains. The easiest way is to link a domain name to the IP-address of your VPS at Domain Name Services Company. To do this youХll have to park a domain to the serviceХs DNS servers and in the DNS-zone control section create three A-type records (or ones of any similar type) named: З*И, З@И and ЗwwwИ. In the ЗIPИ field you should enter the VPS address. Please, pay attention! Changing of the NS records may take up to 24 hours.

In case you use a test unregistered domain name, it is necessary to change ЗhostsИ file on the local computer, so that you could test workability of the configured web server. In Windows system this file has the following path: ЗC:\Windows\System32\Drivers\etcИ.

You should open the file in Notepad with administrating privileges. At the end of the file you should add IP address of the server and test domain names of your websites:



Save the document. Here хх.ххх.хх.ххх stands for the VPS IP-address.

Now the web server is configured!

If you enter into your browser address bar, youХll see the following text: Virtual hosting works.

It means that everything is ready for downloading and installation of your working projects.

Subscribe For Our Newsletter
to get the latest updates of our blog!

Learn more about our services

VPS Hosting

High-performance virtual private servers on KVM virtualization built on cutting-edge hardware

Dedicated Servers

Powerful dedicated servers deliver high performance, reliability and security of your data

Dedicated Server Sale

Customizable & affordable configurations allow saving your budget on not resource-intensive projects

Acronis Backup

Complete and efficient data protection for any environment