ひとり勉強ログ

ITエンジニアの勉強したことメモ

LAMP環境構築その4 – CentOS7にApacheをインストールして起動する

前回CentOSへのログインができたので、今回からApacheのインストールなどを行っていきます。

このサーバーに格納されたHTMLファイルや画像などをブラウザで表示させるためにはWebサーバーにしなければなりません。WebサーバーにするためにApacheをインストールする必要があるんですね。

root権限になる

Apacheをインストールするためには、PuttyCentOSにログインした状態で、root権限になっておく必要があります。

ユーザーID、パスワードともに「vagrant」でログインしている場合、Puttyでは下記のように表示されています。入力できるところのすぐ左が「$」となっている場合、一般ユーザーです。

[bash] [vagrant@localhost ~]$ [/bash]

これをroot権限にするには、下記のコマンドを入力します。

[bash] [vagrant@localhost ~]$ su - [/bash]

で、「Passwort:」とパスワードを聞かれるので同様に「vagrant」と入力して下記のように表示されればroot権限になっています。

[bash] [root@localhost ~]# [/bash]

一般ユーザーで「$」だったのが「#」に変わっていますね。

Apacheのインストール

root権限になったところで、Apacheのインストールを行います。

下記のコマンドを実行します。

[bash] [root@localhost ~]# yum -y install httpd [/bash]

インストールは約1分で終了します。インストール中にダダーっといろいろ出てきますが、最後に下記のように表示されます。

[bash] Komplett! [/bash]

ドイツ語で「Complete!」と言っているようです。言語設定がドイツ語になっているからですね。

Apacheの起動

インストールできたので、Apacheを起動します。

[bash] [root@localhost ~]# systemctl start httpd.service [/bash]

※CentOS6.x以前は下記のコマンドです。 [bash] [root@localhost ~]# service httpd start [/bash]

起動したので、ステータスを確認します。

[bash] [root@localhost ~]# systemctl status httpd.service [/bash]

下記のように3行目に「Active: active (running)」と表示されればOKです。

[bash] httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: active (running) since Mo 2016-07-18 01:35:15 CEST; 49s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 4078 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─4078 /usr/sbin/httpd -DFOREGROUND ├─4079 /usr/sbin/httpd -DFOREGROUND ├─4080 /usr/sbin/httpd -DFOREGROUND ├─4081 /usr/sbin/httpd -DFOREGROUND ├─4082 /usr/sbin/httpd -DFOREGROUND └─4083 /usr/sbin/httpd -DFOREGROUND

Jul 18 01:35:15 localhost.localdomain httpd[4078]: AH00558: httpd: Could not ... Jul 18 01:35:15 localhost.localdomain systemd[1]: Started The Apache HTTP Ser... Hint: Some lines were ellipsized, use -l to show in full. [/bash]

さらに、Linuxファイアウォールであるfirewalldを停止します。

[bash] [root@localhost ~]# systemctl stop firewalld [/bash]

ステータスを確認します。

[bash] [root@localhost ~]# systemctl status firewalld [/bash]

下記のように3行目に「Active: inactive (dead)」と表示されればOKです。

[bash] firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) Active: inactive (dead) since Mo 2016-07-18 01:41:15 CEST; 10s ago Process: 583 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 583 (code=exited, status=0/SUCCESS)

Jul 18 00:59:35 localhost.localdomain systemd[1]: Starting firewalld - dynami... Jul 18 00:59:40 localhost.localdomain systemd[1]: Started firewalld - dynamic... Jul 18 01:41:14 localhost.localdomain systemd[1]: Stopping firewalld - dynami... Jul 18 01:41:15 localhost.localdomain systemd[1]: Stopped firewalld - dynamic... Hint: Some lines were ellipsized, use -l to show in full. [/bash]

※CentOS6.x以前は下記のコマンドです。 [bash] [root@localhost ~]# service iptables stop [/bash]

これで、ブラウザに「http://192.168.33.10/」でApache画面が表示されるはずです。

lamp_04_01

Apacheのその他のコマンド

Apacheの停止

[bash] [root@localhost ~]# systemctl stop httpd.service [/bash]

Apacheのステータス確認

[bash] [root@localhost ~]# systemctl status httpd.service [/bash]

Apache自動起動

CentOSを起動した際に同時にApacheも起動するようにするコマンドです。 [bash] [root@localhost ~]# systemctl enable httpd.service [/bash]

Apache自動起動停止

上記の自動起動を停止するコマンドです。 [bash] [root@localhost ~]# systemctl disable httpd.service [/bash]

これでApacheまで完了しました。次回、MySQLのインストールを行っていきます。