LoginSignup
0
0

More than 3 years have passed since last update.

CentOS8.2にhttpdをセットアップする手順

Last updated at Posted at 2020-11-25
../

VPSサーバー(CentOS8.2)にhttpdをインストールした。手順をメモしておく。

httpdのインストールとサービス登録

httpd関係のパッケージをインストールする。


$ yum install -y httpd httpd-tools httpd-devel httpd-manual
$ httpd -version
Server version: Apache/2.4.37 (centos)
Server built:   Sep 15 2020 15:41:16

httpdサービスを起動する。また、OSの起動時に自動でサービスを開始してくれるように設定しておく。


$ systemctl enable httpd.service
$ systemctl start httpd.service
$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-11-25 11:00:57 JST; 30s ago
     Docs: man:httpd.service(8)
 Main PID: 33994 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 24989)
   Memory: 44.2M

ブラウザからの確認

以下のようなテスト用のhtmlを作成して、サーバーのGNOMEデスクトップ上でブラウザからURL(http://localhost/またはhttp://127.0.0.1/)を指定してアクセスしてみる。GNOMEにはFireFoxがプリインストールされている。


$ vi /var/www/html/index.html
<!DOCTYPE html>
<html lang="ja">
<head/>
<body>
<h1>こんにちは</h1>
</body>
</html>

この時点では、サーバー外のPCなどからIPアドレスやドメインを指定でアクセスしてもつながらない。

Firewallの設定と外部からの接続確認

Firewallに以下のようにhttpサービスを追加する。80/tcpポートは明示的に追加しなくてもいいようだ。

$ firewall-cmd --zone=public --add-service=http --permanent
$ firewall-cmd --reload
$ firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client http ssh vnc-server
  ports: 
  protocols: 

外部のブラウザから、固定のIPアドレスやドメイン名を指定して、http://153.xxx.xxx.xxx/ または http://xxx.com/ のように接続して「こんにちは」が表示されることを確認しておく。

補足1: centos-logos-httpdが足らない場合

yum update httpdの実行時に、依存関係のあるcentos-logos-httpdが足らないとアラートが出る場合は、centos-logos-httpdをネット上で探して、wgetでダウンロードするなどしてインストールしておくこと。


$ su -
$ cd Downloads
$ wget http://mirror.centos.org/centos/8/BaseOS/aarch64/os/Packages/centos-logos-httpd-80.5-2.el8.noarch.rpm
$ ls
centos-logos-httpd-80.5-2.el8.noarch.rpm

$ rpm -ivh centos-logos-httpd-80.5-2.el8.noarch.rpm 

補足2: GoogleChromeを使いたい場合

Firefoxがあれば、特にChromeは必要ないかもしれない。Chromeがお気に入りの場合には、yumのリポジトリにGoogleのサイトを追加してからダウンロードする。手順は、https://www.karelie.net/how-to-install-google-chrome-on-centos7/ などを参照のこと。


$ vi /etc/yum.repos.d/google-chrome.repo
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
$ yum install -y google-chrome-stable

# アプリのアイコンから起動できる。コマンドで開くなら、以下の感じ。
# --no-sandboxがないとワーニングが出るみたい。
$ google-chrome --no-sandbox

# userファイルのアクセス権限のワーニングが出る場合は権限を設定する。
# ユーザーIDごとにディレクトリがある。1000はtaconanaの場合。
$ chmod 777 /run/user/1000/dconf/user

以上

../
0
0
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
0
0