How to Enable Apache Web Server for C++ on Windows
Simple and easy!
Let’s go step by step!
01. Install Apache
1. Visit: https://www.apachelounge.com/.
2. Click Downloads on the left corner
Download the file: Apache 2.4.57 Win64 | [Apache VS17 Win64 Binary] httpd-2.4.57-win64-VS17.zip
3. Unzip the file: Extract to httpd-2.4.57-win64-VS17
4. Move the unzipped folder to the root of the
5. Open CMD (Run as Administrator) and enter the folder:
6. Run the command:
httpd -k install
7. Now enter the folder: C:\Apache24\conf and open the file:
httpd.conf with Notepad
8. I renamed the line that has:
#ServerName www.example.com:80 to ServerName localhost (remember to remove the junk (#) from the beginning of the line), save!
9. Now in CMD, restart Apache by running the command:
httpd -k stop and then
httpd -k start
10. Now open the browser and access: http://localhost/
If the phrase: It works! appears, everything is ok, if not, repeat all the steps, because this procedure should work!
02. Run C++ on the Web
1. Enter the folder:
cd C:\Apache24\cgi-bin and create a file named
main.cpp and insert this content inside:
2. Compile the code (it’s a good idea to use MinGW ) and save the binary ( can be named
index.html) within the same folder:
3. Access the address: http://localhost/cgi-bin/, it is important to put the slash (
/) at the end.
4. If you want Apache to automatically render
index.cpp, edit the file:
C:\Apache24\conf\httpd.conf, look for the line:
DirectoryIndex index.html and add
index. cpp at the end, looking like this:
Now just compile to binary:
index.html) RESTART Apache and access: http://localhost/cgi-bin/.
See the video
The video below is in Portuguese, but you can watch the procedure if you have any difficulties.