Win32 Apache, Perl Environment

zhaozj2021-02-08  224

Can be reprinted on the Internet, keep the author's name to retain other rights

This article will talk about

Apache and perl under Windows98se.

The content involved has the installation of Apache and Perl under Windows98SE, and confirming that they are working properly.

If you are already Apache and Perl users and are not interested in Apache and Perl under Windows98SE.

Please skip this article.

Some of the methods mentioned herein have passed verification on my machine, but it is not excluded from other systems.

Often work.

Like you, I am also an initiator of Perl, a very casual opportunity to start paying attention to Perl.

Just last month I started writing a small thing like a message board, there is a name of everyone and

A group of questions belonging to him. We have a VB written similar to the C / S structure, but he is too slow.

And other things are also incorporated. I have begun to consider using existing IIS Server and ASP.

I have consulted my friends around the ASP, they gave me a lot of suggestions, including using the Access database.

I think that I want it is a simple thing, but put it on the words you want to write,

Just like the message on the door of the company. So I started looking for CGI information.

============================================================================================================================================================================================================= ==================

CGI represents a common gateway interface (COMMON GATEWAY INTERFACE).

In essence, CGI is a program running on the server. It can be written in any language - as long as it is available

Run on your server.

============================================================================================================================================================================================================= ==================

This is great, I can use the language I are familiar with and the system platform I are familiar with. I think I just write one

Win32's executable, you can put it in a directory of IIS. It seems that it is much more complicated than this.

They told me to use UNIX and Apache, my feelings seem to be that CGI does not belong to a Windows system.

But it belongs to UNIX Linux.

I found the Win32 version of Apache, I am very happy, I think I can be in me again.

The familiar system is written with the language I are familiar with.

I think you can find its latest version at http://www.apache.org/.

You can also find Win32 can be run in http://httpd.apache.org/dist/binaries/win32/

The latest version.

I am using it.

http://httpd.apache.org/dist/binaries/win32/apache_1_3_12_win32.exe This is a installer similar to the installer of other Windows applications, there is nothing special place

The only thing to note is that when you choose the installation path, you should choose a short bit path, such as C: / Apache.

This is just for casual, and you choose a long path without any difference.

Apache installation is very simple, after installation, I made a unique modification about the configuration file.

/APache/conf/httpd.conf file

#Servername new.host.name row change to ServerName Matrix

You can use your favorite name, I use Matrix

You can use Apache now.

Enter http:// Matrix in your IE? If you can take a look at apache / htdocs

Directory, change index.html.en to index.html.en. If you still can't see you try your IP address

Like 192.12.199.123 or with http: // loaclhost. No, I can't do it.

Write CGI programs with your favorite language

The CGI program mentioned above is just a program that can run on your HTTP Server, basically you can use

Any programming language written. I used C to write the first program.

INT Main (int Argc, char * argv [], char * envp [])

{

Printf ("Content-Type: Text / HTML / N / N");

Printf ("Hello");

}

Compile this 5 sentences into an EXE file (assuming is hello.exe), double-click this file in Windows, you should play

open

A DOS window and output two sentences, like this

Content-Type: Text / HTML

Hello

Copy Hello.exe to Apache / CGI-BIN, then use IE to access

http://loaclhost/cgi-bin/hello.exe

Hello should appear in your IE. Try Hello.exe to Hello.cgi.

Simple, below is complicated.

How to accept parameters when using a Get Post method?

This is related to the Server you use, when you use apache for win32, the parameter of the get method can be from the input variable.

ARGV or environment variables have been obtained.

The POST method needs to read the standard input device.

INT Main (int Argc, char * argv [], char * envp [])

