NOTE ABOUT FORTRAN CGI PROGRAM IN DEBIAN APACHE2








Contents

To set up a Fortran CGI program in the Debian Apache2 environment, you’ll need to configure a few things to
ensure that the Fortran executable can run properly as a CGI script. Here’s a general guide to help you get
started:

1 Install Necessary Packages

Ensure that you have the necessary packages installed, including Apache2 and a Fortran compiler like gfortran.

sudo apt-get update 
sudo apt-get install apache2 gfortran

2 Write the Fortran Program

Create a simple Fortran program that can be used as a CGI script. Here’s an example of a basic “Hello, World!”
CGI program in Fortran:

program hello_cgi 
  print *, "Content-type: text/plain" 
  print *, "" 
  print *, "Hello, World from Fortran CGI!" 
end program hello_cgi

3 Compile the Fortran Program

Compile the Fortran program to create an executable:

gfortran -o hello_cgi hello_cgi.f90

4 Set Up the CGI Directory

By default, Apache2 may not have a CGI directory enabled. You’ll need to enable the CGI module and set up a
directory for your CGI scripts.

sudo a2enmod cgi 
sudo mkdir /usr/lib/cgi-bin/fortran 
sudo cp hello_cgi /usr/lib/cgi-bin/fortran/ 
sudo chmod 755 /usr/lib/cgi-bin/fortran/hello_cgi

5 Configure Apache2

Edit the Apache2 configuration to allow CGI scripts to be executed. You can either modify the main configuration
file or create a new configuration file for your site. Edit /etc/apache2/sites-available/000-default.conf (or your
specific site configuration):

<VirtualHost *:80> 
   ... 
   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
   <Directory "/usr/lib/cgi-bin"> 
       AllowOverride None 
       Options +ExecCGI 
       AddHandler cgi-script .cgi .pl .f90 .out 
       Require all granted 
   </Directory> 
   ... 
</VirtualHost>

6 Restart Apache2

Restart Apache2 to apply the changes:

sudo systemctl restart apache2

7 Test the Fortran CGI Script

You should now be able to access your Fortran CGI script by visiting:

http://your-server-ip/cgi-bin/fortran/hello_cgi

This should display the “Hello, World from Fortran CGI!” message.



Leave a Reply

Your email address will not be published. Required fields are marked *