Hello World
THIS TUTORIAL IS OUT OF DATE. PLEASE CHECK OTHER DOCUMENTATION TO FIND OUT MORE RECENT STATE OF AFFAIRS.
Copyright © 2004 Henryk Paluch
Hi folks!
I wrote an small tutorial, how to make Hello World application using mod_spin in Red Hat's Fedora Core 1. Hopefully it helps to start development with mod_spin. These RPMS should be installed:
- httpd-devel-2.0.48-1.2
- httpd-2.0.48-1.2
- apr-devel-0.9.4-2
- apr-util-devel-0.9.4-2
- apr-0.9.4-2
- apr-util-0.9.4-2
Note: original RedHat's httpd-2.0.47-x is broken (there is a lot of missing files in httpd-devel) - httpd-2.0.48 package is absolutely needed.
Get libapreq2-2.02-dev.tar.gz from http://httpd.apache.org and compile/install using:
./configure --with-apache2-apxs=/usr/sbin/apxs
make
make install
Unpack and compile mod_spin-0.0.4 using:
CPPFLAGS="-I/usr/include/apr-0" ./configure --with-apxs=/usr/sbin/apxs
make
make install
Unpack and compile spinapp-0.0.4 using:
CPPFLAGS="-I/usr/include/apr-0" ./configure --with-apxs=/usr/sbin/apxs
make
make install
Replace spinapp.c body with:
#include <rxv_spin.h> #include <time.h> #include <string.h> #include <httpd/http_protocol.h> #include <apr_strings.h> int rxv_spin_service(rxv_spin_context_t *ctx){ rxv_spin_data_t *hehe,*current_time; time_t t; struct tm *ttm; char *asc_time; /* str_single - for static constant strings */ hehe=rxv_spin_str_single(ctx->pool,"Hello World!"); rxv_spin_ctx_set(ctx,"hehe",hehe); /* NOTE: Thread unsafe (do not use with threaded Apache)! */ t = time(NULL); ttm = localtime(&t); asc_time = asctime(ttm); /* apr_pstrdup - needed to copy into pool dynamically allocated * "volatile" strings (otherwise further call to asctime() would overwrite * our value) */ current_time = rxv_spin_str_single(ctx->pool, apr_pstrdup(ctx->pool,asc_time)); rxv_spin_ctx_set(ctx,"current_time",current_time); ap_set_content_type(ctx->r, "text/html"); return OK; }
Create sample template file "spinapp.sm":
<html> <head><title>Spinapp Hello world</title></head> <body> Spinapp says: ${hehe} <br /> Current time is: ${current_time} <br /> </body> </html>
Create Apache configuration file and put it into /etc/httpd/conf.d (you may need to remove Duplicate LoadModule in main /etc/httpd/conf/httpd.conf file):
# # Example mod_spin configuration # /etc/httpd/conf.d/mod_spin.conf # LoadModule apreq_module modules/mod_apreq.so LoadModule spin_module modules/mod_spin.so AddType httpd/spin-template .sm # path to the shared library of the application SpinApplication /home/paluch/modspin/app/spinapp.so #path to the workspace directory SpinWorkspace /home/paluch/modspin/ws # base name for session and application database files SpinBasename app1 # name of the cookie for session tracking SpinCookie app1
Note: SpinApplication should point to your compiled spinapp.so (it should be in .libs/spinapp.so of your spinapp-0.0.3 source tree). Also ensure that SpinWorkspace points to existing directory, writable by Apache. Restart Apache.
Now you should point your borwser to your spinapp.sm file (for me it is /~paluch/spinapp.sm):
http://localhost/~paluch/spinapp.sm
and you should see nice output :-)