Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:06:58+00:00 2026-06-18T01:06:58+00:00

This question I’m sure has been answered, I honestly don’t know how to ask

  • 0

This question I’m sure has been answered, I honestly don’t know how to ask it via search though. So please excuse my lack of knowledge as this one of the only place I really have a lack of knowledge in the world of Computer Science.

How can I/ Is it possible, to run a C program on a Hosted Server. To where I could go to http://mysite.com/myspecialcprogram.c and it would run? Or better yet, to what extent can I use a high level language like C to program for my server?

It should also be noted that I have a Dedicated Linux box running apache. So I have full access.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:06:59+00:00Added an answer on June 18, 2026 at 1:06 am

    One way is to run it as CGI, as @paddy already mentioned. However, the program will run slow, long startup time.

    Another way is to run it using FastCGI. It will be much more faster, you just need a few modifications on your code to make it works, for example as CGI:

    #include <stdio.h>
    #include <time.h>
    
    int main(int argc, char **argv)
    {
        time_t timer;
        char time_str[25];
        struct tm* tm_info;
    
        time(&timer);
        tm_info = localtime(&timer);
        strftime(time_str, sizeof(time_str), "%Y/%m/%d %H:%M:%S", tm_info);
    
        /* Without this line, you will get 500 error */
        puts("Content-type: text/html\n");
    
        puts("<!DOCTYPE html>");
        puts("<head>");
        puts("  <meta charset=\"utf-8\">");
        puts("</head>");
        puts("<body>");
        puts("   <h3>Hello world!</h3>");
        printf("   <p>%s</p>\n", time_str);
        puts("</body>");
        puts("</html>");
    
        return 0;
    }
    

    Compile it:

    $ # 'cgi-bin' path may be different than yours
    $ sudo gcc example.c -o /usr/lib/cgi-bin/example
    $ wget -q -O - http://localhost/cgi-bin/example
    <!DOCTYPE html>
    <head>
      <meta charset="utf-8">
    </head>
    <body>
       <h3>Hello world!</h3>
       <p>2013/01/30 08:07:29</p>
    </body>
    </html>
    $ 
    

    Using FastCGI:

    #include <fcgi_stdio.h>
    #include <stdio.h>
    #include <time.h>
    
    int main(int argc, char **argv)
    {
        time_t timer;
        char time_str[25];
        struct tm* tm_info;
    
        while(FCGI_Accept() >= 0)   {
            time(&timer);
            tm_info = localtime(&timer);
            strftime(time_str, sizeof(time_str), "%Y/%m/%d %H:%M:%S", tm_info);
    
            /* Without this line, you will get 500 error */
            puts("Content-type: text/html\n");
    
            puts("<!DOCTYPE html>");
            puts("<head>");
            puts("  <meta charset=\"utf-8\">");
            puts("</head>");
            puts("<body>");
            puts("   <h3>Hello world!</h3>");
            printf("   <p>%s</p>\n", time_str);
            puts("</body>");
            puts("</html>");
        }
    
        return 0;
    }
    

    Compile it:

    $ # Install the development fastcgi package, I'm running Debian
    $ sudo apt-get install libfcgi-dev 
     ...
    $ 
    $ # Install Apache mod_fcgid (not mod_fastcgi)
    $ sudo apt-get install libapache2-mod-fcgid
     ...
    $ 
    $ # Compile the fastcgi version with .fcgi extension
    $ sudo gcc example.c -lfcgi -o /usr/lib/cgi-bin/example.fcgi
    $ # Restart Apache
    $ sudo /etc/init.d/apache2 restart
    Restarting web server: apache2 ... waiting .
    $
    $ # You will notice how fast it is
    $ wget -q -O - http://localhost/cgi-bin/example.fcgi
    <!DOCTYPE html>
    <head>
      <meta charset="utf-8">
    </head>
    <body>
       <h3>Hello world!</h3>
       <p>2013/01/30 08:15:23</p>
    </body>
    </html>
    $
    $ # Our fastcgi script process
    $ ps aux | grep \.fcgi
    www-data  2552  0.0  0.1   1900   668 ?        S    08:15   0:00 /usr/lib/cgi-bin/example.fcgi
    $ 
    

    In poth programes, there is:

    puts("Content-type: text/html\n");
    

    This will prints:

    Content-type: text/html[new line]
    [new line]
    

    Without it Apache will throw 500 server internal error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question might have been answered, if yes, please share the link. I have
This question has been asked and answered a 100 times by several people. However,
This question may sound incredibly stupid, but if I don't ask I'll never know...
This question has probably been asked before, but I was wondering if there was
This question has been asked, in various flavors, several times. Unfortunately, none of the
This question has been thrown around without an answer. YES, we can hide the
This question is totally unacceptable and will be closed but... Has SQL Fiddle been
This question has been retitled/retagged so that others may more easily find the solution
This question has been bothering me for quite a while: I have a Room
this question is applicable on different RDBMS : MySQL and SQL Server I've been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.