{"id":1972,"date":"2013-02-06T19:21:11","date_gmt":"2013-02-06T10:21:11","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=1972"},"modified":"2018-11-14T16:33:56","modified_gmt":"2018-11-14T07:33:56","slug":"bash%e3%81%a7cgi-1-apache%e3%81%ae%e8%a8%ad%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/02\/06\/bash%e3%81%a7cgi-1-apache%e3%81%ae%e8%a8%ad%e5%ae%9a\/","title":{"rendered":"bash\u3067CGI (1) Apache\u306e\u8a2d\u5b9a"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01\u300c\u6e29\u6545\u77e5\u65b0\u300d\u304c\u30de\u30a4\u30d6\u30fc\u30e0\u306b\u306a\u3063\u3066\u3044\u308b\u3001\u6cb3\u91ce\u3067\u3059\u3002<\/p>\n<p>\u65e9\u901f\u3001\u4eca\u56de\u306fCGI\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(bash)\u3067\u4f5c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u305cperl\u3058\u3083\u306a\u304f\u3066bash\u306a\u306e\u304b\u3068\u3044\u3046\u3068\u3001\u79c1\u304cperl\u3092\u826f\u304f\u77e5\u3089\u306a\u3044\u304b\u3089\u3067\u3059(^^;<br \/>\n\u3067\u3082\u3001\u65e5\u5e38\u7684\u306b\u4f7f\u3063\u3066\u3044\u308b\u30b3\u30de\u30f3\u30c9\u3067\u7d44\u307f\u7acb\u3066\u307e\u3059\u306e\u3067\u3001\u7c21\u5358\u3060\u3068\u601d\u3044\u307e\u3059\uff01\u305f\u3076\u3093\uff01<\/p>\n<h2>CGI\u306b\u3064\u3044\u3066\u304a\u3055\u3089\u3044<\/h2>\n<p>CGI\u3068\u3044\u3046\u5358\u8a9e\u3092\u6570\u5e74\u3076\u308a\u306b\u4f7f\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u5ff5\u306e\u305f\u3081\u306b\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>CGI \u3068\u306f\u3001HTTP\u30b5\u30fc\u30d0\u3068\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u3053\u3068\u3067\u3059\u3002Common Gateway Interface\u306e\u7565\u3067\u3059\u3002CGI\u306b\u5247\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u3053\u3068\u3092CGI\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u8a00\u3044\u307e\u3059\u304c\u3001\u305d\u308c\u3082\u542b\u3081\u3066CGI\u3068\u8a00\u3046\u3053\u3068\u304c\u591a\u304b\u3063\u305f\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3056\u3063\u304f\u308a\u8a00\u3046\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6c7a\u307e\u308a\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>HTTP\u30b5\u30fc\u30d0\u30fc\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u5185\u5bb9\u306b\u5fdc\u3058\u3066\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5f15\u6570\u30fb\u74b0\u5883\u5909\u6570\u30fb\u6a19\u6e96\u5165\u529b\u3092\u8a2d\u5b9a\u3057\u3001\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8d77\u52d5\u3059\u308b<\/li>\n<li>\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u53d7\u3051\u53d6\u3063\u305f\u60c5\u5831\u3092\u3082\u3068\u306b\u51e6\u7406\u3092\u884c\u3044\u3001\u7d50\u679c\u3092\u6a19\u6e96\u51fa\u529b\u3059\u308b<\/li>\n<\/ol>\n<p>CGI\u306b\u3064\u3044\u3066\u306e\u8a73\u7d30\u306f\u3001RFC3875\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/tools.ietf.org\/html\/rfc3875\" target=\"_blank\">http:\/\/tools.ietf.org\/html\/rfc3875<\/a><\/p>\n<h2>Apache\u306e\u8a2d\u5b9a<\/h2>\n<p>\u4eca\u56de\u306fApache\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002Apache\u306e\u8a2d\u5b9a(httpd.conf\u306a\u3069)\u3067\u4ee5\u4e0b\u306e3\u70b9\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>1.CGI\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u6709\u52b9\u306b\u3059\u308b<\/h3>\n<pre class=\"lang:apache decode:true\">LoadModule cgi_module modules\/mod_cgi.so<\/pre>\n<p>\u6a19\u6e96\u8a2d\u5b9a\u306e\u307e\u307e\u3060\u3068\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<h3>2.CGI\u306e\u30cf\u30f3\u30c9\u30e9\u3092\u8a2d\u5b9a\u3059\u308b<\/h3>\n<pre class=\"lang:apache decode:true\">AddHandler cgi-script .cgi<\/pre>\n<p>\u3053\u308c\u306f\u6a19\u6e96\u8a2d\u5b9a\u3060\u3068\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\uff08\u3053\u306e\u8a2d\u5b9a\u3092\u6570\u5e74\u3076\u308a\u306b\u884c\u3044\u307e\u3057\u305f\u2026\uff09<\/p>\n<h3>3.CGI\u306e\u5b9f\u884c\u3092\u8a31\u53ef\u3059\u308b<\/h3>\n<pre class=\"lang:apache decode:true\">&lt;Directory \/var\/www\/html&gt;\r\n  Options Indexes FollowSymLinks ExecCGI\r\n  ...<\/pre>\n<p>Directory\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306a\u3069\u306eOptions\u3067ExecCGI\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h2>CGI\u7528\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6e96\u5099<\/h2>\n<p>\u4f5c\u696d\u3092\u9032\u3081\u308b\u305f\u3081\u306b\u3001\/var\/www\/html \u306e\u4e0b\u306b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u3063\u3066\u3001\u30a2\u30af\u30bb\u30b9\u6a29\u9650\u306a\u3069\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4f5c\u696d\u3082\u76f4\u63a5\u3053\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3084\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:sh decode:true\">$ sudo mkdir -m 777 -p \/var\/www\/html\/bash-cgi\r\n$ sudo chown kawano:kawano \/var\/www\/html\/bash-cgi\r\n$ cd \/var\/www\/html\/bash-cgi<\/pre>\n<h2>\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<p>\u3068\u308a\u3042\u3048\u305a\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\uff01<\/p>\n<pre class=\"lang:sh decode:true\" title=\"helloworld.sh\">#!\/bin\/bash\r\n# helloworld.cgi\r\n\r\n# \u304a\u307e\u3058\u306a\u3044\r\necho \"Content-type:text\/plain\"\r\necho\r\n\r\n# \u5185\u5bb9\r\necho \"Hello World\"<\/pre>\n<p>\u203b\u300c\u304a\u307e\u3058\u306a\u3044\u300d\u306e\u3068\u3053\u308d\u3068\u3001\u6539\u884c\u30b3\u30fc\u30c9\u306b\u3064\u3044\u3066\u306f\u6b21\u56de\u4ee5\u964d\u306b\u8aac\u660e\u3092\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>cgi\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u5358\u4f53\u3067\u5b9f\u884c\u3067\u304d\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u5b9f\u884c\u6a29\u9650\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:sh decode:true\">$ chmod +x helloworld.cgi<\/pre>\n<h3>\u5358\u4f53\u3067\u5b9f\u884c\u3067\u304d\u308b\u304b<\/h3>\n<pre class=\"lang:sh decode:true\">$ .\/helloworld.cgi\r\nContent-type:text\/plain\r\n\r\nHello World<\/pre>\n<h3>curl\u3067\u78ba\u8a8d<\/h3>\n<pre class=\"lang:sh decode:true\">$ curl http:\/\/localhost\/bash-cgi\/helloworld.cgi\r\n\r\nHello World<\/pre>\n<p>\u3061\u3083\u3093\u3068\u52d5\u3044\u305f\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3067CGI\u304c\u52d5\u4f5c\u3059\u308b\u74b0\u5883\u304c\u3067\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u6b21\u56de\u304b\u3089RFC\u3092\u53c2\u8003\u306b\u3057\u306a\u304c\u3089\u3001CGI\u306e\u4ed5\u7d44\u307f\u306b\u3064\u3044\u3066\u7406\u89e3\u3092\u6df1\u3081\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01\u300c\u6e29\u6545\u77e5\u65b0\u300d\u304c\u30de\u30a4\u30d6\u30fc\u30e0\u306b\u306a\u3063\u3066\u3044\u308b\u3001\u6cb3\u91ce\u3067\u3059\u3002<\/p>\n<p>\u65e9\u901f\u3001\u4eca\u56de\u306fCGI\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(bash)\u3067\u4f5c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2013\/02\/06\/bash%e3%81%a7cgi-1-apache%e3%81%ae%e8%a8%ad%e5%ae%9a\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[86,18],"tags":[87,88],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1972"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=1972"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1972\/revisions"}],"predecessor-version":[{"id":17960,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1972\/revisions\/17960"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=1972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=1972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=1972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}