Apache2でbashを利用できるようにする

2017/04/18

Apache2

t f B! P L
目的:Apache2+UbuntuでCGIを動かすこと

【各環境情報】

[Apache2]:$apache2 -v
参考URL:https://goo.gl/S1A4Da
Server version: Apache/2.4.18 (Ubuntu)
Server built:   2016-07-14T12:32:26

[Ubuntu]:$ cat /etc/lsb-release
参考URL:https://goo.gl/oWtKVN
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

[Bash]:$bash --version
bash --version
GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

【手順】

①Apacheモジュールを有効可する
有効化対象は、cgid。
$ sudo a2enmod cgid

②mime.confを編集し、拡張子「.cgi」がcgi-scriptをして処理されるよう設定する
$ cd /etc/apache2/mods-enabled/
$ sudo vi mime.conf

220行目付近にある
#AddHandler cgi-script を
  AddHandler cgi-script へ。

③設定ファイルを変更しCGIを有効化する設定とする

################
<Directory "/var/www/html">
                AllowOverride All
                Options ExecCGI Multiviews Indexes IncludesNoExec
        </Directory>
################
↑が、CGIを有効化するおまじない

編集ファイルの場所:/etc/apache2/sites-available/000-default.conf

[編集後]

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        <Directory "/var/www/html">
                AllowOverride All
                Options ExecCGI Multiviews Indexes IncludesNoExec
        </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

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

④文法チェック
$ apachectl configtest

⑤再起動
$sudo service apache2 restart


このブログを検索

フォロワー

QooQ