サーバを立ち上げてからの手順①webサーバ、PHP編

サーバ(CentOS 7)を立ち上げてからの手順を書いていきます。今回はwebサーバ、PHP

サーバ概要

サーバ概要を確認するには、以下のコマンドで確認可能です

# cat /etc/*release
CentOS Linux release 7.3.1611 (Core) 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.3.1611 (Core) 
CentOS Linux release 7.3.1611 (Core) 

[参考]
Linux OSの種類とバージョンの調べ方 - Qiita
CentOS、UbuntuなどLinux OSのバージョン確認をするコマンド | UX MILK

Webサーバ(Apache)のインストール

インストール

# yum install httpd

f:id:harucharuru:20200226142657p:plain
Complete!が最後に表示されればOK!

起動

# systemctl start httpd.service

f:id:harucharuru:20200226142833p:plain

再起動の場合は、

# systemctl restart httpd.service

自動起動

再起動しても自動的に起動するように設定します。

# systemctl enable httpd.service

firewallのストップとiptableのストップ

アクセスしてみる。
f:id:harucharuru:20200226143614p:plain
表示されないので、firewallのストップとiptableのストップを行う
firewallのストップ

# systemctl stop firewalld

iptableのストップ

# systemctl stop iptables

f:id:harucharuru:20200226143316p:plain
すると、表示される
f:id:harucharuru:20200226143817p:plain

PHPインストール

インストール

# yum install php php-mbstring php-mysql

f:id:harucharuru:20200226144016p:plain
Complete!で完了

その後、webサーバを再起動

# systemctl restart httpd.service

PHP動作確認

ドキュメントルート(/var/www/html/)でPHPプログラムを作成

# cd /var/www/html/
# vi test.php

f:id:harucharuru:20200226144411p:plain

プログラムには以下の内容を書き込む

<?php phpinfo();?>

f:id:harucharuru:20200226144556p:plain


http://IPアドレス/test.phpにアクセスするとphp情報が表示される。
f:id:harucharuru:20200226151902p:plain

以上!