{

Printf ("Content-Type: Text / HTML / N / N");

For (i = 0; envp [i]! = null; i)

{

Printf (Envp [i]);

Printf ("
");

}

}

This program can display all of the environment variable content, copy to the CGI-BIN as above, and take a look.

Read standard input device: Scanf ("% s", & buf); like reading a keyboard. Of course, you should check the environment variable first.

Content_length achieves the correct parameter length.

The parameters you have got have some like this is like this.

http://loaclhost/cgi-bin/hello.exe? Name =% B7% C5% BA% 32% 65

The encoding method is% plus two hexadecimal numbers. The two hexadecimal number is the ASCII code of the character. Have a code

Used in decoding.

This is where c-editing CGI is very inconvenient, if it is Perl, it is simple.

C language

Bool Decode (LPTSTR LPSTR)

{

INT length = strlen (lpstr);

IF (length == 0) {

* lpstr = 0;

Return True;

}

Char * pstr = new char [Length 1];

ZeromeMory (PSTR, Length 1);

CHAR CH;

Char CH3 [3];

INT count = 0;

For (INT i = 0; i

IF (* (LPSTR i) == '%')

{

CH3 [0] = * (LPSTR I 1);

CH3 [1] = * (LPSTR I 2);

CH3 [2] = 0;

SSCANF (CH3, "% x", & ch);

* (PSTR count) = CH;

COUNT ;

i = 2;

}

ELSE IF (* (LPSTR I) == ' ') {

* (PSTR count) = '';

COUNT ;

}

Else {

* (PSTR COUNT) = * (LPSTR I);

COUNT ;

}

}

ZeromeMory (LPSTR, LENGTH);

STRCPY (LPSTR, PSTR);

delete [] PSTR;

Return True;

}

Perl language

######################################################################################################################################################################################################################################################################################################## ###################

# Change the URL Code to TEXT

# You can access the input data such as

# $ field {'Your ID'}

Sub formatit ()

######################################################################################################################################################################################################################################################################################################## ###################

{

MY (% Field, $ Name, $ Value, @pairs);

MY ($ in) = @_;

$ FIELD {'data'} = $ in;

@pairs = Split (/ & /, $ in);

Foreach (@PAIRS) {

$ _ = ~ s // / / g;

($ Name, $ Value) = split (/ = /, $ _);

$ Value = ~ s /% ([A-FA-F0-9] / PACK ("C", HEX ($ 1)) / EG;

$ Name = ~ S /% ([A-FA-F0-9] [A-FA-F0-9]) / PACK ("C", HEX ($ 1)) / EG;

$ FIELD {$ Name} = $ value;

}

Return (% Field);

}

It should be simple, at least the code is less.

Next, I started to say Perl ........

Run the Perl program under Windows

Perl is a scripting language, so you need a Perl interpreter.

On www.cpan.org you can find a variety of installation versions of Perl, including Win32 versions.

I downloaded a file called Perl5.00402-Bindist04-bc.zip.

The installation is complex than the installation apache. User does not provide the installation interface of the graphics, and use

The DOS text interface, the installer is a batch file.

First decompress the ZIP files you downloaded to a temporary directory, you can find install.bat

File, run him. The installer will ask you some questions, like the installation path, whether to install help files, and more.

Special, you will ask you if you have a C's compiler, I suggest you answer no, if you want to compile Perl from your new

Or make a modification, select YES and continue the installation according to the prompt.

I think you should be able to install it smoothly, let's try it.

Use your notebook or other text editing tool, enter the following Perl program #c: /perl/binperl.exe

Print "Hello Perl !!!";

Save this file on disk, get a name, such as Hello.pl

Open a DOS window now, run c: / perl / bin / perl hello.pl

Hello Perl !!!

Did you see the result?

If you haven't seen it, check it is wrong.

Ok, let's write a simple CGI program with Perl.

You may ask if you need to modify the following Apache configuration so that you can run Perl's CGI program.

No, your apache is ready :)

Write the following text, save it as hellocgi.pl

#! c: /perl/bin/perl.exe

Print "Content-Type: Text / HTML / N / N";

PRINT "Hello CGI";

The first sentence is used to indicate the location of Perl.exe.

Like the CGI we write before, copy hellocgi.pl to the cgi-bin directory of Apache.

Then access loaclhost / cgi-bin / hellocgi.pl.pl with IE. Did you see the result?

If not, check it out

1. Is it started Apache?

2. Is the PERL path correct?

Here's how to run Perl CGI on IIS

First installing the Perl interpreter is required, which is the same as that we have said above.

Then install IIS, I can only assume that you already have a Win2K and have already available IIS.

The following is just how IIS (IIS5.0) is set to run Perl.

1. From the "Start" menu -> "Administrative Tool" -> "Internet Service Manager"

2. New virtual directory or use existing directories (example: cgi-bin)

3. Open Directory Properties dialog

4. In Application Settings

4.1 "Additional" app (if not)

4.2 "Configuration" -> "App Mapping" -> "Add"

4.3 "Executable File" fills "c: /perl/bin/perl.exe% s% s" (your Perl installation path, pay attention% s% s

have to)

4.4 "Extended" Fill ".pl"

4.5 "OK"

5. "Permission": "Script and Executable Programs"

End.

Copy the top Hellocgi.pl to IIS (Example: CGI-BIN) directory

Try it with IE!

Ok, it is these.

转载请注明原文地址:https://www.9cbs.com/read-2175.html

New Post(0)