LoginSignup
16
15

More than 5 years have passed since last update.

Apache2を使えるようにする

Posted at

Apache2を使えるようにする

USBメモリを使うの続き

Apache2をとりあえず使えるようにして、コンテンツの置き場所をUSBメモリにしてみる

Apache2をインストールする

sudo apt-get install apache2

USBメモリにコンテンツの置き場ディレクトリを作成

sudo mkdir /mnt/usb1/www
必要に応じてデフォルトのDocumentRoot(/var/www)からファイルをコピーしておく

Apache2のインストール先を確認する

whereis apache2

result
apache2: /usr/sbin/apache2 /etc/apache2 /usr/lib/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz

Apache2の設定ファイルは/etc/apache2にあるっぽい

Apache2の設定ファイル

/etc/apache2/apache2.conf

Apache2全体の設定ファイル

/etc/apache2/sites-available/

サイト毎の設定ファイルが置かれているディレクトリ
設定ファイルのうち/etc/apache2/sites-enabled/にリンクしたものだけが有効になる
リンクを張ったり外したりするコマンドも用意されている

  • a2ensite(/usr/sbin/a2ensite):/etc/apache2/sites-enabled/にリンクを張る
Example
sudo a2ensite
Your choices are: default default-ssl
Which site(s) do you want to enable (wildcards ok)?
default
Enabling site default.
To activate the new configuration, you need to run:
  service apache2 reload
  • a2dissite(/usr/sbin/a2dissite):/etc/apache2/sites-enabled/のリンクを外す
Example
sudo a2dissite
Your choices are: default
Which site(s) do you want to disable (wildcards ok)?
default
Site default disabled.
To activate the new configuration, you need to run:
  service apache2 reload

/etc/apache2/mods-available/

Apache2のモジュールを置くディレクトリ
モジュールのうち/etc/apache2/mods-enabled/にリンクしたものだけが有効になる

DocumentRootを変更する

コンテンツの置き場所をUSBメモリにするにはDocumentRootを変更する
デフォルトサイトのDocumentRootは
/etc/apache2/sites-available/default
に書かれている

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default.orig

sudo nano /etc/apache2/sites-available/default

/etc/apache2/sites-available/default
[Before]
DocumentRoot /var/www
<Directory /var/www>

[After]
DocumentRoot /mnt/usb1/www
<Directory /mnt/usb1/www>

変更した設定を反映するためにApache2を再起動する

sudo /etc/init.d/apache2 restart

16
15
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
16
15