next up previous
Next: Directory for CGI data Up: Example Previous: CGI directory

Private development directory

It is unwise, for several reasons, to edit CGI scripts directly in the cgi-bin directory. One reason is that text editors often keep backup files around. If you find a huge security hole in one of your CGI scripts and patch it, the backup file, still containing the hole, may still be around for anyone to use who knows or can guess its name. Another reason is that while improving a working CGI program, you might temporarily introduce a bug that causes it to fail. If you have told other people about your program in its previous form, they might access the broken version and form a bad opinion of your CGI programming skills. By doing the development in a separate, private directory, you can debug the program before publishing it in the public space.

So, now return to your home directory and create a private area for program development.

  ~/public_html/> cd
  ~/> mkdir private
  ~/> chmod go-rwx private
  ~/> ls -ld private
  drwx------    2 joeuser   students      1024 Sep  4 17:45 private

Since you are probably taking other courses besides the CGI class, it is best not to put your work files in this directory itself. Instead, to keep things organized, you should create a different subdirectory for each class you are taking. For the CGI class, create a directory called cgi. Note that it is not necessary to give this directory any special permission, since it is protected simply by being within the private directory.

  ~/> cd private
  ~/private/> mkdir cgi
  ~/private/> ls -ld cgi
  drwxr-xr-x    2 joeuser   students      1024 Sep  4 17:46 cgi
Now, to work in this directory, do cd cgi and run pico or another text editor to create and modify program scripts and source files.

One more step is done solely for convenience. After creating and debugging a CGI program in the private/cgi directory, you will want to copy it over to the public_html/cgi-bin directory. Since these two directories are rather widely separated in your directory tree, it will be convenient to create a symbolic link to make it easy to do the transfer. A symbolic link is a special file that ``points'' to some other location. References to the link are resolved into references to the place it points to. Here is how to do it:

  ~/private/> cd cgi
  ~/private/cgi/> ln -s ../../public_html/cgi-bin bin
  ~/private/cgi/> ls -l bin
  lrwxrwxrwx    1 joeuser   students        12 Sep  4 17:48 bin -> ../../
  public_html/cgi-bin
Now, if a CGI program, say hello.pl, is created in the private/cgi directory, you can ``publish'' it by copying it to the bin directory, which will really be public_html/cgi-bin:
  ~/private/cgi/> cp hello.pl bin
This saves you the trouble of typing ../../public_html/cgi-bin as the destination directory each time you do this operation.


next up previous
Next: Directory for CGI data Up: Example Previous: CGI directory
Robert Moniot
2000-09-13