IP redirects to folder/index.html not www/html/index.html, cgi-bin from other location

  • Posted August 4, 2014

I am using ec2(Ubuntu) for perl program.

  1. When I call my IP, I want to show the IP/foldername/index.html How to do that- which one is suitable for me? redirect or virtual host. because I’m using Perl and I’m afraid that my settings will conflict with another and next question is
  2. I want to run my perl script from IP/foldername/cgi-bin/ (Now I can only run from /usr/lib/cgi-bin How to configure it?

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

For your first question, all you need to do is change DocumentRoot /var/www/html to DocumentRoot /path/to/some/folder in your existing VirtualHost

For your second question, you need to a few things to get that set up. First, run:

sudo apt-get install libapache2-mod-perl2
sudo a2enmod cgi
sudo a2enmod perl

Then you must edit /etc/apache2/conf-enabled/serve-cgi-bin.conf Change the highlighted paths to the folder hosting the Perl scripts:

<IfModule mod_alias.c>
	<IfModule mod_cgi.c>

	<IfModule mod_cgid.c>

		ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
		<Directory "/usr/lib/cgi-bin">
			AllowOverride None
			Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
			Require all granted

Finally, you must restart Apache:

sudo service apache2 restart