This is a personal memo for a complete beginner of the CGI program. This is my first time writing an article like this, so I think it may be unsightly, but please forgive me. If you have any advice or suggestions, I would appreciate it if you could comment.
I want to execute and test a CGI program written in Ruby in a local server environment.
The HTTP server of Apache is used as the server.
How to use AN-HTTPD (Reference: http://www.aikis.or.jp/~s-suzuki/cgilabo/localserver/) There seems to be some, but the URL of the source is dead. It seems that you can download it from the archive (Reference: https://www.nishishi.com/blog/2019/02/an_httpd_waybac.html) However, I tried it but it didn't work.
It's not related to this motivation, but I included Perl in the CGI program because it seems to be a standard (that's right).
Download the latest version (5.28.1) from the ActivePerl site (https://www.activestate.com/)
Sign In (Login required / Login with GitHub account is possible) -> Featured Projects & Languages -> Windows in the frame of ActivePerl 5.28 -> Click on Windows10 .msi ʻActivePerl-5.28.1.0000-MSWin32-x64-b462fde1.msi` Download and install
☆ During installation Setup Type is Typical In Setup Options, With "Add Perl to the PATH environment variable" Check "Create Perl file extension association". (Reference: https://www.hiskip.com/pg-notes/how-to-install/develop-kit/active-perl526.html)
After installation, a directory called Perl64
will be placed under C: (C: \ Perl64
).
From RubyInstaller (https://rubyinstaller.org/downloads/) Download the latest version (2.7.1-1)
Download and install rubyinstaller-2.7.1-1-x64.exe
☆ During installation For the same reason as in Perl "Add Ruby exexutables to your PATH" Check "Associate .rb and .rbw files with this Ruby installation".
After installation, a directory called Ruby27-x64
will be placed under C: (C: \ Ruby27-x64
).
From the Apache HTTP server download site (http://httpd.apache.org/download.cgi) Download the latest version (2.4.43)
Apache HTTP Server Server 2.4.43 (httpd): 2.4.43 is the latest available version
-> Files for Microsoft Windows
-> Apache Lounge (Specify download destination, anything is fine)
-> httpd-2.4.43-win64-VS16.zip
Download and unpack
After unpacking, you will find a directory called ʻApache24under the directory
httpd-2.4.43-win64-VS16. You can do it, so put it under C: (
C: / Apache24`).
ʻApache24 / conf / http.conf` is the Apache (httpd) configuration file. Edit this. Below, edit points
#CGI execution location setting ScriptAlias /cgi-bin/ "C:/Apache24/cgi-bin/"
# Allow execution of CGI <Directory "C:/Apache24/cgi-bin"> AllowOverride All Options Indexes FollowSymLinks ExecCGI Require all granted </Directory>
# Enable the use of .cgi and .pl .rb extensions AddHandler cgi-script .cgi .pl .rb
# Ver2 that enables the use of .cgi and .pl .rb extensions AddType application/x-httpd-cgi .cgi AddType application/x-httpd-cgi .pl AddType application/x-httpd-cgi .rb
(Reference 1: https://phpjavascriptroom.com/?t=php&p=cgi#google_vignette) (Reference 2: https://qiita.com/hirotoyoshidome/items/6d103e04dd07e90519d2) The top two are special thanks
Click here for the difference between AddHandler and AddType (https://senooken.jp/post/2019/06/01/)
ʻApache24 / bin / httpd.exe` can be executed to start Apache's HTTP server.
I couldn't run httpd.exe
and referred to (http://t12488mac.blogspot.com/2011/06/windowsapache.html).
If you hit httpd.exe -t
in the ʻApache24 \ bin directory He told me, "There is a bad description in
httpd.conf` and I can't execute it ~ ".
When I fixed it, it was fixed (naturally)
CGI program Place it under ʻApache24 / cgi-bin`.
--The following description on the first line of ruby's CGI program
#!/Ruby27-x64/bin/ruby
Or
#!C:/Ruby27-x64/bin/ruby
--Perl's CGI program has the following description on the first line
#!/perl64/bin/perl
Or
#!C:/Ruby27-x64/bin/ruby
When you reach a state that satisfies the following three conditions, you can finally display it on your browser.
--Apache's httpd.conf
has been properly edited
--Apache HTTP server started (httpd.exe
executed)
--ʻA state where some CGI program (**. Cgi
) is placed under Apache24 / cgi-bin`
In the URL bar of your browser
http://127.0.0.1/cgi-bin/**.cgi
Or
http://localhost/cgi-bin/**.cgi
If you enter, the page you wrote will be displayed on the browser.
This completes the operation in the local server environment.
The directory layout related to the one introduced in this article is shown below.
C:/ ├ Perl64 │ ├ bin │ │ ├ Perl.exe │ : : │ ├ Ruby27-x64 │ ├ bin │ │ ├Ruby.exe │ : : │ ├ Apache24 │ ├ bin │ │ ├ httpd.exe │ │ : │ │ │ ├ conf │ │ ├ httpd.conf │ │ : │ │ │ ├cgi-bin │: └ **. Cgi (self-made CGI file) │ : ::
While groping, I was able to test a CGI program written in Ruby in a local server environment. tired.