본문 바로가기

홈 페이지 만들기 (3) 웹 서버 apache, php, MariaDB 설치

액트 2020. 6. 19.
반응형

 


저번 포스팅에서 초기 설정 및 ssh로 원격 접속까지 하였습니다.

 

홈 페이지 만들기 (2) 웹 서버 초기 설정

지난 포스팅에서(아래 링크) 가상머신에 웹서버를 설치하였습니다. 홈 페이지 만들기 (1) 웹 서버 OS 설치하기 - VirtualBox, Centos 8 홈페이지를 만들어 보겠습니다. (홈페이지 보단.. 그냥 웹사이트..

yjshin.tistory.com

지금부터는 리눅스에서 직접 명령어를 입력하고 작업하는 것이 아닌 원격으로 접속하여 모든 작업을 하겠습니다.

이번 포스팅에선 홈 페이지 구축을 위한 웹 서버 패키지(아파치, apache)와 데이터베이스(MariaDB), 동적 웹 서버를 구현하기 위한 프로그래밍 언어(php) 패키지를 설치하겠습니다.

설치 방법은 매우 간단합니다.

1. Apache 설치 

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

2. php 설치 

[root@localhost ~]# yum -y install php php-mysqlnd

3. MariaDB 설치

[root@localhost ~]# yum -y install mariadb*

 

4.1 Apache 설정 파일 수정

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

...
    162 #
    163 # DirectoryIndex: sets the file that Apache will serve if a directory
    164 # is requested.
    165 #
    166 <IfModule dir_module>
    167     DirectoryIndex index.html index.php					#index.php 추가
    168 </IfModule>
    169
    170 #
    171 # The following lines prevent .htaccess and .htpasswd files from being
    172 # viewed by Web clients.
    173 #
...
  • 설치 완료 후 *.php 파일을 읽을 수 있게 아파치 설정 파일을 수정합니다
  • 아파치 설정 파일인 /etc/httpd/conf/httpd.conf 파일을 vi 편집기로 엽니다.
  • /set number 결과 167번째 줄에 index.html 옆에 한칸 띄고 index.php 를 추가합니다.

 

4.2 서비스 실행

[root@localhost ~]# systemctl enable httpd

[root@localhost ~]# systemctl restart httpd
  • 서비스를 재실행하고 재부팅해도 올라올 수 있도록 설정합니다

 

4.3 서비스 정상 작동 확인

[root@localhost ~]# systemctl status httpd
  • 서비스 상태가 active (running) 으로 정상적으로 실행되고 있는지 확인합니다.

서비스 상태 확인

 

5. MariaDB 보안 설정

  • root 계정에 대한 패스워드 설정 및 각종 보안 설정을 아래와 같이 합니다.
[root@localhost ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

-- 현재 비밀번호 입력하라 (최초 접속이므로 비밀번호가 없으니 "Enter" 누른다)
Enter current password for root (enter for none):
OK, successfully used password, moving on...


Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

-- root 패스워드 설정 여부 "Y"
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

-- 익명 사용자의 삭제 여부 "Y"
Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

-- root 계정의 외부 접속을 허용할 것인가 "Y"
Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

-- 기본적으로 생성되는 test 데이터베이스를 삭제할 것이가 "Y"
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

-- 현재까지 설정한 것을 즉시 적용할 것인가 "Y"
Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

5.1 MariaDB 접속 테스트

[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

 

6. php 연동 확인 테스트

  • index.php 파일을 아파치에서 제대로 읽어 오는지 확인합니다.
  • 확인을 위한 index.php 파일 작성
  • vi 편집기로 /var/www/html/index.php 파일을 실행시켜 아래와 같이 작성합니다.
[root@localhost ~]# vi /var/www/html/index.php
<?php
        phpinfo();
?>

 

  • 인터넷 브라우저 창에서 http://192.168.70.3 자신의 호스트 전용 IP로 접속합니다.
  • 아래와 같이 뜨면 php가 정상 연동된 것입니다.

php 연동 확인 테스트


반응형

댓글