If you go to the Apache Lounge website you can locate pre-compiled versions of Apache for Windows (or you can try to compile it yourself but that’s another topic altogether). We are looking for a 64bit Windows version and they have version 2.4.46 conveniently located there for download. In this case, it was named httpd-2.4.46-win64-VS16.zip. Right-click on it and extract the files to your C:\ directory. I suggest reviewing the readme.txt file and moving the Apache24 folder to C:\Apache24.
In your text editor, open C:\Apache\conf\httpd.conf and change these lines:
#ServerName www.example.com:80 change to (uncomment) ServerName 127.0.0.1
#Include conf/extra/httpd-vhosts.conf change to (uncomment) Include conf/extra/httpd-vhosts.conf
<IfModule dir_module> DirectoryIndex index.html change to </IfModule> <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> change to
Apache is started with http.exe executable in C:\apache24\bin. If you run that you may get a VCRuntime error. That just means Apache needs Visual C to run. You can download and install that from Microsoft here.
You will also get this annoying error even if you run httpd.exe as Administrator. To disable that go to the Windows Start Menu and type gpedit. Go to Computer Configuration->Administrative Templates->Windows Components->File Explorer. Click on Configure Windows Defender SmartScreen. Set it to disabled and save the change.
The first time you successfully run Apache (http.exe) you will get a firewall warning. Enable the Firewall for private networks. You can now go to your browser and type in localhost as the address. You should get a blank screen saying It Works! Awesome, Apache has been installed!
At this point, you may want to install Apache a Windows Service by entering these command lines at an Administrator Command prompt (Start Menu, type cmd, right-click saying run as Administrator). Once Apache is running smoothly you will want to control Apache using ApacheMonitor located in C:\Apache\bin\ApacheMonitor.exe. The advantage of running apache from a command prompt using httpd.exe is that you will get to see error messages clearly.
cd\apache24 bin\httpd -k install
We should mimic your Host provider at this point and make a folder in C:\Apache24\htdocs\ called public_html if this is your primary site. If it is an add-on domain we would make a folder called example.com. In there, create a text file named index.php and add this info:
<html><body>My new example.com site works!!!</body></html>
Edit C:\Apache24\conf\extra\httpd-vhosts.conf. Comment out any existing virtual hosts with #‘s (every line in the virtual host sections) and add:
<VirtualHost *:80> ServerName example.com ServerAlias example.com *.example.com DocumentRoot "c:/apache24/htdocs/public_html" <Directory "c:/apache24/htdocs/public_html"> </Directory> ServerAdmin email@example.com ErrorLog "logs/example.com-error.log" CustomLog "logs/example.com-access.log" common </VirtualHost>
Start C:\Apache\bin\httpd.exe server and type localhost in your browser. You should get a line saying My new example.com site works!!! If you aren’t installing an HTTPS/SSL server, you can stop here and move onto PHP and MySQL.
Setting up Apache for SSL/HTTPS
There are a lot of ways to do this, and it can be quite frustrating depending on what path you decide to take. This method works for me. Open C:\Apache24\conf\httpd.conf in your text editor. Change the following lines:
#LoadModule ssl_module modules/mod_ssl.so Remove Comment LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf Remove Comment Include conf/extra/httpd-ssl.conf
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so Remove Comment LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
Using your text editor make a batch file in C:\Apache24 called makecert.bat. Edit the file adding the line:
bin\openssl req -x509 -sha256 -newkey rsa:2048 -keyout conf\server.key -out conf\server.crt -days 999 -nodes -subj "/CN=www.example.com" -addext "subjectAltName=DNS:www.example.com" -config example.cnf
Make another file called example.cnf and add the following. You can change the C, ST, L, O, OU values to anything you want- they aren’t important.
[req] distinguished_name = req_distinguished_name x509_extensions = v3_req prompt = no [req_distinguished_name] C = US ST = STATE L = ANYWHERE O = MYCOMPANY OU = IT CN = www.example.com [v3_req] keyUsage = critical, digitalSignature, keyAgreement extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] DNS.1 = www.example.com DNS.2 = example.com DNS.3 = example.net
Go to a command prompt (Windows key+R type CMD) and move to the Apache directory cd\apache24\. Type makecert.bat and enter. You will get a message saying a new private key has been generated. Look in C:\Apache24\conf and you should see files called server.key and server.crt
Edit C:\xampp\apache\conf\extra\httpd-vhosts.conf and add this section to the end of the file. You would replace public_html with your addon-domain name if you were adding one (it would be folder example.com in this case)
<VirtualHost *:443> ServerName example.com ServerAlias example.com *.example.com DocumentRoot "c:/apache24/htdocs/public_html" <Directory "c:/apache24/htdocs/public_html"> </Directory> ServerAdmin firstname.lastname@example.org ErrorLog "logs/example.com-error.log" CustomLog "logs/example.com-access.log" common SSLEngine on SSLCertificateFile "conf/server.crt" SSLCertificateKeyFile "conf/server.key" </VirtualHost>
Start the Apache Server (run c:\Apache24\bin\httpd.exe) or stop and start it if you run as a service. Apache Monitor is handy for doing this too. In the browser, enter https://example.com. You will get a nasty certificate warning, but that’s ok because your certificate doesn’t have a valid authority. Click on advanced and choose to continue at the bottom of the window.
Apache Service Monitor
Apache Service Monitor is a handy tool to make sure Apache Server is running properly. In this example it is located at C:\Apache24\bin\ApacheMonitor.exe. Run it and you will see a tiny icon open up in the lower right of the task bar.
Right-click on the monitor and select Open Apache Monitor to view the panel.
At this point, you have a functioning HTTPS or HTTP server. If you aren’t using PHP or MySQL, you are good to go. You should rename your index.php to index.html if you aren’t using PHP.