Run cgi file browser




















Connect and share knowledge within a single location that is structured and easy to search. I am new to apache2 and I am learning to execute a cgi file using Mac OS. But I have a problem for using a cgi file. I can run it in terminal but can't run it in the browser. For details :. Does it mean that I didn't ebale the cgi module? What a "great job" by me.

In fact, I try to restart my Mac and restart apache2 and then it works I do try "sudo apachectl restart" every time after modification but it seems not work Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 1 year, 11 months ago. Active 1 year, 11 months ago. Viewed times. It contains the configuration directives that give the server its instructions.

Do NOT simply read the instructions in here without understanding what they do. They're here only as hints or reminders. If you are unsure consult the online docs.

You have been warned. ServerRoot: The top of the directory tree under which the server's configuration, error, and log files are kept. Do not add a slash at the end of the directory path. For this discussion, I'm going to assume that you can run a CGI script in any directory in your Web space, as long as the script has a ". So let's copy the script to an appropriate directory, and change its extension to ".

Did you follow that? Trivia: The Unix mkdir command is the only one I can think of that is actually longer than the equivalent DOS command, "md". I chmodded the directory to permissions , then used the "cp" command to copy hello. Then I used the "cd" command to change to that directory, and used the "mv" command to change the file's name from "hello. A couple of additional things about directories and Web space and so on: My Unix command prompt has been customized to show my current directory; if yours hasn't, you can use the command "pwd" to list the current directory any time you lose track.

Before we try to run the script via the Web server, let's try running it from the command line, just to make sure everything works the way we want it to:. Did you get that?

If not, what happened? Did you get a "permission denied" error, by any chance? Then check your permissions: You probably lost the "execute" permission somewhere along the way. Assuming your script did print out from the command line, let's go to the final step: testing the script via the Web server. In my case, that means typing the following into my Web browser's Location box:.

Whatever it is, go ahead and try it. The dreaded "internal server error". You will see messages like this a lot when you are learning to run CGI scripts. It sure would be helpful if you could see that error message.

Fortunately, since your ISP is enlightened enough to let you run your own CGI scripts, they're almost certainly enlightened enough to give you access to the Web server's error log. But if it's a script using a language like Perl, the server needs to know where to find the Perl program. This is the function of the first line of the file. For example:! The first two characters,!

But in some rare instances, things are configured differently, and you need to edit this first line to point to a valid program to run. The file needs to have an executable extension NT only In the Windows NT world, execute permissions don't exist, and the shebang doesn't apply.

So you don't need to worry about using chmod on servers running Windows NT, and you can ignore the first line of the file. What you do need to be concerned about, however, is the file extension. Windows decides which program to open a file with based on its extension. If you want to run a perl script on NT, for example, you need to give it an extension of. The program needs to return a valid response Any CGI program that runs must return a valid response to the browser. However, if the program encounters a problem while running and dies, it could output an error message.

But in the Web world, the program needs to hand its response back to the Web server, which then packages it to send back to the browser. If the program outputs an error message, the Web server does not get the response it expects and instead returns a general error error, for example back to the browser, saying there was a problem running the program.

How does a CGI script actually work? Now that you understand how things need to be set up, it's a good time to step through the whole process and see exactly what happens when a CGI script is run. The server recognizes that. It checks to make sure that CGI programs are allowed to run on the server.

The server launches a sub-process to run the program in the operating system. The operating system opens the file and looks at the first line to see which program to use with the script.

It runs this program and passes it the filename to run. The script runs, does whatever it needs to, and then returns an HTML response, using print statements, for example. The whole response is passed back to the server, which then packages it in an HTTP response, including content length, etc.

The server passes the whole response back to the browser, which displays it. Of course, that whole process doesn't always go as planned, and there are some things that can stand in the way of your program running correctly. Like what, you ask? File permissions When the Web server launches a sub-process to run the program step 5 above , it performs a trick: It changes the User ID to one with very little or no permissions.

This is done for security purposes and prevents others from writing a script that overwrites important files by accident or deletes whole directory trees.



0コメント

  • 1000 / 1000