{"id":4215,"date":"2017-09-05T15:42:54","date_gmt":"2017-09-05T13:42:54","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=4215"},"modified":"2020-02-09T10:59:44","modified_gmt":"2020-02-09T09:59:44","slug":"https-virtual-hosts-xampp","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/https-virtual-hosts-xampp-4215\/","title":{"rendered":"HTTPS with virtual hosts on XAMPP"},"content":{"rendered":"\n<p>Until now, I never used HTTPS for local development domains. Now I had to use it for a project, and here is how to get it working on XAMPP with virtual hosts.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"update-box\">\n<p><strong>Update from May 31, 2018:<\/strong> Before the update, I described the creation of an SSL certificate as the first necessary step before setting up the virtual host. But your browser will display a warning regardless if there is a self-created cert or not, so I removed this part. You need to add your local site as an exception to not get the warning every time.<\/p>\n<p><strong>Update from June 1, 2018:<\/strong> Seems that you need the cert file, otherwise apache will not start, so I added this part back to the post.<\/p>\n<\/div>\n\n\n\n<p>Two steps are necessary for the solution:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Creating an SSL certificate.<\/li><li>Set up the virtual host.<\/li><\/ol>\n\n\n\n<p>The requirement is (of course) XAMPP.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating an SSL certificate<\/h2>\n\n\n\n<p>A good tutorial about creating a cert is on <a href=\"http:\/\/robsnotebook.com\/xampp-ssl-encrypt-passwords\">robsnotebook.com<\/a>. It is from 2007, but works. To create a certificate, you can follow these steps on the command line:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Go to the Apache directory <code class=\"lang-markup\">C:\\xampp\\apache<\/code>.<\/li><li>Run <code class=\"lang-bash\">makecert<\/code>.<\/li><li>Enter a PEM passphrase and the other information you are asked for. For <em>Common Name<\/em>, you should enter the domain you want to use for the virtual host, so the certificate is signed for that domain.<\/li><li>After processing all steps, you maybe want to import the cert into your browser (it lives under <code class=\"lang-markup\">C:\/xampp\/apache\/conf\/ssl.crt\/server.crt<\/code>). Nevertheless, you will get a warning about insecure self-signed certificate after loading your website \u2013 you need to add it as an exception.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Set up virtual host with HTTPS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Entry in the Windows hosts file<\/h3>\n\n\n\n<p>To let Windows know, for example, that the domain <code class=\"lang-markup\">florianbrinkmann.test<\/code> should point to the IP address <code class=\"lang-markup\">127.0.0.1<\/code> (localhost), we have to insert an entry in the Windows <code class=\"lang-markup\">hosts<\/code> file. The file can be found in <code class=\"lang-markup\">C:\\Windows\\System32\\drivers\\etc<\/code>. To edit it, you need admin privileges (search for the editor in Windows, right-click on it and choose <em>Run as administrator<\/em>).<\/p>\n\n\n\n<p>At the end of the <code class=\"lang-markup\">hosts<\/code> file, add an entry with the following pattern:<\/p>\n\n\n<pre class=\"wp-block-code lang-markup\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">127<span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.1<\/span> <span class=\"hljs-selector-tag\">florianbrinkmann<\/span><span class=\"hljs-selector-class\">.test<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You have to replace the domain with your own development domain. Afterwards, you can save and close the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the Virtual Host in Apache<\/h3>\n\n\n\n<p>The virtual hosts in Apache can be found in the <code class=\"lang-markup\">C:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf<\/code> file. Open the file and insert an entry according to the following pattern (an answer from <a href=\"https:\/\/stackoverflow.com\/a\/16761330\/7774451\">stackoverflow.com<\/a> was very helpful \u2013 the related question also, it brought me to the article on SSL certificate setup):<\/p>\n\n\n<pre class=\"wp-block-code lang-markup\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">VirtualHost<\/span> <span class=\"hljs-attr\">florianbrinkmann.test:80<\/span>&gt;<\/span>\n\tDocumentRoot \"C:\\xampp\\htdocs\\florianbrinkmann.test\"\n\tServerName florianbrinkmann.test\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Directory<\/span> \"<span class=\"hljs-attr\">C:<\/span>\\<span class=\"hljs-attr\">xampp<\/span>\\<span class=\"hljs-attr\">htdocs<\/span>\\<span class=\"hljs-attr\">florianbrinkmann.test<\/span>\"&gt;<\/span>\n\tOrder allow,deny\n\tAllow from all\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Directory<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">VirtualHost<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">VirtualHost<\/span> <span class=\"hljs-attr\">florianbrinkmann.test:443<\/span>&gt;<\/span>\n\tDocumentRoot \"C:\\xampp\\htdocs\\florianbrinkmann.test\"\n\tServerName florianbrinkmann.test\n\tSSLEngine On\n\tSSLCertificateFile \"C:\/xampp\/apache\/conf\/ssl.crt\/server.crt\"\n\tSSLCertificateKeyFile \"C:\/xampp\/apache\/conf\/ssl.key\/server.key\"\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Directory<\/span> \"<span class=\"hljs-attr\">C:<\/span>\\<span class=\"hljs-attr\">xampp<\/span>\\<span class=\"hljs-attr\">htdocs<\/span>\\<span class=\"hljs-attr\">florianbrinkmann.test<\/span>\"&gt;<\/span>\n\tOrder allow,deny\n\tAllow from all\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Directory<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">VirtualHost<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here you have to adjust the settings for <code class=\"lang-markup\">DocumentRoot<\/code>, <code class=\"lang-markup\">ServerName<\/code>, <code class=\"lang-markup\">Directory<\/code>, and the domain in the <code class=\"lang-markup\">VirtualHost<\/code> element. The first <code class=\"lang-markup\">VirtualHost<\/code> is for HTTP connections, the second for HTTPS connections.<\/p>\n\n\n\n<p>Maybe you have to uncomment the following line in the <code class=\"lang-markup\">C:\\xampp\\apache\\conf\\httpd.conf<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code lang-markup\"><span><code class=\"hljs\">LoadModule ssl_module modules\/mod_ssl.so<\/code><\/span><\/pre>\n\n\n<p>Now you can restart Apache and open your site with HTTPS (including browser warning\u2026).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Until now, I never used HTTPS for local development domains. Now I had to use it for a project, and here is how to get it working on XAMPP with virtual hosts.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4215","post","type-post","status-publish","format-standard","hentry","category-tips"],"wp-worthy-pixel":{"ignored":false,"public":"687797c2f5b449c08e02c5174c6a5541","server":"vg07.met.vgwort.de","url":"https:\/\/vg07.met.vgwort.de\/na\/687797c2f5b449c08e02c5174c6a5541"},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/4215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=4215"}],"version-history":[{"count":6,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/4215\/revisions"}],"predecessor-version":[{"id":5852,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/4215\/revisions\/5852"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=4215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=4215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=4215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}