웹사이트 검색

Nginx와 함께 Moodle을 설치하는 방법 및 Ubuntu 22.04에서 무료 Lets Encrypt SSL


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 16.04(Xenial Xerus)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. Nginx, MariaDB 및 PHP 설치
  4. Moodle용 데이터베이스 생성
  5. Ubuntu 22.04에 Moodle 설치
  6. Moodle용 Nginx 구성
  7. Moodle 웹 인터페이스 액세스
  8. Lets Encrypt SSL로 안전한 Moodle\n
  9. 결론

Moodle은 PHP로 작성된 무료 오픈 소스 학습 관리 시스템 및 CMS입니다. 이를 통해 튜터와 강사는 학생들을 위한 코스를 만들 수 있으며 장거리 교육 및 기타 온라인 학습 프로그램에 보다 쉽게 접근할 수 있습니다. Moodle은 사용자가 현재, 과거 또는 미래 코스에 액세스하고 보류 중인 작업을 검토할 수 있도록 도와주는 간단하고 사용자 친화적인 맞춤형 대시보드를 제공합니다. 기술에 정통한 교육을 제공하는 것을 목표로 하는 교사 및 교육자를 위해 설계되었습니다.

이 튜토리얼은 Ubuntu 22.04에서 Nginx와 Lets Encrypt SSL을 사용하여 Moodle을 설치하는 방법을 보여줍니다.

전제 조건

  • Ubuntu 22.04를 실행하는 서버.\n
  • 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
  • 루트 암호는 서버에서 구성됩니다.\n

시작하기

먼저 시스템 패키지를 최신 버전으로 업데이트해야 합니다. 다음 명령을 실행하여 모두 업데이트할 수 있습니다.

apt-get update -y

서버가 업데이트되면 다음 단계로 진행할 수 있습니다.

Nginx, MariaDB 및 PHP 설치

시작하기 전에 Apache, MariaDB, PHP 및 기타 PHP 라이브러리를 시스템에 설치해야 합니다. 먼저 다음 명령을 사용하여 Apache 및 MariaDB 서버를 설치합니다.

apt-get install nginx mariadb-server -y

기본적으로 Ubuntu 22.04는 PHP 8.1 버전과 함께 제공되며 Moodle은 이 PHP 버전을 지원하지 않습니다. 따라서 서버에 PHP 7.4를 설치해야 합니다.

먼저 다음 명령을 사용하여 필요한 모든 종속 항목을 설치합니다.

apt install software-properties-common ca-certificates lsb-release apt-transport-https -y

다음으로 다음 명령을 사용하여 서버에 PHP 저장소를 추가합니다.

add-apt-repository ppa:ondrej/php

다음으로 다음 명령을 사용하여 리포지토리를 업데이트합니다.

apt update

저장소가 업데이트되면 다음 명령을 사용하여 다른 필수 확장과 함께 PHP를 설치합니다.

apt install php7.4 php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-soap php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip unzip git curl -y

모든 패키지가 설치되면 php.ini 파일을 편집하고 일부 설정을 변경합니다.

nano /etc/php/7.4/fpm/php.ini

다음 줄을 변경합니다.

memory_limit = 256M
max_input_vars = 6000

cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = UTC

파일을 저장하고 닫은 다음 PHP-FPM 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart php7.4-fpm

완료되면 다음 단계로 진행할 수 있습니다.

Moodle용 데이터베이스 생성

Moodle은 MySQL 또는 MariaDB를 데이터베이스 백엔드로 사용하므로 Moodle용 데이터베이스 및 사용자를 생성해야 합니다.

먼저 다음 명령을 사용하여 MySQL 셸에 연결합니다.

mysql

로그인 후 다음 명령을 사용하여 데이터베이스와 사용자를 생성합니다.

CREATE DATABASE moodledb;
CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'password';

다음으로 다음 명령을 사용하여 Moodle 데이터베이스에 대한 모든 권한을 부여합니다.

GRANT ALL ON moodledb.* TO 'moodle'@'localhost' WITH GRANT OPTION;

다음으로 권한을 플러시하고 다음 명령을 사용하여 MySQL을 종료합니다.

FLUSH PRIVILEGES;
EXIT;

다음으로 MariaDB 기본 구성 파일을 편집하고 innodb_file_format을 정의합니다.

nano /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld] 섹션 안에 다음 줄을 추가합니다.

