Examine Apache's configuration file again to see what the CGI arrangements are.
root@petalinux:~# nano /etc/apache2/httpd.conf
Search for
cgi-bin. Do this multiple times to find the two lines of interest.
As can be seen, CGI is being served from
/usr/libexec/apache2/modules/cgi-bin.
Quite Nano.
Examine the cgi-bin directory and the files it contains.
root@petalinux:~# ls -la /usr/libexec/apache2/modules/cgi-bin
total 16
drwxr-xr-x 2 root root 120 Mar 9 2018 .
drwxr-xr-x 3 root root 1900 Mar 9 2018 ..
-rw-r--r-- 1 root root 820 Mar 9 2018 printenv
-rw-r--r-- 1 root root 1074 Mar 9 2018 printenv.vbs
-rw-r--r-- 1 root root 1133 Mar 9 2018 printenv.wsf
-rw-r--r-- 1 root root 1261 Mar 9 2018 test-cgi
Examine the CGI script test-cgi.
root@petalinux:~# cat /usr/libexec/apache2/modules/cgi-bin/test-cgi
- #
-
- # To permit this cgi, replace # on the first line above with the
- # appropriate #!/path/to/sh shebang, and set this script executable
- # with chmod 755.
- #
- # ***** !!! WARNING !!! *****
- # This script echoes the server environment variables and therefore
- # leaks information - so NEVER use it in a live server environment!
- # It is provided only for testing purpose.
- # Also note that it is subject to cross site scripting attacks on
- # MS IE and any other browser which fails to honor RFC2616.
-
- # disable filename globbing
- set -f
-
- echo "Content-type: text/plain; charset=iso-8859-1"
- echo
-
- echo CGI/1.0 test script report:
- echo
-
- echo argc is $#. argv is "$*".
- echo
-
- echo SERVER_SOFTWARE = $SERVER_SOFTWARE
- echo SERVER_NAME = $SERVER_NAME
- echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
- echo SERVER_PROTOCOL = $SERVER_PROTOCOL
- echo SERVER_PORT = $SERVER_PORT
- echo REQUEST_METHOD = $REQUEST_METHOD
- echo HTTP_ACCEPT = "$HTTP_ACCEPT"
- echo PATH_INFO = "$PATH_INFO"
- echo PATH_TRANSLATED = "$PATH_TRANSLATED"
- echo SCRIPT_NAME = "$SCRIPT_NAME"
- echo QUERY_STRING = "$QUERY_STRING"
- echo REMOTE_HOST = $REMOTE_HOST
- echo REMOTE_ADDR = $REMOTE_ADDR
- echo REMOTE_USER = $REMOTE_USER
- echo AUTH_TYPE = $AUTH_TYPE
- echo CONTENT_TYPE = $CONTENT_TYPE
- echo CONTENT_LENGTH = $CONTENT_LENGTH
Edit the file as the header comment suggests, replace the first line # with #!/bin/sh
root@petalinux:~# nano /usr/libexec/apache2/modules/cgi-bin/test-cgi
Quit Nano (press Ctrl + X to quit, enter y when asked about saving the modified buffer, then Enter to confirm the original file location).
Access the webserver by pointing a browser at
http://192.168.2.87/cgi-bin/test-cgi.
Sadly the test-cgi script is not being executed, instead its contents are simply being dumped to the browser.
Take a look at Apache's configuration file again.
root@petalinux:~# nano /etc/apache2/httpd.conf
Search for
mod_cgid.so.
As can be seen, the LoadModule for this line is commented out. Delete the # at the start of the line and save the file.
Reload Apache so the updated httpd.conf is being used.
root@petalinux:~# /etc/init.d/apache2 reload
Access the webserver again by pointing a browser at
192.168.2.87/cgi-bin/test-cgi.
Sadly the test-cgi script is still not being executed.
Thinking back to the previous Webserver tutorial, the BitBake recipe set execute permissions on the shell script CGI's.
As seen above, the permissions for test-cgi are -rw-r--r--. Change these so the file is executable.
root@petalinux:~# chmod +x /usr/libexec/apache2/modules/cgi-bin/test-cgi
Access the webserver again by pointing at
http://192.168.2.87/cgi-bin/test-cgi.
All being well the following page should be displayed.
The CGI (shell script) service is working OK.