- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2017-11-08T20:26:52+09:00","default:wikiwriter","wikiwriter")
&tag(MacPorts/apache2);
*目次 [#ub3be697]
#contents
*参考情報 [#m9e28149]
-[[MacPorts]]
-[[MacPortsでApache2をインストール -- BONNOH FRACTION 13:http://www.fraction.jp/log/archives/2007/11/02/Leopard_de_Apache2]]
-[[./古い情報]]…Apache 2.2用の設定など。
*概要 [#v8a4f06b]
-2017/11/08(水)現在、ひさびさにapache2パッケージをインストールしたらapache 2.4.29がインストールされた。
-以下のように設定が変わっている模様。
#pre{{
---> Some of the ports you installed have notes:
apache2 has the following notes:
Apache2 has been migrated from the 2.2.x to the 2.4.x branch.
The install paths have been changed to no longer violate the MacPorts mtree:
1. The binaries are now under /opt/local/sbin/
(rather than under /opt/local/apache2/bin/)
2. The configure files are now under /opt/local/etc/apache2/
(rather than under /opt/local/apache2/conf/)
3. The modules are now under /opt/local/lib/apache2/modules/
(rather than under /opt/local/apache2/modules/)
4. The web root is now located under /opt/local/www/apache2/html/
(rather than under /opt/local/apache2/htdocs/)
5. The cgi-bin is now located under /opt/local/www/apache2/cgi-bin/
(rather than under /opt/local/apache2/cgi-bin/)
6. The logs are now located under /opt/local/var/log/apache2/
(rather than under /opt/local/apache2/logs/)
7. The manual is now located under /opt/local/www/apache2/manual/
(rather than under /opt/local/apache2/manual/)
8. The manual (man) pages are still at /opt/local/share/apache2/man/
You can move your htdocs and cgi-bin to the new locations, or edit
/opt/local/etc/apache2/httpd.conf to point at the old locations.
}}
-/usr/local/apache2フォルダから移動となったようなので、古いバージョンから以降した場合、間違えないようにapache2.oldというような名前にしておくと良いかもしれない。
*インストール [#d5bf5ed5]
-portコマンドでインストール
sudo port install apache2
-自動起動設定
sudo port load apache2
*設定 [#oafa1f67]
**httpd.confの作成 [#xba2b819]
-httpd.conf.sampleをコピーする
$ cd /opt/local/apache2/conf
$ sudo cp httpd.conf.sample httpd.conf
*設定 [#y4219586]
**ユーザーディレクトリを有効にする。 [#x3df4c5b]
-httpd.confで以下の部分のコメントを外す
# User home directories
Include conf/extra/httpd-userdir.conf
-httpd-userdir.confは以下のようになっている。/Users/ユーザー名/Sites以下にコンテンツを作れば良いことが分かる。
**ユーザーディレクトリを有効にする [#q59df476]
-/opt/local/etc/apache2/httpd.confを編集する
#pre{{
# User home directories
Include etc/apache2/extra/httpd-userdir.conf
}}
-httpd-userdir.confの作成。
cd /opt/local/etc/apache2/extra/
sudo cp httpd-userdir.conf.orig httpd-userdir.conf
-中身を変更。とりあえず以下のようにした。
#pre{{
UserDir Sites
#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/Users/*/Sites">
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
Require method GET POST OPTIONS
</Directory>
}}
*起動 [#j86210ea]
-apachectrlコマンドを使う
$sudo /opt/local/apache2/bin/apachectl start
*停止 [#i53615fe]
-apachectrlコマンドを使う
$sudo /opt/local/apache2/bin/apachectl stop
*動作確認 [#ld85a673]
-http://localhost/にアクセスする。
*自動起動するようにする [#nf3c0b86]
自動起動用の設定ファイルが/Library/LaunchDaemons/org.macports.apache2.plistに保存されている。
-launchctlコマンドを使う。
$sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
*自動起動を停止する [#nf3c0b86]
-launchctlコマンドを使う。
$sudo launchctl unload -w /Library/LaunchDaemons/org.macports.apache2.plist
*Tips [#hf70b269]
**rubyでcgi [#aeaffcd7]
-/opt/local/apache2/cgi-bin/test.rbを編集
#pre{{
#!/opt/local/bin/ruby
require "cgi"
print "Content-type: text/html\n\n"
print "<html><body>Hello World</body></html>"
}}
-$ sudo chmod 755 test.rb
-http://localhost/cgi-bin/test.rb にアクセス。