5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FreeBSDでApacheのインストールと起動

Last updated at Posted at 2018-03-14

今回はFreeBSDでWebサーバとしてのApacheをインストールしていきます。

Apacheのインストール
# pkg search apache2Apache2バージョンの検索
apache22-2.2.34_1              Version 2.2.x of Apache web server with prefork MPM
apache24-2.4.29                Version 2.4.x of Apache web server
p5-Apache2-SOAP-0.73_4         Apache2 mod_perl2 SOAP Server
p5-Apache2-SiteControl-1.05_3  Perl web site authentication/authorization system
今回は最新のApache2.4を選択しましょう

# pkg install apache24-2.4.29
インストール開始・・・

インストールが完了したら、Apacheの設定をいじっていきましょう。
今後、Apacheに関して色々と設定していくと思います。Apacheの設定は

/usr/local/etc/apache24/httpd.conf

に書き込んでいきます。
FreeBSDには初期状態からエディタとして**「vi」がインストールされていますが、「vim」**を今後使用したい方はインストールしておきましょう。

vimのインストール
# pkg install vim
インストール開始・・・

では、vimでApacheの設定をみてみましょう。

Apacheの設定
# vim /usr/local/etc/apache24/httpd.conf
#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
...Apacheについての文章や設定が書かれています

変更点は一つのみです
...
ServerName www.example.com:80
文頭のを消して下さい
...

 
viやvimはコマンドで操作することになるため、使い方がわからない場合はWebで調べながら進めて下さい。以上で設定完了です。vimを終了して下さい。  
  
  
  
  
次にApacheを起動するための設定をします。

rc.confの設定
# vim /etc/rc.conf
...
apache24_enable="YES"
最終行に追記して下さい

以上で設定完了です。vimを終了して下さい。
  
では、設定した内容に間違いがないか確認しましょう。

設定内容の確認
# apachectl configtest文法チェック
Performing sanity check on apache24 configuration:
Syntax OK
Syntax OKと出たら文法あってますというサイン

#apachectl startApacheスタート
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

これで完了ですもし設定を変えた際には毎回Apacheの再起動を行わないと反映されません
リスタート方法
# apachectl restart
Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 30177.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

もしくは
# apachectl stop
Stopping apache24.
Waiting for PIDS: 91657.
# apachectl start
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.
を実行すれば大丈夫です

ではApacheが正常に動いているのか確認しましょう。

Apacheが起動している場合、自分のPCから何らかのエクスプローラーを開きましょう。GoogleChomeでもSafariでもFirefoxでも何でもいいです。  
  
  
アドレスを打ち込む場所にhttp://(アドレス)
アドレスは自分で設定したもの
アドレスがわからない方はこちら
Apacheの確認.png
  
  
  
  
するとIt works!と出てくると思います。
It works.png
これで正常に動いていると確認できました。

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?