LinuxにApacheをインストールする方法

Apacheをインストールする手順について紹介します。

目次

インストール環境

今回のインストール環境は以下になります。

Apacheのモジュール名は「httpd」なので注意してください。

  • CentOS:CentOS Linux release 7.0.1406 (Core)
  • Apache:httpd 2.4.6-67.el7

インストール手順

今回はyumを使用してApacheをインストールします。

yum install httpd

↓が実行ログになります。

[root@centos7-local ~]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-18.el7.centos will be updated
--> Processing Dependency: httpd = 2.4.6-18.el7.centos for package: 1:mod_ssl-2.4.6-18.el7.centos.x86_64
---> Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be an update
--> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos.6 for package: httpd-2.4.6-67.el7.centos.6.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-18.el7.centos will be updated
---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos.6 will be an update
---> Package mod_ssl.x86_64 1:2.4.6-18.el7.centos will be updated
---> Package mod_ssl.x86_64 1:2.4.6-67.el7.centos.6 will be an update
--> Processing Dependency: openssl-libs >= 1:1.0.1e-37 for package: 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64
--> Running transaction check
---> Package openssl-libs.x86_64 1:1.0.1e-34.el7_0.4 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-34.el7_0.4 for package: 1:openssl-1.0.1e-34.el7_0.4.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-8.el7 will be an update
--> Running transaction check
---> Package openssl.x86_64 1:1.0.1e-34.el7_0.4 will be updated
---> Package openssl.x86_64 1:1.0.2k-8.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Updating:
httpd x86_64 2.4.6-67.el7.centos.6 updates 2.7 M
Updating for dependencies:
httpd-tools x86_64 2.4.6-67.el7.centos.6 updates 88 k
mod_ssl x86_64 1:2.4.6-67.el7.centos.6 updates 109 k
openssl x86_64 1:1.0.2k-8.el7 base 492 k
openssl-libs x86_64 1:1.0.2k-8.el7 base 1.2 M

Transaction Summary
========================================================================================================================
Upgrade 1 Package (+4 Dependent packages)

Total download size: 4.6 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): httpd-tools-2.4.6-67.el7.centos.6.x86_64.rpm | 88 kB 00:00:01
(2/5): mod_ssl-2.4.6-67.el7.centos.6.x86_64.rpm | 109 kB 00:00:00
(3/5): openssl-1.0.2k-8.el7.x86_64.rpm | 492 kB 00:00:03
(4/5): openssl-libs-1.0.2k-8.el7.x86_64.rpm | 1.2 MB 00:00:04
(5/5): httpd-2.4.6-67.el7.centos.6.x86_64.rpm | 2.7 MB 00:00:09
------------------------------------------------------------------------------------------------------------------------
Total 500 kB/s | 4.6 MB 00:00:09
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:openssl-libs-1.0.2k-8.el7.x86_64 1/10
Updating : 1:openssl-1.0.2k-8.el7.x86_64 2/10
Updating : httpd-tools-2.4.6-67.el7.centos.6.x86_64 3/10
Updating : httpd-2.4.6-67.el7.centos.6.x86_64 4/10
Updating : 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64 5/10
Cleanup : 1:mod_ssl-2.4.6-18.el7.centos.x86_64 6/10
Cleanup : httpd-2.4.6-18.el7.centos.x86_64 7/10
Cleanup : httpd-tools-2.4.6-18.el7.centos.x86_64 8/10
Cleanup : 1:openssl-1.0.1e-34.el7_0.4.x86_64 9/10
Cleanup : 1:openssl-libs-1.0.1e-34.el7_0.4.x86_64 10/10
Verifying : 1:mod_ssl-2.4.6-67.el7.centos.6.x86_64 1/10
Verifying : 1:openssl-1.0.2k-8.el7.x86_64 2/10
Verifying : httpd-2.4.6-67.el7.centos.6.x86_64 3/10
Verifying : httpd-tools-2.4.6-67.el7.centos.6.x86_64 4/10
Verifying : 1:openssl-libs-1.0.2k-8.el7.x86_64 5/10
Verifying : 1:openssl-libs-1.0.1e-34.el7_0.4.x86_64 6/10
Verifying : 1:openssl-1.0.1e-34.el7_0.4.x86_64 7/10
Verifying : httpd-tools-2.4.6-18.el7.centos.x86_64 8/10
Verifying : httpd-2.4.6-18.el7.centos.x86_64 9/10
Verifying : 1:mod_ssl-2.4.6-18.el7.centos.x86_64 10/10

Updated:
httpd.x86_64 0:2.4.6-67.el7.centos.6

Dependency Updated:
httpd-tools.x86_64 0:2.4.6-67.el7.centos.6 mod_ssl.x86_64 1:2.4.6-67.el7.centos.6 openssl.x86_64 1:1.0.2k-8.el7
openssl-libs.x86_64 1:1.0.2k-8.el7

Complete!
[root@centos7-local ~]# httpd -version
Server version: Apache/2.4.6 (CentOS)
Server built: Oct 19 2017 20:39:16
[root@centos7-local ~]#

Apacheのインストールの作成は終了です。

Apacheの自動起動設定

ApacheはOS起動した時に起動設定しておくことをオススメします。

↓のコマンドで自動起動設定を有効化します。

systemctl enable httpd.service 

Apacheの起動・停止・ステータス確認

Apacheの起動・停止手順は↓になります。

  • 起動手順
systemctl start httpd.service 
  • 停止手順
systemctl stop httpd.service 
  • ステータス確認
systemctl status httpd.service 

確認作業:Apacheにアクセスしてみる

実際にApacheにアクセスしてみましょう。

http://IPアドレス or ホスト名/

↓の画面が出力されれば完了です。

繋がらない場合は?

↑の画面が表示されていない場合は下の項目を確認してみてください。

  • httpdサービスは起動しているか?
  • IPアドレス or ホスト名は解決できているか?
  • 80ポートを使用可能か?ファイアウォールなどが設定されていないか?
  • index.htmlファイルパスは間違っていないか?
  • index.htmlファイルが存在するか?

参考:サーバーに接続できない時の確認点・原因・解決方法

よかったらシェアしてね!
  • URLをコピーしました!
目次