Recommended VPS Complete list of best VPS hosting providers.

How To Add New Site Into Your Apache-based Debian Server

Alright so you installed Apache web server on your VPS running Debian OS on top of it. But then how can you host your websites in it and how to add new website on it? The answer is Apache Virtual Host file. It is a configuration file where you can put necessary configuration regarding websites you want to host it on your server / vps. In Debian (and Ubuntu) you can simply create a specific Virtual Hosts file for each domain or subdomain then enable or disable it using simple command. Curious? Let’s move on to the steps.


  1. A SSH client like Putty and basic knowledge about how to use it.
  2. Basic knowledge about common Unix command to SSH to your server.
  3. A server or VPS with at least 512MB of RAM (in OpenVZ you can use 256MB but not really recommended). If you not already have one then you can read my list of recommended VPS providers or this top low end cloud server providers. Quick recommendation:, Digital Ocean and RamNode.
  4. Have one already? Now install Ubuntu or Debian OS on it. In this tutorial I use Debian 8 32-bit on Atlantic’s 512MB cloud server.
  5. Install Apache, MySQL / MariaDB and PHP on it. How to install LAMP on Debian and Ubuntu.
  6. About 20 minutes of your time
  7. a cup of coffee or tea.

The Steps

Step 1 – Login to your server as root or as user with root / sudo privilege. In this article I simply login as root so I ditch sudo, however if you logged in as user, then do not hesitate to add sudo prefix to each command.


Step 2 – Now you have to firstly create the directory where you will put all your site’s files on it (html, php, jpg, png, css, js, etc). This is being main directory of your websites.

mkdir -p /var/www/

# or you can also name it htdocs
mkdir -p /var/www/

change with your own domain name. Structuring web directories to each domain name will come handy in the future. Here’s an example:


Step 2 – Now you will also need to grant ownership of that directory to a user and group you wish. Use command below:

chown -R $USER:$USER /var/www/

However if you are using WordPress and you want for Auto update to work within Admin page, you can simply chown that directory to the webserver:

chown -R www-data:www-data /var/www/



Step 3 – Make sure everyone can read files to the Apache web root directory, so chmod it to 755:

chmod -R 755 /var/www/



Step 4 – Now you can upload all your web files to that directory using your favorite FTP client. In this example, for the test purpose you can simply create a new .html file, name it index.html

nano /var/www/

then enter this in that new file:

 <title>Test Page for</title>
 <h1>Welcome To website</h1>



inside Nano editor:


Save that file and exit (In Nano it is Control+O then Control+X)

Step 5 – Now it is time to create Virtual Hosts file for that website.

nano /etc/apache2/sites-available/



do not forget to always replace with your own domain name:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        DocumentRoot /var/www/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

change with your real email and domain name. Example:


Save changes and exit the editor which in Nano it is Control+O then Control+X.

Step 6 – The Virtual Hosts file has been created and now you can enable it using following command:


You can understand the command as acronym of “apache 2 enable site“. Also, you need to reload apache service after that:

service apache2 reload



Step 7 – Now give it a test. Open up your browser and type your domain name in it. You’ll then see the test page we created earlier:


That’s all.


Q: I can’t use the command with Nano part in it?
A: You have to firstly install it:

apt-get install nano -y

Q: I open up my browser but I can’t open my website?
A: You have to firstly setup a proper DNS entry for your domain name. For this, you can use third-party free DNS manager or use your own DNS server if you have it installed. As per my example above, I just use dummy domain name and simply edit my local hosts file (on Windows). Useful tutorial:

Q: I want to add another website or domain, how can I do that?
A: Simply repeat steps above for your another domain.

Enjoy! Do not hesitate to drop comment below.. Have a nice day!


Add a Comment

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

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.