[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix = ON

파일을 저장한 다음 MariaDB 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart mariadb

우분투 22.04에 무들 설치하기

먼저 디렉토리를 Apache 루트 디렉토리로 변경하고 다음 명령을 사용하여 최신 버전의 Moodle을 다운로드합니다.

cd /var/www/html
git clone -b MOODLE_400_STABLE git://git.moodle.org/moodle.git moodle

다음으로 Moodle에 적절한 권한과 소유권을 설정합니다.

mkdir -p /var/www/html/moodledata
chown -R www-data:www-data /var/www/html/moodle
chmod -R 755 /var/www/html/*
chown www-data:www-data /var/www/html/moodledata

완료되면 다음 단계로 진행할 수 있습니다.

Moodle용 Nginx 구성

다음으로 Moodle을 호스팅하기 위해 Nginx 가상 호스트 구성 파일을 생성해야 합니다.

nano /etc/nginx/conf.d/moodle.conf

다음 줄을 추가합니다.

server {
    listen 80;
    root /var/www/html/moodle;
    index  index.php index.html index.htm;
    server_name  moodle.example.com;

    client_max_body_size 100M;
    autoindex off;
    location / {
        try_files $uri $uri/ =404;
    }

    location /dataroot/ {
      internal;
      alias /var/www/html/moodledata/;
    }

    location ~ [^/].php(/|$) {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

파일을 저장하고 닫은 후 다음 명령을 사용하여 구문 오류가 있는지 Nginx를 확인합니다.

nginx -t

다음 출력이 표시되어야 합니다.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

마지막으로 Nginx 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart nginx

다음 명령을 사용하여 Nginx 서비스의 상태를 확인할 수도 있습니다.

systemctl status nginx

다음 출력이 표시되어야 합니다.

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-07-18 07:08:50 UTC; 26s ago
       Docs: man:nginx(8)
    Process: 51379 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 51382 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 51383 (nginx)
      Tasks: 3 (limit: 4579)
     Memory: 3.6M
        CPU: 64ms
     CGroup: /system.slice/nginx.service
             ??51383 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??51384 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??51385 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jul 18 07:08:50 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 18 07:08:50 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

이 시점에서 Nginx는 Moodle을 호스팅하도록 구성됩니다. 이제 다음 단계를 진행할 수 있습니다.

Moodle 웹 인터페이스에 액세스

이제 웹 브라우저를 열고 URL http://moodle.example.com을 사용하여 Moodle 웹 인터페이스에 액세스하십시오. Moodle 설치 페이지가 표시됩니다.

언어를 선택하고 다음을 클릭하십시오. 다음 페이지가 표시됩니다.

Moodle 웹 주소, 디렉토리 경로, 데이터 디렉토리 경로를 제공하고 다음을 클릭하십시오. 다음 페이지가 표시됩니다.

데이터베이스 드라이버 유형을 선택하고 다음을 클릭하십시오. 다음 페이지가 표시됩니다.

데이터베이스 호스트, 데이터베이스 이름, 사용자 이름, 암호를 제공하고 다음을 클릭합니다. 다음 페이지가 표시됩니다.

계속을 클릭하여 모든 조건을 확인합니다. 다음 페이지가 표시됩니다.

필요한 모든 PHP 확장이 설치되었는지 확인한 다음 계속을 클릭하십시오. 다음 페이지가 표시됩니다.

계속을 클릭합니다. 다음 페이지가 표시됩니다.

관리자 사용자 이름, 비밀번호, 이메일, 국가, 시간대를 제공하고 프로필 업데이트를 클릭합니다. 다음 페이지가 표시됩니다.

첫 페이지 설정을 제공하고 변경 사항 저장 버튼을 클릭하여 변경 사항을 저장하십시오.

Lets Encrypt SSL로 안전한 무들

다음으로 Lets Encrypt SSL을 다운로드하고 이 SSL을 사용하도록 Nginx를 구성하려면 Certbot 도구를 설치해야 합니다.

먼저 다음 명령을 사용하여 Certbot을 설치합니다.

apt-get install python3-certbot-nginx -y

설치가 완료되면 다음 명령을 실행하여 모든 SSL을 다운로드하고 이를 사용하도록 Nginx를 구성합니다.

certbot --nginx -d moodle.example.com

유효한 이메일 주소를 제공하고 아래와 같이 서비스 약관에 동의하라는 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for moodle.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/moodle.conf

다음으로 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2를 입력하고 Enter를 눌러 계속하십시오. 다음 출력이 표시되어야 합니다.

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/moodle.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://moodle.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=moodle.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/moodle.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/moodle.example.com/privkey.pem
   Your cert will expire on 2022-10-19. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

이제 URL http://moodle.example.com을 사용하여 Moodle 웹사이트에 액세스할 수 있습니다.

결론

축하합니다! Nginx와 함께 Moodle을 성공적으로 설치했으며 Ubuntu 22.04에서 SSL을 암호화합니다. 이제 Moodle 기능을 탐색하고 자신만의 온라인 학습 관리 시스템을 쉽게 만들 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.