How to Create Virtual Host in Ubuntu 22.04?
Hello Friends,
Now, let's see an example of how to create virtual host in ubuntu 22.04. you can see how to create virtual host in ubuntu 20.04. we will help you to give an example of ubuntu 22.04 create virtual host. This article will gaive you a simple example of how to create virtual host in ubuntu 20.04.
Creating a virtual host in Ubuntu 22.04 involves configuring the Apache web server to host multiple websites on a single server. Here's a step-by-step guide to creating a virtual host:
Follow the following steps to create a virtual host in the Ubuntu 22.04 system.
Step 1: Install Apache (if not already installed)
Run the following command to install apache2 server.
sudo apt update
sudo apt install apache2
Step 2: Create a new directory for your website files
Here, we will create "example.test" directory.
sudo mkdir /var/www/html/example.test
Replace "example.test" with your domain or preferred website name.
Step 3: Set appropriate permissions for the directory
run following command to setup folder permission:
sudo chown -R $USER:$USER /var/www/html/example.test
sudo chmod -R 755 /var/www/html
Step 4: Create a simple HTML file for testing purposes (optional)
Here, we will create simple "index.html" file with "hello world" test. so, run the below command:
echo "<html><head><title>My Website</title></head><body><h1>Hello, World!</h1></body></html>" | sudo tee /var/www/html/example.test/index.html
Step 5: Create a virtual host configuration file
Run the below command to configure apache file.
sudo nano /etc/apache2/sites-available/example.test.conf
Replace "example.test" with your domain or preferred website name, and paste the following configuration:
<VirtualHost *:80>
ServerAdmin webmaster@example.test
ServerName example.test
DocumentRoot /var/www/html/example.test
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/example.test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Step 6: Enable the virtual host
Run the below command to enable virtual host.
sudo a2ensite example.test.conf
Step 7: Restart Apache to apply the changes
run the below command to restart apache2 server.
sudo systemctl restart apache2
Step 8: Update the hosts file (if testing on a local machine)
add host entry by following command:
sudo nano /etc/hosts
Add the following line:
127.0.0.1 example.test
Replace "example.test" with the domain you specified in your virtual host configuration.
Open a web browser and navigate to your virtual host
http://example.test
Replace "example.test" with your domain or server IP address.
Your virtual host should now be accessible, and you can customize the content in the `/var/www/html/example.test` directory to host your website files.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Delete File in Ubuntu 22.04?
- How to Change Root Password in Ubuntu 22.04?
- How to Zip & Unzip Files in Ubuntu 22.04 Terminal?
- How to Restart Apache2 in Ubuntu 22.04?
- How to Install and Setup Supervisor in Ubuntu for Laravel?
- How to Upgrade from Ubuntu 20.04 LTS to Ubuntu 22.04 LTS?
- How to Increase post_max_size in PHP Ubuntu?
- Ubuntu Skype Screen Sharing Not Working - Solved
- How to Install Laravel in Ubuntu Server?
- How to Install Apache PHP MySQL and Phpmyadmin on Ubuntu?
- How to Install PHP in Ubuntu Server?
- How to Enable Apache mod_rewrite Module in Ubuntu?
- How to Downgrade php 7.4 to 7.3 Ubuntu?
- How to create quick apache virtual host in Ubuntu?