Apache Virtual Host Setup
Understand how to set up Apache virtual hosts to run multiple local websites each with its own domain name. Learn to configure the httpd-vhosts.conf file, update your system hosts file, and enable virtual hosting in Apache to mirror production setups. This lesson helps you create a more accurate local development environment for PHP applications.
We'll cover the following...
Setting up a web server like Apache gives us only one domain, which is http://localhost. This domain is associated with the 127.0.0.1 IP address.
One host per server —localhost
As we stated above, we are only allowed to have on the website by a web server. To get around this limitation, we’ll create different directories, each for one website on the localhost:
http://localhost/time-tracker
http://localhost/smartsapp
We have two directories in http://localhost. We can add as many as we want.
Although this solution is helpful it has its own issues as well:
- It does not reflect the reality of the production server, where each site has its own domain (
http://time-tracker.com). - We may encounter issues with relative paths.
To avoid issues in a production server, it would be better if we have a local ...