pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

HOW TO CONFIGURE VIRTUALHOSTS WITH APACHE IN WINDOWS (IN 2 STEPS)

When working with Apache on Windows, the most usual is to use WampServer or Xampp.

These “packages” allow us to install Apache, MySQL and PHP in a single pass.

And the result is as follows:

Our projects will be saved in a certain folder (usually wwww in Wamp and htdocs folder of Xamp).
We can access our projects by visiting the local host.
What we are going to configure now will allow us to access our projects from different directions.

This is very useful for Laravel projects, because it allows us to access our projects using my-project.localhost instead of localhost/my-project/public (this way we can avoid the use of php artisan serv and use Apache as server).

Configuration in 2 steps
The configuration that we are going to make consists of 2 steps.

First we are going to tell our operating system that when looking for the address localhost subdirectory of the folder, resolve this request through our local server (and do not search this page publicly on the Internet, as normally happens).

Then we’ll tell Apache how to resolve an incoming request for my-project.localhost (since Apache usually doesn’t know how to react to it).
File hosts and Virtual hosts
I know you’re eager to do the setup now.

As the title of the article says, it’s simply 2 steps.

If you’re in a hurry, you can skip this section. However, I recommend you continue reading.

Step 1

Hosts file

Every operating system presents a hosts file, to save the correspondence between Internet domains and IP addresses.
The location of this file depends on the operating system.
We will modify this file in step 1.
Virtual hosts

The creation of virtual hosts (or VirtualHosts) allows the same computer to resolve multiple domain names.
In our case we are going to tell Apache to resolve certain addresses through our local IP.
We will do this in step 2.
VirtualHosts are useful in different scenarios.

In this case, we will use them to configure our local development environment.

Well, let’s get started.

On Windows, the hosts file is located at hosts subdirectory within the drivers folder in System32.

This file allows us to map host names with IP addresses.

A default hosts file usually includes only the following definition:

Here you can add as many addresses as you need. I’ll give you an example for now.

I’m currently developing an application that will probably be available from tawa.com.pe. Locally I can use localhost of tawa.

The important thing is to use a domain name that doesn’t exist (and can’t exist in the future) in order to avoid collisions.


Step 2


If so far I access tawa.dev.pe from the browser, Apache will resolve this as if it were localhost.

This is because we have not yet created a VirtualHost to serve this address. Let’s get on with it.

Apache has a configuration file. You must open this file.

In the case of Wamp it is located in the httpd.conf subdirectory of the apache2.4.23 folder. (if you’re looking at this article from the future, the version might change)
We can create Virtual hosts directly on this file. But not. Apache usually includes other configuration files on top of this main file to keep an order.

Within this file we find the following lines:

Virtual hosts

Include the httpd-vhosts.conf file extension in your window. This is necessary to make the local hosts virtual declaration.

This will help you get the virtual host up and running. The process is very straightforward, so you shouldn’t have to dedicate too much time to it.

Filed Under: Articles

Latest Articles

Cable Modems – for cable Internet connections

Cable modems offer the prospect of fast and affordable Internet access by leveraging existing broadband cable TV networks. The technology is more applicable to home than business users since it is residential areas that are more likely to be wired for cable. The devices, manufactured by such … [Read More...]

Top Computer Privacy Issues You Need to Know

The internet impacts every aspect of your life, irrespective of which part of the world you are in. Whether you're scouting for information for your research project or looking to order fresh vegetables, you’ll find it all on the internet. However, not everything is as great as it seems. Malware … [Read More...]

Tape Storage Compatibility

In its early days, some MO disks were proprietary. Nowadays both the 3.5in and 5.25in disk types are governed by ISO standards and any compliant disk will work in any MO drive - providing the drive is compatible with that capacity. … [Read More...]

A Harsh Reality You Can’t Ignore About Network Information Security

We are becoming more and more connected to our lives with computer technology. They help to process data at work. We receive money using plastic … [Read More...]

What is the Best VPN for Gamers?

Of the 44% of UK Internet users who have used a virtual private network (VPN) at some point in their lives, approximately 39% of this demographic are … [Read More...]

Think About Headless Commerce as of a Modular System

In recent years, eCommerce has transformed to where consumers no longer handle purchases on conventional websites. Shopping is currently carried out … [Read More...]

Service That Succeeds: How To Build an Effective IT Service Desk

In today’s tech-forward world, building a capable IT service team is essential for businesses hoping to scale tech-related hurdles and soar past the … [Read More...]

A simple PC guide on keeping safe while using public Wi-Fi

Did you know that there is a cyberattack every 39 seconds? You are more likely to be a victim if you are lax about your digital security. This … [Read More...]

Motivating Students to Learn Computer Science

Computer science has been an important part of the educational curriculum for decades. Professor Seymour Papert, a mathematician from South Africa … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

Inkjet Paper and Ink

The ink used in inkjet technology is water-based, which poses certain problems. The results from some of the early … [Read More...]

LP to CD Equipment

The following equipment will be needed to produce a signal capable of being digitised in your PC: a turntable and pickup arm fitted with a good … [Read More...]

Registry Reviver Review

PROS: Installation is easy; it practically installs all on its own. CONS: Registry Reviver isn’t the most comprehensive or extensive registry … [Read More...]

[footer_backtotop]

Copyright © 2022 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors