LoginSignup
0
2

More than 3 years have passed since last update.

Apache2でcgiを機能させるまで

Last updated at Posted at 2020-07-05

環境

  • WEBサーバー: Apache2
  • OS : Ubuntu

cgiモジュールのインストール

cgidインストール

$ sudo apt install cgid

cgi設定の確認

$ cd /etc/apache2/conf-available
$ ls 
#serve-cgi-bin.confに設定が書いてある
harset.conf  localized-error-pages.conf  other-vhosts-access-log.conf  security.conf  serve-cgi-bin.conf
serve-cgi-bin.conf
<IfModule mod_alias.c>
        <IfModule mod_cgi.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfModule mod_cgid.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfDefine ENABLE_USR_LIB_CGI_BIN>
                #URLで/cgi-bin/以下のファイルが/usr/lib/cgi-bin配下のファイルと結びつく
                ScriptAlias /cgi-bin/ "/usr/lib/cgi-bin/"
                <Directory "/usr/lib/cgi-bin">
                        AllowOverride None
                        #+ExecCGIがオプションとして書かれているのでCGIが動く
                        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                        Require all granted
               #.cgiの拡張子がつくファイルがcgiスクリプトが書かれているファイルであることを設定
                        AddHandler cgi-script .cgi
                </Directory>
        </IfDefine>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

cgiファイルを設置

$ cd /usr/lib/cgi-bin
$ vi hello.cgi
hello.cgi
#!/bin/bash

echo "Content-Type: text/html;charset=utf-8\n"
echo ""
echo '<html><body>Hello cgi.</body></html>'

ファイルのパーミッションにて実行権限をつける

$ sudo chmod 755 hello.cgi

確認

スクリーンショット 2020-07-05 11.47.26.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2