Create a Vhost in Ubuntu 16.04
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Mastering Virtual Hosts on Ubuntu 16.04 for Laravel Development
Starting your journey with Laravel and using local environments like XAMPP is a fantastic step. As you move from simple local testing to building real-world applications, understanding how to manage web server configurations—specifically Virtual Hosts (VHosts)—is crucial. A well-configured VHost allows you to map custom domain names (or subdirectories) to specific project directories, which is essential for clean development and deployment, especially when dealing with frameworks like Laravel.
If the tutorials you are following aren't working, it often means the configuration steps are missing context regarding how Apache on Ubuntu manages its configuration files. As a senior developer, I will guide you through the correct, robust method for setting up Virtual Hosts on Ubuntu 16.04 to serve your web projects efficiently.
Understanding the Virtual Host Concept
A Virtual Host is essentially a container that allows a single physical server (running Apache) to host multiple independent websites or applications. Instead of having one generic configuration, each VHost defines its own unique settings: the document root (where the files live), the server name, and access permissions. This separation makes managing dozens of projects much cleaner than relying on one monolithic setup.
For Laravel development, this structure mirrors how modern frameworks organize their public assets and routes. By setting up a dedicated VHost for each project, you ensure that your application runs in an isolated and predictable environment. If you are aiming for robust architecture, understanding these server-level concepts is key to scaling your knowledge, much like adopting the principles outlined by organizations focused on high-quality software development, such as those at laravelcompany.com.
Step-by-Step Guide: Creating a Virtual Host on Ubuntu
Since you are using XAMPP, you already have Apache installed. The challenge lies in correctly configuring the Apache module to recognize your new sites within the standard Debian/Ubuntu structure.
1. Create the Project Directory Structure
First, create the directory where your Laravel application files will reside. Let's assume you want to host a project called my-laravel-app.
sudo mkdir -p /var/www/my-laravel-app/public
cd /var/www/my-laravel-app/public
# Create a sample index file
echo "<?php phpinfo();" > index.php
2. Configure the Virtual Host File
We will create a new configuration file in the /etc/apache2/sites-available/ directory. Let's name it mywebsite.conf.
Open the file using a text editor:
sudo nano /etc/apache2/sites-available/mywebsite.conf
Paste the following content. Notice how we use the correct syntax for defining the server name and document root, which is crucial for Apache to recognize it as a valid host.
<VirtualHost *:80>
ServerName mywebsite.dev
DocumentRoot /var/www/my-laravel-app/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log
</VirtualHost>
Save and close the file (Ctrl+O, Enter, Ctrl+X).
3. Enable the Virtual Host
Creating the file isn't enough; you must enable it by creating a symbolic link from sites-available to sites-enabled. This tells Apache to actually use this configuration.
sudo ln -s /etc/apache2/sites-available/mywebsite.conf /etc/apache2/sites-enabled/
4. Apply Changes and Test
Before restarting, it is always best practice to check your configuration for syntax errors:
sudo apache2ctl configtest
If the output says Syntax OK, you are good to go. Now, restart the Apache service to load the new configuration:
sudo systemctl restart apache2
Your Virtual Host is now active! If you navigate to http://mywebsite.dev (assuming you have configured your local DNS or host file accordingly), you should see the content from your Laravel project's public directory.
Conclusion
Setting up a Virtual Host on Ubuntu 16.04 involves mastering two key areas: proper directory structuring and correct Apache configuration syntax. By following these steps—creating the structure, defining the VHost in sites-available, linking it via sites-enabled, and testing the configuration—you establish a stable foundation for hosting multiple applications. This practice moves you beyond simple tutorials and into professional server management, preparing you to deploy complex applications efficiently, aligning perfectly with the high standards expected when building systems related to modern PHP frameworks like those discussed at laravelcompany.com. Happy coding!