はじめに
タイトルのとおりですが…
XAMPPではなく、Apache2をCygwinに入れて、http://localhost/でアクセスできるところまでやりました。
その手順を公開します。
※今回Windowsのサービスへの登録は行っていません!
手順
Apache2のインストール
まず、インストールから。
入れているapt-cygにより、コマンドは多少違いますが…
searchall or find すれば、見つかるはずなのでそれをinstallします。
$ apt-cyg searchall apache2 $ apt-cyg install apache2
ちなみに、各ファイルの場所はこんな感じです。
ファイルの種類 | 場所 |
---|---|
exeファイル | /usr/sbin/httpd.exe |
設定ファイル | /etc/httpd/conf/httpd.conf |
デフォルトのDocumentRoot | /srv/www/htdocs |
デフォルトのエラーログ | /var/log/httpd/error_log |
デフォルトのアクセスログ | /var/log/httpd/access_log |
この時点でやっておくべき最低限の設定は、サーバー名の変更でしょうか。
localhostでアクセスできるようにしておきます。
# # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80 ServerName localhost:80
Cygwinならでは、cygserverの起動
cygserverとは?
↓公式サイトに正確な情報が記載されています(英語)。
Cygserver
cygwin*.dll ではまかなえない機能を、Windowsの機能を用いて提供するプログラムらしいです。
apache2を起動するには、cygserverの機能が必要ということですね。
(浅い解説ですみません…時間の都合で先に進みます…)
cygserverデーモンを起動するには、まずは設定が必要になります。
設定ファイルを作成する
cygserver-configスクリプトを実行します。
パスが通ってない場合は "/usr/bin/cygserver-config" で。
また、途中で "Do you want to install cygserver as service?" と聞かれるので、今回は "no" で進めます。
(私の用途が、Windowsのサービスに登録するほどではないので)
$ cygserver-config Generating /etc/cygserver.conf file Warning: The following function requires administrator privileges! Do you want to install cygserver as service? (Say "no" if it's already installed as service) (yes/no) no Further configuration options are available by editing the configuration file /etc/cygserver.conf. Please read the inline information in that file carefully. The best option for the start is to just leave it alone. Basic Cygserver configuration finished. Have fun!
"Have fun!" と言われたら、いざcygserverを起動してみましょう。
cygserverを起動する
バックグラウンドで起動します。
$ /usr/sbin/cygserver & $ cygserver: Initialization complete. Waiting for requests.
プロセスが立ち上がっているのを確認できたら、成功です。
$ ps | grep cygserver
Apacheの起動
下記コマンドを実行してみます。
エラーログ (/var/log/httpd/error_log) を "tail -f" しておくのをオススメします。
$ /usr/sbin/httpd -k start
私の場合は、下記エラーが表示されました。
AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded?? AH00020: Configuration Failed, exiting
"is mod_slotmem_shm loaded??" って言われたので、httpd.conf を編集します。
↓ここのコメントアウトを解除しました。
vi /etc/httpd/conf/httpd.conf
...
#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
そして、改めてApacheを起動してみると…
http://localhost/ に "It works!" が表示されました。
よかった…。
最後に
cygserverの存在は知らなかったので、いい勉強になりました。
Apacheのコマンドはヘルプを見るといろいろ載っています。
停止や再起動は↓こんな感じです。
$ /usr/sbin/httpd -h $ /usr/sbin/httpd -k start $ /usr/sbin/httpd -k stop $ /usr/sbin/httpd -k restart
以上でした!