notes/C program cgi for Apache2 server-kNqS4yE7.sh
#setting Apache2 up for C cgi programs
#install needed programs
sudo apt-get install build-essential vim apache2
##########create C code 'vim test.c'###########
#include <stdio.h>
int main(){
printf("Content-type:text/plain\n\n");
printf("Hello, you are still learning C!!\n");
return 0;
}
################################################
#compile code and put it in cgi folder for apache
gcc test.c test
sudo cp test /usr/lib/cgi-bin/
#enable cgi for apache and restart server
sudo a2enmod cgi
sudo service apache2 restart
###################################another cgi example with user variables##################
/*****************************************************************
* C Programming in Linux (c) David Haskins 2008
* chapter1_3.c *
*****************************************************************/
#include <stdio.h>
int main(int argc, char *argv[]){
int i=0;
printf("Content-type:text/plain\n\n");
printf("Hello, you are still learning C!!\n");
printf("Number of arguments to the main function:%d\n", argc);
for(i=0;i<argc;i++){
printf("argument number %d is %s\n", i, argv[i]);
}
return 0;
}
################################################################
#usage
http://localhost/cgi-bin/test?hello world