Development teams running Drupal 8 on a local web server often choose WampServer for programming and development. For WampServer to work correctly when executing local file in the browser, you need to edit the Windows hosts file and WampServer Virtual Hosts file.
If you’ve set up a local WampServer environment to run Drupal 8 websites and want to set up a Virtual Host file, then this article is for you. For this tutorial, we work on Windows system.
Step-by-Step Process
Here are the steps you need to follow:
Install WampServer
If you haven’t already, you need to download and install WampServer locally. It’s recommended that you install the latest version for best compatibility. So download it from SourceForge or project homepage. While doing so, ensure that it is installed on the local environment.
The most recent version of WampServer has support for databases like PostgreSQL, MySQL, and MariaDB. Along with that, it comes pre-installed with PHP 7.x.
Build the Local Development Environment
The next step is to build the development environment locally. The WampServer Installation Guide has detailed information on how to build a Drupal 8 website from scratch. You may follow that.
In this tutorial, we want the website files to be installed in the C:wampwww folder. Then name each website differently. For this tutorial, we have the folders named as www.site1.com, www.site2.com, www.site3.com, and so on.
As per your requirements, you need to install scripts into these folder. So download Drupal, WordPress, Magento frameworks if you need and place into these folders.
Edit WampServer Virtual Host File
Next step is to edit the WampServer Virtual Host or Vhost files. This is also the first step to configure the WampServer environment for running Drupal 8 websites with version control utilities.
You can find the Vhost files at -
Open the file and add the following:
It is the Virtual Host definition for /www.
Then, you need to add the following code for every folder in C:wampwww:
Save the respective files. Also remember to update them accordingly as and when necessary or when you add new websites.
Edit Local Windows Host File
Next, you need to work on the Windows Host file. You need to add the codes for correct URL routing. To locate this file, navigate to - C:windowssystem32driversetchosts
Then open the file (without extension) and copy and paste this code into it:
Save the changes made. When saving, ensure that it doesn’t have extension like .txt or .php. Or else, it will not work properly as a Windows system file.
Then, open your Command Prompt in Windows and execute these commands:
Running those commands will reload DNS cache and apply the new settings for the WampServer. Then, restart WampServer to complete the configuration part.
Edit httpd.conf File
The final step is to edit the httpd.conf file. So locate the projects in WampServer administration menus and then this file in Apache Web Server.
You can use this code to find httpd.conf file:
You have to uncomment #before #include. Save the changes and restart WampServer. This will set the required configuration.
So that’s how you set up a Virtual Host FIle on WampServer. For more assistance, get in touch with the customer support team.
If you’ve set up a local WampServer environment to run Drupal 8 websites and want to set up a Virtual Host file, then this article is for you. For this tutorial, we work on Windows system.
Step-by-Step Process
Here are the steps you need to follow:
Install WampServer
If you haven’t already, you need to download and install WampServer locally. It’s recommended that you install the latest version for best compatibility. So download it from SourceForge or project homepage. While doing so, ensure that it is installed on the local environment.
The most recent version of WampServer has support for databases like PostgreSQL, MySQL, and MariaDB. Along with that, it comes pre-installed with PHP 7.x.
Build the Local Development Environment
The next step is to build the development environment locally. The WampServer Installation Guide has detailed information on how to build a Drupal 8 website from scratch. You may follow that.
In this tutorial, we want the website files to be installed in the C:wampwww folder. Then name each website differently. For this tutorial, we have the folders named as www.site1.com, www.site2.com, www.site3.com, and so on.
As per your requirements, you need to install scripts into these folder. So download Drupal, WordPress, Magento frameworks if you need and place into these folders.
Edit WampServer Virtual Host File
Next step is to edit the WampServer Virtual Host or Vhost files. This is also the first step to configure the WampServer environment for running Drupal 8 websites with version control utilities.
You can find the Vhost files at -
Code:
wampbinapacheapache2.4.9confextrahttpd-vhosts.conf
Code:
<VirtualHost *:80>
DocumentRoot"c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverrideAll
Require local
</Directory>
</VirtualHost>
Then, you need to add the following code for every folder in C:wampwww:
Code:
<VirtualHost *:80>
DocumentRoot"c:/wamp/www/www.site1.com"
ServerName project1
<Directory "c:/wamp/www/www.site1.com">
AllowOverrideAll
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot"c:/wamp/www/www.site2.com"
ServerName project1
<Directory "c:/wamp/www/www.site2.com">
AllowOverrideAll
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot"c:/wamp/www/www.site3.com"
ServerName project1
<Directory "c:/wamp/www/www.site3.com">
AllowOverrideAll
Require local
</Directory>
</VirtualHost>
Edit Local Windows Host File
Next, you need to work on the Windows Host file. You need to add the codes for correct URL routing. To locate this file, navigate to - C:windowssystem32driversetchosts
Then open the file (without extension) and copy and paste this code into it:
Code:
127.0.0.1localhost
127.0.0.1www.site1.com
127.0.0.1www.site2.com
127.0.0.1www.site3.com
::1 localhost
::1 www.site1.com
::1 www.site2.com
::1 www.site3.com
Then, open your Command Prompt in Windows and execute these commands:
Code:
net stop dnscache
netstart dnscache
Edit httpd.conf File
The final step is to edit the httpd.conf file. So locate the projects in WampServer administration menus and then this file in Apache Web Server.
You can use this code to find httpd.conf file:
Code:
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
So that’s how you set up a Virtual Host FIle on WampServer. For more assistance, get in touch with the customer support team.