CentOS 7 간단 웹서버 구축 APM – yum 설치

안녕하세요.

JP-Hosting 입니다.

오늘은 yum을통해 간단 웹서버 구축을 하려고합니다.

  • 테스트환경은 Centos 7.8 버전입니다.


[root@localhost ~]# rpm -qa *-release 
centos-release-7-8.2003.0.el7.centos.x86_64

  • 의존성 라이브러리 설치

yum으로 필요한 라이브러리를 한번에 전부 설치합니다. (한번에 관련된 의존성도 같이 설치가 됩니다.)



[root@localhost ~]# yum install libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
.

.

.

Installed:
gcc.x86_64 0:4.8.5-39.el7 gcc-c++.x86_64 0:4.8.5-39.el7 ncurses-devel.x86_64 0:5.9-14.20130511.el7_4

Dependency Installed:
cpp.x86_64 0:4.8.5-39.el7 glibc-devel.x86_64 0:2.17-307.el7.1 glibc-headers.x86_64 0:2.17-307.el7.1 kernel-headers.x86_64 0:3.10.0-1127.8.2.el7
libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.5-39.el7 mpfr.x86_64 0:3.1.1-4.el7

Complete!

  • [APM] : Apache, PHP, MariaDB (설치 순서는 Apache, MariaDB, PHP)

1. Apache 설치


[root@localhost ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================
Installing:
httpd x86_64 2.4.6-93.el7.centos base 2.7 M

Transaction Summary
==============================================================================================================================================================
Install 1 Package

Running transaction
Installing : httpd-2.4.6-93.el7.centos.x86_64 1/1
Verifying : httpd-2.4.6-93.el7.centos.x86_64 1/1

Installed:
httpd.x86_64 0:2.4.6-93.el7.centos

Complete!



2.MariaDB 설치


[root@localhost ~]# yum install mariadb mariadb-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.65-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.65-1.el7 for package: 1:mariadb-5.5.65-1.el7.x86_64
---> Package mariadb-server.x86_64 1:5.5.65-1.el7 will be installed
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.65-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.65-1.el7 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================
Installing:
mariadb x86_64 1:5.5.65-1.el7 base 8.7 M
mariadb-server x86_64 1:5.5.65-1.el7 base 11 M
Installing for dependencies:
mariadb-libs x86_64 1:5.5.65-1.el7 base 759 k
perl-DBD-MySQL x86_64 4.023-6.el7 base 140 k

Transaction Summary
==============================================================================================================================================================
Install 2 Packages (+2 Dependent packages)

Total download size: 21 M
Installed size: 112 M
Is this ok [y/d/N]:Y

Installed:
mariadb.x86_64 1:5.5.65-1.el7 mariadb-server.x86_64 1:5.5.65-1.el7

Dependency Installed:
mariadb-libs.x86_64 1:5.5.65-1.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7

Complete!



3. PHP 설치


[root@localhost ~]# yum install php php-mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-48.el7 will be installed
---> Package php-mysql.x86_64 0:5.4.16-48.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================
Installing:
php x86_64 5.4.16-48.el7 base 1.4 M
php-mysql x86_64 5.4.16-48.el7 base 102 k

Transaction Summary
==============================================================================================================================================================
Install 2 Packages

Total download size: 1.5 M
Installed size: 4.6 M
Is this ok [y/d/N]:Y

Running transaction
Installing : php-mysql-5.4.16-48.el7.x86_64 1/2
Installing : php-5.4.16-48.el7.x86_64 2/2
Verifying : php-5.4.16-48.el7.x86_64 1/2
Verifying : php-mysql-5.4.16-48.el7.x86_64 2/2

Installed:
php.x86_64 0:5.4.16-48.el7 php-mysql.x86_64 0:5.4.16-48.el7

Complete!

  • 방화벽 포트허용

여기서는 Iptables를 사용하였습니다.

Centos7 Iptables를 사용하는 방법으로 바로가기


[root@localhost ~]# vi /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT           # 80 포트 추가
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@localhost ~]# systemctl restart iptables        
[root@localhost ~]# systemctl restart httpd.service
  

  • 기본웹페이지 화면 및 phpinfo()확인

기본페이지 확인

phpinfo 확인

유익한 정보가되었을지 모르겠네요

서버관련 문의는 텔레그램으로 연락 주시면 감사하겠습니다.