Logo

dev-resources.site

for different kinds of informations.

How to setup an Apache server on Ubuntu 22.04.4 LTS with Virtual hosting

Published at
5/31/2024
Categories
apache
devops
ubuntu
selfhosting
Author
oyololatoni
Categories
4 categories in total
apache
open
devops
open
ubuntu
open
selfhosting
open
Author
11 person written this
oyololatoni
open
How to setup an Apache server on Ubuntu 22.04.4 LTS with Virtual hosting

Apache is a popular open source web server that is widely used to host web pages.

In this tutorial, you’ll be creating a virtual host environment to run multiple websites with Apache on your Ubuntu 22.04.4 LTS server allowing you to add several domains hosted on just 1 IP address.

Installing Apache

We’ll begin by updating the local repository with the following command

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Next, install the Apache server

sudo apt install apache2
Enter fullscreen mode Exit fullscreen mode

Run this command to start the Apache server

systemctl start apache2.service
Enter fullscreen mode Exit fullscreen mode

Run this command to verify that Apache is running

systemctl status apache2.service
Enter fullscreen mode Exit fullscreen mode

You can test if your Apache server is live by typing your public IP address in your web server, you should get the following result

apache home page

Configuring Your Own Website

Apache by default is setup to serve documents from **/var/www. **So you will need to create store your webpage directory in this folder. We will be using demo.com here as follows:

sudo mkdir -p /var/www/demo.com
Enter fullscreen mode Exit fullscreen mode

You will need to modify the ownership of this directory so as to be accessible and executable by your user account. This is done by executing the following:

sudo chown -R $USER:$USER /var/www/demo.com
Enter fullscreen mode Exit fullscreen mode

Next you will change the permission settings of the directory to allow everyone to have read and execute permissions while the $USER has read, write and execute permissions

sudo chmod -R 755 /var/www/demo.com
Enter fullscreen mode Exit fullscreen mode

Next create an index.html file that will be used to host your site’s html code

sudo vim /var/www/demo.com/index.html
Enter fullscreen mode Exit fullscreen mode

Insert the following code in the index.html **file by pressing **i **to write the file. And to save it press **ESQ **to exit insert mode, *and *:wq **after to save and quit the the file editor

<html>
    <head>
        <title>Welcome to Your_domain!</title>
    </head>
    <body>
        <h1>Success!  The your_domain virtual host is working!</h1>
    </body>
</html>
Enter fullscreen mode Exit fullscreen mode

Setting up the VirtualHost Configuration File

The next step is to setup the configuration file for the webserver in the /etc/apache2 folder — which is where the Apache configuration file is located. The file also uses the **.conf **extension. Create the configuration file using the following command

sudo vim /etc/apache2/sites-available/demo.com.conf
Enter fullscreen mode Exit fullscreen mode

Insert this code into the file

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName demo.com
    ServerAlias www.demo.com
    DocumentRoot /var/www/demo.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

Save and close the file

Activating VirtualHost file

After setting up the website, the next step is to activate the virtual host file. Do that by running the following commands

First enable the file with the **a2ensite **command

sudo a2ensite demo.com.conf
Enter fullscreen mode Exit fullscreen mode

Then disable the default configuration file

sudo a2dissite 000-default.conf
Enter fullscreen mode Exit fullscreen mode

Check for configuration errors using the following command:

sudo apache2ctl configtest
Enter fullscreen mode Exit fullscreen mode

The output of that command should be “ Syntax OK” to indicate that it is properly configured

Restart the Apache server to implement the changes

sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

Congrats! Your website is now hosted on your machine. To view the website navigate to http://demo.com

apache Article's
30 articles in total
Favicon
Power Up Your AWS Game: Create EC2 Instances, Install Apache, and Connect with PowerShell
Favicon
AutoMQ: A Revolutionary Cloud-First Alternative to Kafka
Favicon
Laravel 11: Allowed memory size of 134217728 bytes exhausted (tried to allocate 23085056 bytes)
Favicon
Seamlessly Migrate PostgreSQL to YugabyteDB in Minutes!
Favicon
Apache Log Parser and Data Normalization Application
Favicon
Unlock 10% Discounts in 5 Minutes: Build a Drools Project with Maven
Favicon
[pt-BR] Como criei minha prĂłpria imagem Docker do Apache Benchmark para testes de stress em servidores web
Favicon
What Goes Into a Major OSS Release? A CouchDB Story
Favicon
Monitor Apache Ignite in 5 Minutes: Fix Cluster Issues Fast!
Favicon
Mastering Data Routing in Apache Camel: Leveraging the Splitter Pattern
Favicon
Exploring Core Features and Components of Apache Camel
Favicon
Practical Guide to Apache Camel with Quarkus: Building an ETL Application
Favicon
Implementation of Missing Security Header Vulnerability in Apache (Part 2)
Favicon
Join Apache Answer at CommunityOverCode Asia 2024
Favicon
Implementation of Missing Security Header Vulnerability in Apache (Part 1)
Favicon
Installing Apache, PHP, and MySQL on Oracle Linux 8
Favicon
Install LEMP LAMP LLMP LEPP LAPP or LLPP using parameters only
Favicon
Deploying an Application Using Apache as a Web Server
Favicon
My first experience with the LAMP stack
Favicon
Shades of Open Source - Understanding The Many Meanings of "Open"
Favicon
Updating the solr client(org.apache.solr.solr-core) from 8.11.2 to 9.6.0
Favicon
Automating the installation of a LAMP stack on Ubuntu 22.04
Favicon
How to setup an Apache server on Ubuntu 22.04.4 LTS with Virtual hosting
Favicon
Build a Safe and Respectful Community with Answer 1.3.1
Favicon
Apache Spark 101
Favicon
Apply for Apache Answer’s Project at OSPP 2024
Favicon
Understanding Kappa Architecture and Kafka: Empowering Real-Time Data Processing
Favicon
Run Laravel locally on Ubuntu using Apache virtual host
Favicon
Deploy Sendy on AWS EC2 with Apache in Ubuntu
Favicon
Docker LAMP Stack With Composer PSR-4 Autoloading – Apache Server

Featured ones: