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.
Related
Perl newbie here with very little time and support to learn Perl but all the expectations from management to use it like a Perl Pro :)
I am using Perl (v5.30.2 by Larry Wall) under Cygwin (windows 10)
My developer issued a new script, that now uses a Perl module I didn't have.
They then sent me the .pm file (which they authored themselves and it is not on any online Perl repo).
I was unable to use CPAN to install that file into my Perl execution environment.
Where should the .pm file be saved at? (please specify the exact folder)
How to tell CPAN to install this file for usage? Ideally, a one-time affair, as I don't want to forget installing this file, if I have to do that every time I need to run the Perl script...
Just in case there may be any security concern from the dear answer-ers: There isn't any security concern here, this is all under an environment that has no connection to the internet.
A Perl module is just a file (or collection of files). You don't have to put them anywhere special, but you need to tell Perl where to find them.
When you call use or require with a bareword, Perl translates that module name, like Some::Module, into Some/Module.pm (or whatever is appropriate for your system. Anyone still using VMS?).
Once it has the filename form of the module, it looks for that subpath in the directories in #INC. It tries the first directory. If it doesn't find it it moves on to the next, and so on down the line. These directories are decided when someone configures and installs Perl. And, before v5.26, it included the current working directory (see v5.26 removes dot from #INC and Doesn't Perl include current directory in #INC by default?
)
But, you can tell Perl where else to look. perlfaq8 has How do I add a directory to my include path (#INC) at runtime?. ikegami also showed FindBin in the comments (How do I add the directory my program lives in to the module/library search path?).
Beyond that, you can tell require to load a path, although you then need to ensure that the program can find that path even if someone runs it from another directory
require './this_file/over/here';
require '/usr/local/lib/this_file/over/here';
I have a Perl app on my development server that I would like to replicate on my local machine (mac osx). I'm not a perl programmer by trade (I'm a PHP/Rails developer), and the developer of this app is no longer around so I can't contact him for help. I've gotten pretty close to getting it to work. I was able to install all the packages using CPAN (at least I think I got them all) but I keep running into the following error:
Can't locate WebCNP/Config.pm in #INC (
#INC contains: /Library/Perl/5.16/darwin-thread-multi-2level
/Library/Perl/5.16
/Network/Library/Perl/5.16/darwin-thread-multi-2level
/Network/Library/Perl/5.16
/Library/Perl/Updates/5.16.2/darwin-thread-multi-2level
/Library/Perl/Updates/5.16.2
/System/Library/Perl/5.16/darwin-thread-multi-2level
/System/Library/Perl/5.16
/System/Library/Perl/Extras/5.16/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.16 .
)
at webcnp_lib.pl line 30.
On the server, the app's file structure looks like this:
/var/www/cgi-bin (empty dir)
/var/www/conf
/var/www/error
/var/www/html (empty dir)
/var/www/icons
/var/www/perl (the config file is located in this directory)
- /WebCNP/Config.pm
/var/www/ssi (all the .pl files for the app are located here, including all the JS and CSS files)
Line 30 of /var/www/ssi/webcnp_lib.pl has the following:
use WebCNP::Config;
Any ideas what I could be doing wrong?
Just so you know I've copied the file structure of the app from my development server to my local machine and created a virtual host so that it points to the app's root directory (/var/www).
Thanks in advanced for any insight!
was able to fix this with a symbolic link
ln -s /path/to/my/app/WebCNP /Library/Perl/5.16/WebCNP
I take this isn't a module from CPAN.
I would be a bit hesitant to use a symbolic link. This will work, but you're basically linking in a file you have under your own control to the master /Library directory on MacOS X. You delete your file, and that link won't be pointing to anything.
You can use use lib to add directories that contain your modules to the #INC directory:
use lib qw(/path/to/my/app);
This will now include this path for module searches.
If you rather install the module itself, why not simply copy it into /Lbrary/Perl/5.16 itself? It's what cpan would have done. At least this way, you're Perl module directory isn't dependent upon a link that can be removed.
/var/www/perl isn't present in #INC, so Perl won't look there. The most common approach to solve this for CGI scripts would be to add the following to your scripts (but not modules):
use FindBin qw( $RealBin );
use lib "$RealBin/../perl";
I was able to fix this with a symbolic link
ln -s /path/to/my/app/WebCNP /Library/Perl/5.16/WebCNP
Not sure if this is the most elegant approach, but seems to work well for this app. Thanks everyone for your replies! This has been very insightful.
Old post, I know, but there is a much more portable way. When you install the modules, you need to do two things.
Add the installation path to PERL5LIB (i.e. PERL5LIB=$PERL5LIB:/My/Module/Path/lib) in your environment configuration (.profile or other files which get read on system initialization)
Add a PREFIX to your perl Makefile.PL call (perl Makefile.PL PREFIX=/My/Module/Path)
It goes without saying that you need to make certain your Makefile.PL is written correctly.
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!
I am developing a Meego/Harmattan application, in my package there is a file x.dat that I need to write in it using my executable foo app, the Debian package succeeds and installs x.dat in /opt/foo/bin but when I debug, the application foo refuse to fopen the file successfully for a subsequent fwrite, Is this related a missing Aegis manifest entry?, what is the correct sentence of that entry and is it done manually?
Note: I tried without success to use different path for the installation of the data file x.dat, this includes trying /home/user.
Thanks in advance,
Your application does not have permission to write to /opt as it is run as user. You have to put the file in /home/user/.yourapp/ and chown it to user:user in the postinstall script. (You could also chown the file right in /opt but it is not recommended)
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)