Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Set Up Apache Virtual Hosts on Debian 7

Rumi, July 29, 2019

Step One— Create a New Directory

First, it is necessary to create a directory where we will keep the new website’s information. This location will be your Document Root in the Apache virtual configuration file. By adding a -p to the line of code, the command automatically generates all the parents for the new directory.

You will need to designate an actual DNS approved domain (or an IP address) to test that a virtual host is working. In this tutorial, we will use example.com as a placeholder for a correct domain name.

sudo mkdir -p /var/www/example.com/public_html

*If you want to use an unapproved domain name to test the process, you will find information on how to make it work on your local computer in Step Seven.

Step Two—Grant Permissions

Now you must grant ownership of the directory to the user, as opposed to just keeping it on the root system.

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

Additionally, it is important to make sure that everyone will be able to read your new files.

sudo chmod -R 755 /var/www

Now you are all done with permissions.

Step Three- Create the Page

Within your configurations directory, create a new file called index.html

sudo nano /var/www/example.com/public_html/index.html

It’s also useful to add some text to the file, in order to have something to look at when the IP redirects to the virtual host.

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

Save & Exit.

Step Four—Create the New Virtual Host File

The next step is to set up the apache configuration. We’re going to work off a duplicate—go ahead and make a copy of the file (naming it after your domain name) in the same directory:

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

Step Five—Turn on Virtual Hosts

Open up the new config file:

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

We are going to set up a virtual host in this file.

To begin, insert a line for the ServerName under the ServerAdmin line.

ServerName example.com

The ServerName specifies the domain name that the virtual host uses.

If you want to make your site accessible from more than one name (ie with www in the URL), you can include the alternate names in your virtual host file by adding a ServerAlias Line. The beginning of your virtual host file would then look like this:

<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
[...]

The next step is to fill in the correct Document Root. For this section, write in the extension of the new directory created in Step One. If the document root is incorrect or absent you will not be able to set up the virtual host.

The section should look like this:

DocumentRoot /var/www/example.com/public_html

You do not need to make any other changes to this file. Save and Exit. The last step is to activate the host with the built-in apache shortcut:

sudo a2ensite example.com

Step Six—Restart Apache

Although there have been a lot of changes to the configuration and the virtual host is set up, none of the changes will take effect until Apache is restarted:

sudo service apache2 restart
Administrations Configurations (Linux) ApacheDebianVirtual Host

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

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

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes