In this article we will see how to install Apache from scratch and prepare your environment on Windows for development web with Apache and C++.
Let’s go step by step!
Download the file: Apache 2.4.57 Win64 | [Apache VS17 Win64 Binary] httpd-2.4.57-win64-VS17.zip
:C\
drivecd C:\Apache24\bin\
httpd -k install
httpd.conf
with Notepad#ServerName www.example.com:80 to ServerName localhost (remember to remove the junk (#) from the beginning of the line), save!
FROM:
TO:
httpd -k stop
and then httpd -k start
If the phrase: It works! appears, everything is ok, if not, repeat all the steps, because this procedure should work!
cd C:\Apache24\cgi-bin
and create a file named main.cpp
and insert this content inside:#include <iostream>
int main(int argc, char **argv){
std::cout << "Content-Type: text/html\n\n";
std::cout << "<h1>C++ running on the Web on Windows via Apache</h1>" << '\n';
return 0;
}
index.html
) within the same folder:g++ main.cpp -o index.html
/
) at the end.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:<IfModule dir_module>
DirectoryIndex index.html index.cpp
</IfModule>
Now just compile to binary: index.cpp
(remove index.html
) RESTART Apache and access: http://localhost/cgi-bin/.
The video below is in Portuguese, but you can watch the procedure if you have any difficulties.