There are 3 ways to use CGI.
- First Way
When we install Apache server, then /usr/lib/cgi-bin folder is automatically created. You can place c++ files in that folder and execute them on browser(localhost/cgi-bin/example). - Second Way
You can also configure /var/www/cgi-bin for CGI programming. - Third Way
You can also configure cgi-bin in home directory as /public_html/cgi-bin.
According to me 3rd way is best as its in home directory and we don’t have to use sudo while compiling or creating any file.
Steps to configure cgi-bin in public_html and public_html. Run following commands in terminal
- $ sudo a2enmod cgi
- $ sudo a2enmod cgid
- $ sudo a2enmod userdir
- $ sudo service apache2 restart
- $ mkdir ~/public_html
- $ cd ~/public_html
- $ mkdir cgi-bin
- $ cd /etc/apache2
- $ sudo vim sites-available/default
- Add following text in file:
ScriptAlias /cgi-bin/ /home/*/public_html/cgi-bin/ <Directory "/home/*/public_html/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch SetHandler cgi-script Order allow,deny Allow from all </Directory>
- $ sudo service apache2 restart