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
<VirtualHost *:80>
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
<Directory /var/www/html/cgi-bin/>
##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
</Directory>
</VirtualHost>
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
Try with this command:
sudo a2enmod cgi
Then restart apache!
Steps to install Apache on Ubuntu 13.10:
sudo apt-get install apache2
sudo service apache2 start
Steps to test Apache on Ubuntu 13.10:
Steps to use CGI programs under Apache on Ubuntu 13.10:
Steps to test CGI programs under Apache on Ubuntu 13.10:
/usr/lib/cgi-bin/
(e.g. /usr/lib/cgi-bin/test
)sudo chmod +x /usr/lib/cgi-bin/test
Note: "your-host-here.com" might well be "localhost", but SO won't let me use that in a URL :-/
Expanding on the answer from @tops.
Try sudo a2enmod cgi
, if you have already tried following a bunch of tutorials like Apache Tutorial: Dynamic Content with CGI, Ubuntu HTTDP or How to Install Apache2 webserver with PHP, CGI, and Perl Support in Ubuntu Server, and still cannot figure out what is missing from them.
Then restart apache!
Which may be done with:
sudo /etc/init.d/apache2 restart
sudo apache2ctl restart
sudo service apache2 restart
<- try this first
This worked for me on Ubuntu 13.10.
New commands to users coming from RedHad based distributions:
a2enmod
a2dismod
a2enconf
a2disconf
a2ensite
a2dissite
Remember, the main configuration file is /etc/apache2/apache2.conf
by default, and individual configuration components for modules and websites are in separate files.
EDIT: Expanded with details as to why people coming to this page may be having difficulties with enabling Apache CGI on Ubuntu.
I encountered this problem when trying to setup bugzilla in Ubuntu 14.04 @Andrew's answer was helful and so was @Kevin's links.. so other than enabling cgi, ensure that perl's module for apache2 is installed. You can do this by:
sudo apt-get install libapache2-mod-perl2
This will automatically enable the module as well as restart apache server. If not do that manually.
Don't have enough rep to upvote both of you, so thanks.
I tried to reproduce this issue and this is what i learned: In /etc/apache2/sites-available you either have multiple sites setup or are using the default. Either way there is a .... shows the path to my DocuumentRoot (wherer my .html files live). The second .... shows the path to my .cgi , .pl , .perl files:
<VirtualHost *:8080>
ServerName casey.local
**DocumentRoot /home/casey/work/htdocs/casey.local**
<Directory />
Options FollowSymlinks
AllowOverride All
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
**<Directory "/usr/lib/cgi-bin">**
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>