At first, I recommend you to make some coffee for you.
The second main thing that you need is a Debian server account with “sudo” privileges.
Then you need Apache installed on your system. If you want to know how to install Apache web server read this.
if you have done all these steps you should log in into your server. If you use the terminal of Debian system use the command “ssh” in Windows OS you can download “PuTTY” and use it for connecting to the server.
Let’s create the directory structure.
You should create all your files and directories for your site into /var/www. Because it is the top-level directory which Apache search to find the content to serve. Let’s create the directory for our tutorial there. Use the command “mkdir” to create some directories like this:
but I want to create just one more directory:
Are you interested in what is “-p”?
INFO: the command “mkdir” can create just one directory but if you want to create nested directories you should use “-p”.
The Irony of Fate!!! we have created the directories but we haven’t any permission to modify the files in it. The problem is that files are owned by the root user. The solution is to change the ownership of that files by using the command “chown” like this:
sudo chown –R $USER:$USER /var/www/domainofyourtestsite.com/public_html
sudo chown –R $USER:$USER /var/www/domainofyourtestsite2.com/public_html
Now let’s change your permissions to be sure that you can make changes into that files. Use the command “chmod”: there are several ways to do that I prefer the following way:
sudo chmod 755 /var/www
creating demo page.
let’s create an index.html file for each of our domains (domainofyourtestsite.com and domainofyourtestsite2.com). In this tutorial, I will use “nano” to edit files. You may use your favorite text editor:
in this file you need to create some html document like this:
Save and close that file.
INFO: to save your document with “nano” use “ctrl+o” then “ctrl+x” to exit.
you can use the command “nano” again and create the same document into “domainofyourtestsite2.com” or copy this content and make changes there like this:
cp /var/www/domainofyourtestsite.com/public_html/index.html /var/www/domainofyourtestsite2.com/public_html/index.html
we have just copied the file, now let’s make some changes:
Save and close this file too. Now you have some pages to test your host configuration.
Creating new files for virtual host.
In this step, we will create a directory by name “sites- available”. In which you need to add all your virtual host files. Apache comes with a default virtual host file by name 000-default.conf that you can use as a jumping-off point.
Copy this file for the first domain:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/domainofyourtestsite.com.conf
open that file with the editor:
sudo nano /etc/apache2/sites-available/domainofyourtestsite.com.conf
Now copy this bunch of code there then save and close that file:
Let’s understand what it means.
these two lines are responsible for designating the content as a virtual host which is listening on port 80 (80 is the default HTTP port)
Via this two lines you say that your main server name is “www.domainofyourtestsite.com” and at the same time, you make an alias for the server to point “domainofyourtestsite.com” to. Now the request for “www.Domainofyourtestsite.com” and “domainofyourtestsite.com” will show the same content.
These three lines tell Apache where to store the error page and request logs for this particular site.
Now let’s copy this content for second virtual server and make corresponding changes for it. Use this command:
sudo cp /etc/apache2/sites-available/domainofyourtestsite.com.conf /etc/apache2/sites-available/domainofyourtestsite2.com.conf
Open this file to with command “nano”:
sudo nano /etc/apache2/sites-available/domainofyourtestsite2.com.conf
now you should modify that file like this:
After modifying the file save and close it.
Enable the new virtual host files.
You have already created folders and Apache virtual host config files, but Apache will not use them because they aren’t active. Use the command “a2ensite” to activate them:
If you see something like this all is well you can continue.
Now use the same command for the second site:
after this command you will see something similar like above:
Now you need to disable the default site defined in “000-default.conf” via “a2dissite” command like this:
Restart the Apache:
sudo systemctlrestart apache2
Now if you use a real domain you can test your site but if you use your local machine or just try out this tutorial you need to do something more.
If you use Mac or Linux systems use this command:
if you use Windows Command prompt with administrative privileges.
Add into this file the line that maps your server’s public IP address to each domain name like this:
You need to do this because you need to direct any requests for domainofyourtestsite.com and domainofyourtestsite2.com on your local machine and send them to your server at 22.214.171.124 .
In this case, this site will be available only for your local machine.
Now you can type in your browser your domain in our case the domain is “domainofyourtestsite.com”
And you will see something like this:
We have done it.
That is all!!! Thanks for reading us!!!