How to add new website into your Apache-based Debian server

So we have already set up a working Debian server with an Apache, Now the question is how can we host a new website on this? Simply we can do it via Apache virtual host file where we can put necessary configuration regarding websites we want to host on our Server.

First of all SSH into your server via root user,I am using putty here.

Now we will create the directory where we can put all our files for website. That would be a main directory for your website.

mkdir -p /var/www/domain.com/public_html

Or you can also name it httpsdocs

mkdir -p /var/www/domain.com/httpsdocs

Make sure to change domain name with your domain name. Now change the ownership of the domain with the user and group you want to:

chown -R $USER:$USER /var/www/domain.com/public_html

Make sure everyone can read files to the Apache web root directory so change permissions as follows:

chmod -R 755 /var/www/

Now you can upload all your files to that directory using your favorite FTP client.

Next it’s time to create a virtual host file for that website.

nano /etc/apache2/sites-available/domain.com.conf

Don’t forget to always replace domain.com 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.

        #ServerName www.example.com


        ServerAdmin [email protected]

        ServerName domain.com

        ServerAlias www.domain.com

        DocumentRoot /var/www/domain.com/public_html


        # 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

</VirtualHost>

Save changes and exit the editor.

Virtual host file has been created now we can enable it by using the below command:

a2ensite domain.com.conf

After that restart your Apache service:

service apache2 restart

Now we can test it into our favorite browser.

That’s all and now you know how it’s easy to setup a new website into Apache-based Debian server.

Give your opinion below if you experience any issues or to discuss your ideas and experiences.