![virtual host apache ubuntu 22.04](https://me.gersonhernandez.net/wp-content/uploads/2024/06/Vhost-Apache-Ubuntu-22.04.webp)
12
Jun
Create Virtual Host Apache 2 on Ubuntu 22.04
Expanding your web server to host multiple sites on Apache is a common need, especially during development or when managing several projects. Using Apache’s Virtual Host feature, you can easily set up multiple websites on a single server. In this guide, we’ll walk through the process of configuring a new virtual host on Apache for hosting a site called “mysite” on Ubuntu.
Create a Configuration File
Let’s create a new configuration file for our site “mysite”. Open a terminal and use your preferred text editor to create and edit the file:
sudo nano /etc/apache2/sites-available/mysite.conf
Paste the following configuration into the file:
<VirtualHost *:80> ServerAdmin gersonhernandez93@hotmail.com DocumentRoot /var/www/html/mysite/ ServerName mysite.localhost ServerAlias mysite.localhost <Directory /var/www/html/mysite/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
This configuration sets up a new virtual host listening on port 80 with the specified server name and document root.
Enable the Site
After creating the configuration file, we need to enable the site using the a2ensite
command:
sudo a2ensite mysite
Restart Apache
To apply the changes, restart Apache:
sudo service apache2 restart
Test the Site
Open your web browser and navigate to http://mysite.localhost
. If everything is configured correctly, you should see your website served from the specified document root.
Conclusion
By following these steps, you can easily set up and manage multiple sites on your Apache web server. Feel free to repeat these steps to add more virtual hosts for additional websites.
If you encounter any issues or have any questions, don’t hesitate to ask in the comments below. Happy hosting!
Author
I'm a web developer with eight years of experience and a proud graduate of the Universidad Tecnológica de El Salvador, where I earned my degree in Computer Science. Specializing in PHP, WordPress, Laravel, and Magento, I've channeled my passion for technology into crafting innovative and functional web solutions.