Create a New Apache Site

Photo by Taylor Vick on Unsplash

Create a New Apache Site

A Step-by-Step Guide to Creating a New Site in Apache2

Install Apache: If you haven't already done so, install Apache using the following command

sudo apt-get update
sudo apt-get install apache2

Create a new directory for your site under the /var/www directory. For example, if you want to create a site called, you can create a directory called /var/www/

sudo mkdir /var/www/
#Create an index.html file inside the new directory with the following command and the below contnet
sudo vim /var/www/
<!DOCTYPE html>
    <title>Hello World!</title>
    <h1>Hello World!</h1>
    <p>This is a test page.</p>

Set the correct file permissions for the new directory and file

sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/

Create a new virtual host configuration file for your site

sudo vim /etc/apache2/sites-available/

Inside the file, type the following configuration:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Enable the new virtual host configuration and restart Apache

sudo a2ensite
sudo systemctl restart apache2

Finally, add an entry to your /etc/hosts file to map the domain name ( to the IP address of your local machine,

# on the machine you have browser access ,
sudo vim /etc/hosts
# add the below line by replacing with your local server IP address

Note: If you have a real server and Domain name you don't need this, you just have to Add a DNS record to your domain name provider

Finally, Test the Application from your Browser