WAMP Virtual Hosts

Setting Up Overall Structure

Keep localhost homepage in default location on C drive. Set up all websites to be virtual hosts that you configure from the localhost homepage which will be the name of website ending in .local.

Update httpd-vhosts.conf to make files.local URL point to the D drive. This will make WordPress sites work when the database is not updated with new domain. Add this code to the file:

<VirtualHost *:80>
   DocumentRoot "d:/sites"
   ServerName files.local
   <Directory "/">
      AllowOverride All
      Require local
      Allow from All
      Require local
   </Directory>
</VirtualHost>

Add an htaccess to C:\wamp64\www so that all localhost links except the homepage rewrite to files.local which points to D drive

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://files.local/$1 [L]

Setting Up HTTPS

  1. Download and Install OpenSSL
    OpenSSL is available in both 32 and 64 bit. Make sure you select the correct installer for your version of Windows. You can find the latest version of OpenSSL here https://slproweb.com/products/Win32OpenSSL.html. Navigate to your downloads folder and double click the installer. When Installing OpenSSL leave all settings default.
  2. Create Your Key and Certificate
    Open your start menu and Load Command Prompt as an Administrator and run the following commands.

    First, we will need to change our directory to where we installed OpenSSL.
    cd D:\Program Files\OpenSSL-Win64\bin

    Next, we will create our private key. You will be asked for a passphrase. Make it anything you want just make sure you remember it for the next step.
    openssl genrsa -aes256 -out private.key 2048
    openssl rsa -in private.key -out private.key

    Next, we will create our certificate. You will be asked several questions on this step. You can put whatever you like or just hit enter to leave it at default. The only one that really matters is Common Name (e.g. server FQDN) you will need to type “localhost” for this.
    openssl req -new -x509 -nodes -sha1 -key private.key -out certificate.crt -days 36500
  3. Move your Key and Certificate
    Create a folder named “key” in the C:\wamp64\bin\apache\apache2.4.23\conf directory.

    Navigate to c:/program files/openssl-win64/bin/ to find the certificate.crt and private.key that you just created. Both of these need to be moved to the new folder c:/wamp64/bin/apache/apache2.4.41/conf/key/.
  4. Edit Your httpd.conf File
    Open c:/wamp64/bin/apache/apache2.4.23/conf/httpd.conf and un-comment (remove the #) the following 3 lines:
    LoadModule ssl_module modules/mod_ssl.so
    Include conf/extra/httpd-ssl.conf
    LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
  5. Edit Your httpd-ssl.conf File
    Open up C:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-ssl.conf and replace content with:
Listen 443

DocumentRoot "c:/wamp64/www"
ServerName localhost:443
ServerAdmin info@christinewilson.ca
SSLSessionCache "shmcb:${SRVROOT}/logs/ssl_scache(512000)"
ErrorLog "${SRVROOT}/logs/error.log"
TransferLog "${SRVROOT}/logs/access.log"
SSLCertificateFile "${SRVROOT}/conf/key/certificate.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/key/private.key"

<VirtualHost localhost:443>

	DocumentRoot "c:/wamp64/www"
	ServerName localhost:443
	ServerAlias localhost
	ServerAdmin info@christinewilson.ca
	ErrorLog "${SRVROOT}/logs/error.log"
	TransferLog "${SRVROOT}/logs/access.log"

	SSLEngine on
	SSLCertificateFile "${SRVROOT}/conf/key/certificate.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/key/private.key"

	<FilesMatch "\.(cgi|shtml|phtml|php)$">
		SSLOptions +StdEnvVars
	</FilesMatch>

	<Directory "d:/sites">
		SSLOptions +StdEnvVars
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		Require all granted
		AllowOverride All
	</Directory>

	BrowserMatch "MSIE [2-5]" \
			 nokeepalive ssl-unclean-shutdown \
			 downgrade-1.0 force-response-1.0

	CustomLog "${SRVROOT}/logs/ssl_request.log" \
			  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

<VirtualHost files.local:443>
 
	DocumentRoot "d:/sites"
	ServerName files.local:443
	ServerAlias files.local
	ServerAdmin info@christinewilson.ca
	ErrorLog "${SRVROOT}/logs/error.log"
	TransferLog "${SRVROOT}/logs/access.log"

	SSLEngine on
	SSLCertificateFile "${SRVROOT}/conf/key/certificate.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/key/private.key"

	<FilesMatch "\.(cgi|shtml|phtml|php)$">
		SSLOptions +StdEnvVars
	</FilesMatch>

	<Directory "d:/sites">
		SSLOptions +StdEnvVars
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		Require all granted
		AllowOverride All
	</Directory>

	BrowserMatch "MSIE [2-5]" \
			 nokeepalive ssl-unclean-shutdown \
			 downgrade-1.0 force-response-1.0

	CustomLog "${SRVROOT}/logs/ssl_request.log" \
			  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

Adding New Websites

Open hosts file in C:\Windows\System32\drivers\etc\hosts to point new domain name to localhost:

127.0.0.1	mongooseandmink.local

Add Virtual Host on localhost homepage for http.

Add Virtual Host on https by opening up C:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-ssl.conf and add:

<VirtualHost mongooseandmink.local:443>
 
	DocumentRoot "D:/sites/ouioui"
	ServerName mongooseandmink.local:443
	ServerAlias mongooseandmink.local
	ServerAdmin info@christinewilson.ca
	ErrorLog "${SRVROOT}/logs/error.log"
	TransferLog "${SRVROOT}/logs/access.log"

	SSLEngine on
	SSLCertificateFile "${SRVROOT}/conf/key/certificate.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/key/private.key"

	<FilesMatch "\.(cgi|shtml|phtml|php)$">
		SSLOptions +StdEnvVars
	</FilesMatch>

	<Directory "D:/sites/ouioui">
		SSLOptions +StdEnvVars
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		Require all granted
		AllowOverride All
	</Directory>

	BrowserMatch "MSIE [2-5]" \
			 nokeepalive ssl-unclean-shutdown \
			 downgrade-1.0 force-response-1.0

	CustomLog "${SRVROOT}/logs/ssl_request.log" \
			  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

Websites with Old WordPress Database

For WordPress websites with old database (URL is localhost still), Update the htaccess to remove the folder

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /ouioui/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ouioui/index.php [L]
</IfModule>

Update wp-config file to use new domain name:

define( 'WP_HOME', 'http://mongooseandmink.local/' );
define( 'WP_SITEURL', 'http://mongooseandmink.local/' );