Execute CGI program on WAMP from any folder - perl

I am developing a a PHP web site but I am using Perl CGI for file uploads with progress.
I have installed ActivePerl under WAMP.
As I am developing the site to run on a Unix server I want to mirror that environment locally, so I want to execute CGI files outside of the WAMP cgi-bin.
How can I do that?

I work on Perl and CGI recently for Movable Type on Localhost so I was doing few steps on setting up Perl and CGI with Wamp Server. I hope this might be useful.
Step1:
First you need to download Wamp Server from www.wampserver.com and install Wamp Server on your machine. The default installation directory is ‘C:\wamp” and here I am using the default options for installation. To complete the installation you have to set the host name for your mail server and your email address, here you can leave the default option again. That will do no harm.
The current Wamp Server will install Apache 2.2.11, PHP 5.2.9-2 + PECL, MySQL 5.1.33, SQLitemanager and PhpMyadmin.
Step2:
Now you have to download ActivePerl (currently 5.10.0) from http://www.activestate.com/activeperl/downloads and install it. The default installation directory is “C:\Perl“, but for simplicity and ease of use I use different directory. I create a new folder name “perl” inside “C:\wamp\bin“. So I install Active Perl in “C:\wamp\bin\perl” directory. The next thing you need to do is configure the Apache web server to execute Perl and CGI script.
Step3:
This is the most important part here. You need to edit the Apache configuration file. Now go to “C:\wamp\bin\apache\Apache2.2.11\conf” directory and open “httpd.conf” file. Edit the httpd.conf file as below.
1. Inside httpd.conf, look for the line that says ““, just a few lines below this you’ll find the line that says “Options Indexes FollowSymLinks“. Add “Includes ExecCGI” in the SAME line with FollowSymLinks, thus it will change from:
Options Indexes FollowSymLinks
And now becomes:
Options Indexes FollowSymLinks Includes ExecCGI
This will enable CGI script inside your www folder.
2. Now look for the line “AddHandler cgi-script .cgi“, this line is commented out. You need to enable this by un-comment this line, to do that remove the # character at the beginning of this line. This will add handler for files with .cgi extension. If you want to use .pl file extension in your server add “AddHandler cgi-script .pl” just below the above line. Now you will be able to execute CGI and Perl script with .cgi and .pl, extension.
Lines to add
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
3. To add directory index file, look for the line “DirectoryIndex index.php index.php3 index.html index.htm“. Add index.cgi and index.pl in this line.
Lines to add
1. DirectoryIndex index.php index.php3 index.html index.htm index.cgi index.pl
DirectoryIndex index.php index.php3 index.html index.htm index.cgi index.pl
Alternative: If you do not want to waste your time doing the above 3 steps, you can download the edited configuration file httpd.conf here. Replace the one inside your apache directory with this one.
Step4:
Your server is now configured and ready to run perl and cgi script. Next thing you might need to do is to configure perl to use mysql database. You need to download and install mysql driver to enable database connection through your perl script. You have to grab the driver from the ActivePerl package repository. However, mysql driver module is not available in the default ActivePerl Package Repository. So, you need to add additional repository and install from that repository. Follow the steps below:
Go to DOS Command Prompt and type “PPM”. Now type “Install DBI” > ENTER. Once that install is done, type “Install DBD-mysql” > ENTER. You should be done by now.
we will have to modify some setting of all our cgi files, well we have to modify all cgi files that you get as commonly they will point to perl like “#!/usr/bin/perl” but we do not have that convention in windows. The change is just on the first line of your CGI files, so it shoould be easy. Change any reference to perl in your cgi files to your current location. Keep in mind if you have not enabled environment variable path during perl installation, you will have to give a full path like “c:\perl\bin\perl.exe” but if you have given the path in the environment variable, you can simply do “perl.exe” so most of our cgi files with have the first line as “#!perl.exe -w”, without the quotes though.

Depending on your webserver, on W(in) it is often IIS.
You can have any virtual folder point to your perl-script folder. Then you need to set c:\Perl\bin\perl.exe "%s" %s to be a handler for *.pl for this folder. See e.g. http://community.activestate.com/forum-topic/configuring-perl-iis-7-0 for details. (under item 7, I think pressing Yes is the right thing to do). To make a virtual folder, open Internet Information Services (IIS) Manager, and browse down to Default Web Site, then Right-Click and add Virtual Directory. You may also have to install some modules for iis (under windows Control Panel -> Applications & Features -> Turn features on -> iis-> www -> Appl-> CGI etc)
If Apache add *.cgi, or *.pl as a handler, as described in e.g. http://www.thesitewizard.com/archive/addcgitoapache.shtml
Best wishes!

Related

How can you run a config script when installing a perl module?

