I just install Ubuntu 13.10 and I am trying to install Apache. But when I tried to run a perl file in cgi-bin, the browser showed only plain text.
My default.conf of Apa
Make sure apache cgi mode is enable
sudo a2enmod cgi //will enable the cgi mode
sudo a2dismod cgi //Will disable the cgi mode
Keep your all files under the webroot "cgi-bin" folder
sudo mkdir /home/www/cgi-bin
Make sure that the file permission to the .cgi file is okay
sudo chmod 755 yourFile.cgi
Try executing it through terminal
perl /Path_To_The_File/fileName.cgi
Ensure that your fileName.cgi contains bellow code at top of the file
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
If all above step is working well then
Create virtual host in apache for your perl project
cp /etc/apache2/sites-available/000-default.conf ./your_project.conf
sudo nano /etc/apache2/sites-available/your_project.conf
Inside your your_project.conf file, replace these lines
ServerAdmin xyz@gmail.com
DocumentRoot /var/www/html/cgi-bin //Define where your project is
ServerName your_project.com //URL through which you want to access
ServerAlias your_project.com
ErrorLog ${APACHE_LOG_DIR}/error.log //Error for the project will store in this file
CustomLog ${APACHE_LOG_DIR}/access.log combined
ScriptAlias /cgi-bin/ "/var/www/html/cgi-bin/" //particular directory is set aside for CGI programs
##TO consider the files as cgi which has .cgi and .pl extension
Options +ExecCGI
AddHandler cgi-script .cgi .pl
##To consider all files as cgi file (if want to use remove # from last two line add in above 2 line)
#Options ExecCGI
#SetHandler cgi-script
Run these commands
sudo a2ensite your_project.conf //Will enable your configuration file
sudo service apache2 restart //Restarting apache2
Add your host
sudo nano /etc/hosts
//add this line
127.0.0.1 your_project.com
Now run execute your cgi file
your_project.com/cgi-bin/fileName.cgi