Thursday, September 25, 2014

Setup web server, apache, for cgi script , bash, php and perl

1- install apache2, php5, php5-cli, libapache2-mod-fcgid
root@localhost# apt-get install apache2 php5 php-cli libapache2-mod-fcgid

2- configure apache2 to be able to execute extension, .sh, .php and .pl in /usr/local/apach2/cgidir

 create file cgidir.conf in /etc/apache2/conf.d/ and add the following content

Alias /cgidir/ /usr/local/apache2/cgidir/

<Directory /usr/local/apache2/cgidir>
 Options +ExecCGI
 AddHandler cgi-script .cgi .pl .sh .php 


</Directory>

3- create the cgidir directory and add the cgi script
root@localhost# mkdir -p /usr/local/apache2/cgidir/
root@localhost# cd /usr/local/apache2/cgidir/

create file test.sh in  /usr/local/apache2/cgidir/ and add the following content (cgi script for bash sh)

#!/bin/bash

echo "Content-type: text/html"
echo ""

echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>PoC</title>'
echo '</head>'
echo '<body>'
echo '<pre>'
/usr/bin/env
echo '</pre>'
echo '</body>'
echo '</html>'

exit 0


create file test.pl in  /usr/local/apache2/cgidir/ and add the following content (cgi script for perl)


#!/usr/bin/perl

print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello Word - CGI Program</title>';
print '</head>';
print '<body>';
print '<h2>Hello CGI program ! -- perl</h2>';
print '</body>';
print '</html>';

1;


create file test.php in  /usr/local/apache2/cgidir/ and add the following content (cgi script for php)

 <?php
        echo "test cgi php";
?>


4- assign permission to directory to be able to execute then restart apache service

root@localhost# chmod 777 -R /usr/local/apache2
root@localhost# service apache2 restart


5- access the cgi script
http://192.168.202.5/cgidir/test.sh
http://192.168.202.5/cgidir/test.pl
http://192.168.202.5/cgidir/test.php




No comments:

Post a Comment