I have written a simple Lua script that reads from and writes to an XML database. I want to use it as CGI, eventually returning data to display in a web page, but when, for testing purposes, I go straight to the script in a browser, it blows up on require("socket.http") with a 500 Internal Server Error and it apparently can't find the Lua socket library when run in a browser.
I haven't used CGI in years and I'm very new at Lua, so thanks for any assistance.
it apparently can't find the Lua socket library when run in a browser.
I assume your script is using socket.http. If so, you need to make luasocket (both its binary libraries and Lua files) available to your script. My suggestion is to make it work when you run it locally, before you try to make it run as a CGI script. You'll need to either get a pre-compiled luasocket for your platform or compile and install it yourself. You'll then need to use LUA_PATH and LUA_CPATH in your script to reference the locations of Lua (PATH) and binary (CPATH) files.
Related
I have memory related problem in my application on solaris9 environment where Tcl_DeleteInterp() function calls lot of free() and mutex_unlock() functions. To debug the problem i followed the below steps to compile tcl on solaris server (with TCL_MEM_DEBUG flag) but still i couldn't use the 'memory' command in my interpreter.
Ran configure script on server (./configure –prefix=<directory needs to be installed> --enable-symbols=mem)
Make clean all
Make install (tcl libraries and tlcsh exe is copied to the path specified in step1)
Compilation generated two libraries (libtcl8.4g.so and libtclstub8.4g.a), I copied libtcl8.4g.so as libtcl8.4.so to my app
Copied tcl8.4 directory as well.
I also copied the tclsh8.4 to $PROVHOME/bin and created soft link as tclsh-> tclsh8.4.
From my application i linked the debug symbol enabled libraries to the place where exactly i created the Tcl interpreter.
Initialized the Tcl interpreter to using Tcl_InitMemory() function (so that the memory command will be registered in the supplied(arg) interpreter.
When i used the interpreter exe (tclsh) separately i could execute the memory command, but when i used the same exe on my application its not working. Can someone help me what could be the possible reason for this problem ?
Also help me how can i cross verify the libraries that they are compiled with TCL_MEM_DEBUG flag.
Will the Tcl source code tar file contain Solaris directory where i have to build the libraries or should i use the unix source code for solaris platform as well ?
Thanks
Are you using [mem] interactively (which does expansion of unambiguous short command names) and forgetting to use the full name ([memory]) in your scripts?
You're using Tcl embedded in your code? You need to call Tcl_InitMemory (passing in the handle to the interpreter where you want the memory command created) after creation of the interpreter and before you run user scripts, i.e., straight after the Tcl_CreateInterp gives you the handle (which should in turn come after the Tcl_FindExecutable call that initializes the shared parts of the library).
You must also make sure that everything is built with that flag set so that the correct memory allocation APIs are used in both your code when it integrates with Tcl, and you must make sure that you are linking against the debugging build. It's probably the linking that has gone wrong, but I've not done that level of development on Solaris for many years.
I think you'll find that “Getting a list of used libraries by a running process (unix)” is relevant to your problems.
Is there a way to place a matlab gui I have on a website, such that users could use or play with, similar to java applets etc? Would I need to compile it differently in some sense?
MATLAB Compiler allows you to create a standalone exe which can be called by your web server using the Common Gateway Interface (CGI).
The CGI script outputs HTML by printing it to the screen (stdout). You can input to a CGI script through the environment variable query_string . A simple CGI script can be written Using the Matlab functions getenv and fprintf.
But don't forget to check that you have configured your web server properly in order to run CGI programs, and that you are able to execute a CGI program that is independently.
There's an example which demonstrates how to do this in Mathworks website. Perform the following steps to compile and run this example:
Compile the MATLAB file into a standalone application. This can be done with the following command in MATLAB: mcc -m mycgimagic.m
Copy the HTML file to the web server and place it in a directory with the proper permissions. Consult your web server documentation for how to do this.
Copy the exe and CTF files to the web server and place them in the "/cgi-bin" directory of your website. You will need to configure the web server to have the proper permissions to be able to execute the exe-file. Consult your web server documentation for how to do this.
Install the MCR on the web server.
Execute the exe-file for the first time from the web server system itself in order to force the CTF-archive extraction.
Load the HTML-file in a web browser from the remote computer and submit the form to execute the CGI program.
I want to run a Perl script online, but I don't know how.
In PHP you need to start with <?php, so do you have to start with something like that in Perl?
And does Apache automatically recognize Perl? Or do I have to upload Perl and let it point to it using #!/path/to/perl?
Can I use print() to display HTML?
In PHP you need to start with <?php, so do you have to start with something like that in Perl?
There are frameworks (such as Mason) which work like that, but it is more typical to have a standard Perl program which outputs the page.
And does Apache automatically recognize Perl?
Apache doesn't automatically recognise any kind of server side programming.
Or do I have to upload Perl and let it point to it using #!/path/to/perl?
You would need to have Perl installed on the server. You would generally start a script that way (but not necessarily, e.g. if you were using mod_perl), but would have to configure the server to recognise it as an executable and run it (just as you have to configure the server to recognise files ending with .php as scripts to run with PHP).
Can I use print() to display HTML?
Yes.
You should probably start by looking at the question Web Programming For The Non-Web Programmer (in Perl).
Must you use Apache? If not here is an alternative to consider.
I have found that the built-in servers and templating engine in the Mojolicious framework work very naturally for inline Perl within HTML. The tags are of the form <%== but work the same way. Also it has good documentation and examples to get you going.
Edit: It seems that there are ways to use Apache with Mojolicious too, see http://search.cpan.org/perldoc?Mojolicious::Guides::Cookbook, though the built-in servers have worked well for me, with FAR less (ie no) configuration.
Apache HTTP doesn't automatically understand Perl or PHP for that matter. For PHP to work, you have to have the Apache httpd module called something like mod_php.so or libphp5.so installed. However, since many websites use PHP in this manner, this Apache httpd module is normally installed.
Just as you need mod_php in order to use PHP in Apache's httpd web server, you need to do is make sure your web server is using mod_perl if you want to use Perl in a similar manner.
You'll need to build and install mod_perl which can be tricky -- especially if you don't control the machine the server is on.
The other way to use Perl is to use what's known as CGI-Perl. This is much easier to setup, but it is also much more dangerous since it can lead to someone being able to run unauthorized programs on your Apache httpd server.
In this case, you need to set up a CGI-BIN directory, and configure Apache httpd. This is fairly simple. Once you do that, you put all of your Perl scripts into the _CGI_BIN_ directory. In this case, your Perl scripts will have to handle all of the communication between your web server and the web client and handle all displays. Fortunately, it's not too difficult in perl since Perl gives you the basic modules to do this.
I have been working in a Perl script to read log files, but none of the people at work
want to use it as it requires run it from CLI, Im looking to integrate my Perl code which mainly
reads a txt file and produces and output (Already more than 2,000 lines) into a GUI which can be used with Windows or MAC PCs,
Example:
my perl script:
#./perl -i myfile
# HELLO this is the output!
Instead I want users to run the App and give them the chance to upload file and a Run button.
Thanks!
Then you can either write a web based frontend or use a GUI library such as Tk, Wx or Gtk.
Run as a CGI script which should ouput as HTML. For more you use template system like Template tool kit
In my experience, Tk is the most cross-platform GUI framework for Perl. It is very primitive (both in looks and API), but it works as expected almost everywhere with minimal fuss. Even with Gtk, I found there were some combinations of platforms and Perl deployments that just wouldn't work.
If you want to go the CGI route, try POEx::HTTP::Server. This will run a small web server within Perl without needing all the configuration of a full web server like Apache.
What does it mean when I access my Perl script via URL, but when I do, the source code is printed on the screen?
Does this mean that Perl isn't properly set up? I'm using Apache on Fedora.
This means your webserver isn't set up to execute the script at that url. What server are you using?
It could also mean you are putting the Perl script in the wrong folder. The cgi-bin folder is still widely used as the folder where CGI scripts should be stored and run from. Other folders may just open the file and read it as text, similar to an HTML document, instead of running the document as code. But it can also mean the server is just not setup properly to run Perl scripts or other types of server-side scripts.
This means that you probably aren't doing what your server is expecting. Usually servers expect either that every file in a CGI directory is an executable, or that files with a certain extension are executable and it can serve any other file as its content.
Figure out which file extension your server expects your CGI program to use.
Ovid's CGI Course may help you (if you use CGI of course)