LoginSignup
20
21

More than 5 years have passed since last update.

ubuntu16.04のApache2設定/cgi設定

Last updated at Posted at 2016-11-16

Apacheのインストール・設定

(参考) http://tobysoft.net/wiki/index.php?Ubuntu%2Fapache2

$ sudo apt-get install apache2
$ apaches -v
Server version: Apache/2.4.18 (Ubuntu)

/etc/apache2/apache2.confやhttpd.confは使わない.
(設定ファイルの場所が結構変わっている)

設定フォルダ 設定内容
/etc/apache2/site-available サイト設定を 000-default.confをもとに新規作成
/etc/apache2/conf-available 必要に応じてsecurity.confなどを修正
/etc/apache2/mods-available モジュール設定はここ
/etc/apache2/site-enabled a2ensite/a2dissiteで設定が反映/削除
/etc/apache2/conf-enabled a2enconf/a2disconfで設定が反映/削除
/etc/apache2/mods-enabled a2enmod/a2dismodで設定が反映/削除
/etc/apache2/port.conf port変更の設定はここ? ``(Listen 8080など)

サイト設定でまとめてCGI設定などもするのが吉?
cgi-binフォルダは公開フォルダ(html下)に置かないこと (参考)

/etc/apache2/site-available/xxxx.conf
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddHandler cgi-script .cgi .py

<Directory "/var/www/cgi-bin">  
        AllowOverride None
        Require all granted
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
</Directory>
$ a2ensite xxxx.conf
$ sudo service apache2 reload

注意
- ubuntu16.04では,apach2は "www-data" のuser idで動作している. (apacheやhttpdではない)
- apache2ctl status を出すためには lynxを入れること. (無いとwww-browser: not found で怒られる)

CGIでpoweroffを実行する (root権限で実行する)

(参考) http://changineer.info/server/centos_basic/sudoers.html

/etc/sudoers.d に設定を追加することで,apache (www-data) から,poweroffが実行可能

/etc/sudoers.d/apache
Defaults:www-data !requiretty
Cmnd_Alias POWEROFF = /sbin/poweroff
www-data ALL = (ALL) NOPASSWD: POWEROFF
www-data ALL = (ALL) NOPASSWD: /sbin/reboot
  • /etc/sudoers の最後で "#includedir /etc/sudoers.d" が有効なことを確認すること (頭に#がついているが,コメントではない)

(参考)apachのCGI設定
http://qiita.com/YasuyukiKawai/items/231821dd22a72194b3fb

  • documentrootの下にcgi-binを置かない

(参考)apache2.4系はアクセス許可の設定の書き方が違うので注意
https://www.softel.co.jp/blogs/tech/archives/3142

  • cgi-binのScriptAliasは conf-available/serve-cgi-bin.conf でも設定されているので,site.confで設定する場合,a2disconf serve-cgi-bin で停止.

PHPのインストール

$ sudo apt-get install php
$ sudo apt-get install libapache2-mod-php

ブラウザからphpが動作するか確認.

/var/www/html/info.php
<?php
    phpinfo();
?>

設定ファイルは /etc/php/7.0/apache2/php.ini

20
21
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
20
21