I'm sort of new to this myself too, although I've been experimenting with Python scripts rather than C.
Still, the info I have on this may prove useful to you.
Assuming you're running Raspbian (Debian), you'll have website definitions in the directory /etc/apache2/sites-available/. I for example have a file called stevepdp in there which is the development site for my personal website.
That file, looks like this:
Code: Select all
<VirtualHost *:80>
ServerAdmin webmaster@localhost
* ServerName stevepdp.local
* DocumentRoot /home/stevepdp/data/projects/www/stevepdp
* <Directory /home/stevepdp/data/projects/www/stevepdp/>
* Options +ExecCGI
* DirectoryIndex index.py
AllowOverride None
Order allow,deny
allow from all
* AddHandler cgi-script .py
* PythonDebug On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The lines you'll most likely need to consider are those I've marked with a *. For C programming for example, you'll probably be need to add a .cgi handler like so:
Your directory index line could therefore be:
Once you have a complete sites-available file, you must add the site to Apache by running:
I then have a hosts file entry (/etc/hosts) which lists each of my development sites and allows me to browse to them at addresses like
http://stevepdp.local or
http://norwichrpi.local.
The rules look like this:
The other thing to note is that your CGI script, if it prints out to the browser, must print the HTML content-type before anything else. The following C++ example came from
StackOverflow:
Code: Select all
#include <iostream>
using namespace std;
int main()
{
cout << "Content-Type: text/html" << endl << endl;
cout << "Hello to Apache and Firefox!" << endl;
return 0;
}
Use the /etc/apache2/sites-available/default file as a template and work from there.
I hope this info helps.