 Welcome this video is in response to a question that one of my supporters has asked and he's trying. He's going through a book that's talking about C programming and he was trying to create a C program that he can run on an Apache web server and He came across a problem. So what I've done now is on I'm logged in remotely to a machine here. It's a Linux Mint 18.1 Cinnamon and it's it's running. It's the live CD So it's it's a brand new system The only thing I've done so far is connected to my network and enable SSH so I can log in. So this is bare bones Linux Mint if you can call it bare bones I just wanted to do on a fresh system. So I don't skip any steps, but let's go ahead and get started So the first things we need to do are install the tools that we need So we're going to pseudo app to get install build essentials We're going to need those to compile our C code. I'm going to use Vim as my text there You don't have to have that but I'm going to install that and we're going to use Apache 2 as our As our web server, so I'm gonna go ahead and let those install Once those are installed. We're then going to create a basic little hello world C file This should only take a few seconds to install here. It's I'm packaging them Give it a second and that's everything we need installed. I'll clear the screen It's not gonna go Vim and I'm gonna create a Text file dot C file called test. I'm gonna go in here and we're going to type Include and we're gonna include the standard and out header And they're gonna init main our main function here and we're going to in here give a print F and We're going to say in here Rowing to type and you got to type this properly. So all your code every code you write for your Apache CGI bin folder has to start with this line. So it's content dash type Colon and this part might change a little bit. We're going to create a text file. So this is going to output plain text. So text plain Backslash and backslash and those are new line characters. So this is telling the web browser I'm transferring you a plain text file and then you got to give it Two new line characters before you can start giving the output. This may change to To say HTML if it's an HTML file, but we're just working with a plain text file here for now I'm gonna go ahead and hit enter and then we're going to give it our out I'm gonna say print F in here. I'm gonna say Hello world and Then to be proper. We're going to return zero and We will save that now we can pile that GCC That file name dash o for output and we'll just call the output test So it's compiled it and here in my shell. I should be able to test See and get the output. So as you can see it gave us this I didn't plan new line character at the end of this, which I probably should have Let's go ahead and add that just to to be proper about it. So going back into Vim New line character will recompile that GCC the file name We just created and the dash o in the output file name Dot slash test and there we go. You can see the output So the web browser will only display this line here This line here is just telling the web browser what we're passing to it So it knows how to display it properly So our C program is created compiled now We need to put it someplace on our web server where it can run and this folder may change But on Debian based systems. So Debian Ubuntu Linux Mint. It's usr lib cgi bin so we're going to as Root or pseudo we're gonna pseudo copy the file. We just created we just compiled and I'm gonna put it in this folder here now Let me go to our web browser This is our the URL for our web server or not the URL, but the IP address I'll go ahead and refresh that you can see that this is the default page and to get to our code Since we copied it into our CGI folder, it's going to be all our case CGI dash bin Forward slash and the name of our file, which is in this case test. I'll go ahead and hit enter and we get not found So this is where the question came in From the viewer from my supporter. He was getting that error. I believe it was that or he was getting Thing is you have to enable CGI scripts for Apache. You should only have to do this once, but you're going to pseudo a2en mod CGI I'm gonna go ahead and enter it will enable that and tell us that you have to restart the Apache server So we're going to pseudo server Apache to restart and Our Apache server should only take a second. It's restarted We go back to our web browser here and now if we refresh our script we get hello world as an output So that is how you? Create your CGI or your C programs to run on Apache in your CGI bin folder So again, we just created C code after installing the tools to compile a C code. We compiled it and We copied the compiled program into again This is on Debian based systems usr lib CGI bin if you're running fedora or sent OS or red hat This folder is gonna be something different But if you're on a Debian based system, this is where it should be for Apache 2 anyway After doing that again, you only have to do this once you shouldn't have to do this again But pseudo a2en mod CGI and that will enable the CGI scripts For your web server and then you have to restart your server, but that should stay even after a reboot. This should stay effective And that's it. I do. Thank you for watching. I do hope that you have a great day Please visit films by Chris comm. That's Chris of the K. There should be a link in a description There's also gonna be a link in a description to some notes on this going over what I've gone over and Also, if you do enjoy my videos think about coming a supporter over at patreon.com It's patreon.com forward slash metal x one thousand and you can also support me through paypal If you go to films by Chris comm again, there's link in the description There's a support section with links to both my patreon account and also a paypal link So I do thank you for all who support me and I hope that you have a great day