Test CGI in userdir on Fedora 26

1. Config mod_userdir
<IfModule mod_userdir.c>
    UserDir public_html
</IfModule>

<Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes Options
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

2. Disable SELINUX

3. Change the permission for $HOME to 711, $HOME/public_html to 755 and $HOME/public_html/cgi-bin to 755 (SUEXEC doesn't allow this folder to be writable to others)

4. Add .htaccess to $HOME/public_html/cgi-bin with below contents.
* SetHandler will disable Directory Index
SetHandler cgi-script
AddHandler cgi-script .cgi .pl .py .rb .phpc
Options +ExecCGI

5. Test CGI scripts.
5.1 Perl testperl.pl
#!/usr/bin/perl

print "Content-Type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello World - First CGI Program - Perl</title>';
print '</head>';
print '<body>';
print '<h2>Hello World! This is my first Perl CGI program</h2>';
print '</body>';
print '</html>';

1;


5.2 Python testpython.py
#!/usr/bin/python
  
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello World - First CGI Program - Python</title>'
print '</head>'
print '<body>'
print '<h2>Hello World! This is my first Python CGI program</h2>'
print '</body>'
print '</html>'

5.3 PHP testphp.phpc
* need to turn off cgi.force-redirect in /etc/php.ini
cgi.force_redirect = 0


<?php

        print("Content-type:text/html\r\n\r\n");
        print('<html>');
        print('<head>');
        print('<title>Hello World - First CGI Program - PHP</title>');
        print('</head>');
        print('<body>');
        print('<h2>Hello World! This is my first PHP CGI program</h2>');
        print('</body>');
        print('</html>');
?>


5.4 Ruby testruby.rb
#!/usr/bin/ruby
  
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello World - First CGI Program - Ruby</title>'
print '</head>'
print '<body>'
print '<h2>Hello World! This is my first Ruby CGI program</h2>'
print '</body>'
print '</html>'

6. CGI with shells. 






Comments

Popular Posts