I've been searching for a couple of hours and I'm coming up empty trying to find a solution. I'm using Dist::Zilla. I have a module that uses a simple config file in .ini format located in the module's share/ directory. When my module is installed, I'd like the install script to prompt the user for configuration options and save the user's options in the config file. Then, using File::UserConfig, it will copy the file over to the user's configuration directory where it can be loaded by the module when it runs.
Someone had suggested the Dist::Zilla::Plugin::MakeMaker::Custom module but I know next to nothing about MakeMaker and how I might write a custom one to kick off the configuration script.
I'm surprised I can't find anything that makes this easy to do. Perhaps I'm searching on the wrong keywords?
You had discussed this in IRC, and the gist is:
You cannot rely on the installation process allowing any interaction, as a large amount of installations are via cpanm which is non-interactive and hides output from Makefile.PL by default. This is because users don't like having to configure things, and as an example, a Carton deployment is frequently non-interactive by its nature. You can allow configuration via environment variables recognized by your Makefile.PL to get around this.
You can document to install using the --interactive option for cpanm in order to respond to prompts in your Makefile.PL, injected into the generated file using the [MakeMaker::Awesome] plugin.
You can include a script with the distribution that will set up the configuration so the user can do it themselves separate from the installation.

Newbie: How to make .pl file executable?

I don't know anything about PERL first of all. I know very limited html. My assignment is to upload a .pl file (provided to me) to my cg-bin dir on my web server, then make the file executable. I had to manually create a cgi-bin dir into my public_html dir. I uploaded the .pl file. How do I make it executable?
chmod a+rx /path/to/your/file.pl
You may want to check out the chmod man page as well. Just type
man chmod
in your terminal.
Manually creating the cgi-bin directory probably isn't going to work. The web server needs to be configured to recognise the directory as well. And we can't help you with that as we don't know which web server you are using.
As others have said, you will need to chmod
Also (depending on webserver, which you haven't tolYou need to put the path to your Perl executable in the first line of your script:
#!/bin/perl
This will be particular to your server though - you'll need to ask your admin or teacher what it should be for you.

Setting up Zend Framework CLI tool on OS X 10.7 Lion

I have been fighting to set up Zend Framework's CLI tool on OS X for ages. I have followed the manual, but I can't get it to work.
The most common setup in the *nix environment, is to copy the zf.sh
and zf.php into the same directory as your PHP binary.
[...]
To find out the location of your PHP binary, you can execute 'which
php' on the command line. This will return the location of the PHP
binary you will be using to run PHP scripts in this environment.
When I do this, it says /usr/bin/php. So, I have put zf.sh and zf.php into /usr/bin.
Now, the next step is where I get really confused.
The next order of business is to ensure that Zend Framework library is
set up correctly inside of the system PHP include_path. To find out
where your include_path is located, you can execute php -i and look
for the include_path variable, or more succinctly, execute php -i |
grep include_path. Once you have found where your include_path is
located (this will generally be something like /usr/lib/php,
/usr/share/php, /usr/local/lib/php, or similar), ensure that the
contents of the /library/ directory are put inside your include_path
specified directory.
Running php -i | grep include_path returns include_path => .: => .:, which I am not really sure what means (I am new to *nix). I have tried to copy the contents of the library folder to /usr/share/php/, but without luck.
So I guess my problem is figuring out where my include path is so I can put the contents of the library folder there. I figured I would find my php.ini. When I run phpinfo() from a script, it says that my php.ini is located at /etc, but there is no php.ini in that folder. Also, executing php -i shows the following:
Configuration File (php.ini) Path => /etc
Loaded Configuration File => (none)
I guess my PHP is running with default settings since no config file is loaded. I am testing from the terminal with zf show version and get -bash: zf: command not found.
I am really, really confused!
I had similar problems once. If i remember correctly i was using WAMP and it had multiple php.ini files (3 i think), i had to track down the right one.
i followed this tutorial and it worked for me
http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf
hope it helps

Perl file extension

We have few files which don't have the standard perl extension like cgi etc.
Couple of them end with *.cfm and have perl code in them.
Now i am not sure why the developer decided to use a coldfusion extension and decide to use perl in it, but we are at a point now where we cannot alter the filename and we need to make some configuration changes such that perl is able to render *.cfm files too.
Is there a way we can modify the perl configuration to accept *.cfm files and render them as perl scripts?
I'll go out on a limb and guess that your actually asking about running ".cfm" files as CGI scripts, through Apache. In that case, you would use a "handler" to tell Apache to treat all *.cfm files as Perl scripts. If I've guessed what's going on, then add this to your Apache 2.2 configuration:
AddHandler cgi-script .cfm
Also, make sure the Perl scripts have the right "shebang" line on the first line, usually:
#!/usr/bin/perl
If you want some *.cfm files to be still be treated as Cold Fusion, then you'll need a different solution.

How do I specify the Perl include path for a Catalyst fastcgi process?

i have installed all my dependencies for Catalyst in ~/perl5/lib/perl5 using local::lib
I want to run my app under Apache2 using mod_fcgid, but the fastcgi perl script cannot find the modules in my custom path. How can I specify that (apache config?) my custom lib dir is to be included in the INC directory without explicitly hacking it into myapp_fastcgi.pl? I want to be able to move my app between servers that have the perl includes installed in different directories.
Thanks,
Rob
You can set the environment variables with DefaultInitEnv. You probably want something like this, but with your regular includes too,
DefaultInitEnv PERL5LIB /home/rob/perl5/lib/perl5
You can also do things like setting your app config like that too,
DefaultInitEnv APPNAME_CONFIG /srv/app/appname.conf