SW/리눅스

Ubuntu 18.04 : Drupal 설치하는 방법, 예제, 명령어

얇은생각 2020. 10. 19. 07:30
반응형

Drupal은 전세계에서 가장 인기 있는 오픈 소스 CMS 플랫폼 중 하나입니다. 그것은 PHP로 쓰여져 있고 작은 개인 블로그에서부터 대규모 기업, 정치, 정부 사이트에 이르기까지 다양한 종류의 웹사이트를 만드는 데 사용될 수 있습니다.

우분투 18.04 Drupal 8.6을 설치하는 방법을 알아보겠습니다. Drupal을 설치하는 방법은 여러 가지가 있습니다. Drupal 프로젝트에 대한 작곡가 템플릿을 사용하여 Drupal 8.6을 설치하는 데 필요한 단계를 다룹니다. 

Nginx를 웹 서버로, 최신 PHP 7.2 MySQL/MariaDB를 데이터베이스 서버로 사용할 예정입니다.

 

 

 

필수 구성 요소

이 튜토리얼을 계속하기 전에 다음 필수 구성 요소를 충족했는지 확인합니다.

공용 서버 IP를 가리키는 도메인 이름이 있습니다. 우리는 example.com을 사용할 것입니다.

이전 포스팅에 따라 Nginx를 설치했습니다.

도메인에 대해 설치된 SSL 인증서가 있습니다. 이전 포스팅에 따라 무료 SSL 암호화 인증서를 설치할 수 있습니다.

 

 

 

시작하기 전에 먼저 확인

패키지 인덱스 및 시스템 패키지를 최신 버전으로 업데이트합니다.

sudo apt update && sudo apt upgrade

 

 

 

1. MySQL 데이터베이스 생성

서버에 MySQL 또는 MariaDB가 설치되어 있는 경우 이 단계를 건너뛸 수 있습니다. 그렇지 않으면 다음을 입력하여 Ubuntu의 기본 리포지토리에서 MySQL 5.7 서버 패키지를 설치할 수 있습니다.

sudo apt install mysql-server

 

 

새로운 MySQL 설치의 경우 MySQL 서버의 보안을 향상시키기 위해 mysql_secure_installation 명령을 실행하는 것이 좋습니다.

이제 MySQL 셸에 로그인하고 새 데이터베이스 및 사용자 계정을 생성하고 사용자에게 적절한 허가 권한을 부여해야 합니다.

MySQL 셸에 로그인하려면 다음 명령을 입력하고 메시지가 표시되면 암호를 입력합니다.

mysql -u root -p

 

 

drupal이라는 데이터베이스를 생성하려면 drupaluser라는 사용자가 필요한 권한을 사용자에게 부여하고 다음 명령을 실행합니다.

CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'change-with-strong-password';

 

 

 

2. PHP 설치

우분투 18.04의 기본 PHP 버전인 PHP 7.2 Drupal 8.6에 대해 충분히 지원되고 권장됩니다. Nginx를 웹 서버로 사용하기 때문에 PHP-FPM도 설치할 것입니다.

필요한 모든 PHP 모듈을 설치하려면 다음 명령을 실행합니다.

sudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

 

 

설치 프로세스가 완료되면 PHP-FPM 서비스가 자동으로 시작됩니다. 서비스 상태를 인쇄하여 확인할 수 있습니다.

systemctl status php7.2-fpm

 

 

출력에 fpm 서비스가 활성 상태이고 실행 중임을 나타내야 합니다.

● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-05-19 19:54:13 UTC; 9h ago
     Docs: man:php-fpm7.2(8)
 Main PID: 17781 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 507)
   CGroup: /system.slice/php7.2-fpm.service
           ├─17781 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
           ├─17796 php-fpm: pool www
           └─17797 php-fpm: pool www

 

 

 

3. Composer 설치

Composer PHP의 종속 관리자이며, Drupal 템플릿을 다운로드하고 필요한 Drupal 구성 요소를 설치하는 데 사용할 것입니다. 

Composer를 전체적으로 설치하려면 curl Composer 설치 관리자를 다운로드하고 파일을 /usr/local/bin 디렉토리로 이동합니다.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

 

 

다음과 같이 작곡가 버전을 인쇄하여 설치를 확인합니다.

composer --version

 

 

출력은 다음과 같아야 합니다.

Composer version 1.6.5 2018-05-04 11:44:59

 

 

 

4. Drupal 설치

이제 작곡가가 설치되었으므로 /var/www/my_drupal 디렉토리 내의 작곡가 템플릿을 사용하여 새로운 Drupal 프로젝트를 진행 및 생성할 수 있습니다.

sudo composer create-project drupal-composer/drupal-project:8.x-dev /var/www/my_drupal --stability dev --no-interaction

 

 

위 명령은 템플릿을 다운로드하고 필요한 php 패키지를 모두 가져오고 몇 가지 스크립트를 실행하여 프로젝트를 설치할 수 있도록 준비합니다. 이 프로세스는 몇 분 정도 걸릴 수 있으며, 성공적으로 수행될 경우 출력의 끝은 다음과 같아야 합니다.

Create a sites/default/settings.php file with chmod 0666
Create a sites/default/files directory with chmod 0777

 

 

다음 단계는 Drush를 사용하여 Drupal을 설치하는 것입니다. 아래 명령에서는 1단계에서 생성된 MySQL 데이터베이스와 사용자 정보를 전달합니다.

cd /var/www/my_drupal
sudo vendor/bin/drush site-install --db-url=mysql://drupaluser:change-with-strong-password@localhost/drupal

 

 

설치 프로그램이 다음 메시지를 표시합니다. 계속하려면 Enter 키를 누르십시오.

You are about to DROP all tables in your 'drupal' database. Do you want to continue? (yes/no) [yes]:

 

 

설치가 완료되면 스크립트는 관리 사용자 이름과 암호를 인쇄합니다. 출력은 다음과 같아야 합니다.

[notice] Starting Drupal installation. This takes a while. Consider using the --notify global option.
[success] Installation complete.  User name: admin  User password: XRkC9Q5WN9

 

 

마지막으로 웹 서버가 사이트의 파일 및 디렉토리에 대한 전체 액세스 권한을 가질 수 있도록 올바른 권한을 설정해야 합니다. Nginx PHP 모두 www-data 사용자 및 www-data 그룹으로 실행 중이므로 다음 명령을 실행해야 합니다.

sudo chown -R www-data: /var/www/my_drupal

 

 

 

5. Nginx 구성

시스템에 SSL 인증서가 설치된 Nginx가 이미 설치되어 있어야 합니다.

새로운 Drupal 프로젝트를 위한 새로운 서버 블록을 만들기 위해 공식 Nginx 사이트의 Nginx 레시피를 사용할 것입니다.

텍스트 편집기를 열고 다음 파일을 만듭니다.

/etc/nginx/sites-available/example.com
# Redirect HTTP -> HTTPS
server {
    listen 80;
    server_name www.example.com example.com;

    include snippets/letsencrypt.conf;
    return 301 https://example.com$request_uri;
}

# Redirect WWW -> NON WWW
server {
    listen 443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    root /var/www/my_drupal/web;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;

    # log files
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }

    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
        return 403;
    }

    location / {
        try_files $uri /index.php?$query_string;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }


    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        include fastcgi_params;
        # Block httpoxy attacks. See https://httpoxy.org/.
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }

}

 

 

example.com Drupal 도메인으로 교체하고 SSL 인증서 파일의 올바른 경로를 설정하는 것을 잊지 마세요. 모든 HTTP 요청이 HTTPS로 리디렉션됩니다. 이 구성에 사용된 스니펫은 작성되어 있습니다.

사이트 사용 디렉토리에 대한 심볼 링크를 만들어 서버 차단을 활성화합니다.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

 

 

Nginx 서비스를 다시 시작하기 전에 구문 오류가 없는지 테스트합니다.

sudo nginx -t

 

 

오류가 없는 경우 출력은 다음과 같아야 합니다.

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

 

 

마지막으로 다음을 입력하여 Nginx 서비스를 다시 시작합니다.

sudo systemctl restart nginx

 

 

6. 설치 테스트

브라우저를 열고 도메인을 입력하면 설치가 성공한다고 가정하면 다음과 유사한 화면이 나타납니다.

Ubuntu 18.04 : Drupal 설치하는 방법, 예제, 명령어

 

관리자로 로그인하여 새로운 Drupal 설치를 사용자 정의할 수 있습니다.

 

 

 

7. Drupal 모듈과 테마 설치

이제 Drupal 프로젝트가 설치되었으므로, 몇 가지 모듈과 테마를 설치하려고 할 것입니다. 드루팔 모듈과 테마는 맞춤형 작곡가 저장소에서 진행되며, 드루팔 프로젝트는 즉시 위해 구성됩니다.

모듈이나 테마를 설치하려면 프로젝트 디렉토리에 cd를 찍기만 하면 되고 타입의 작곡가는 drpal/module_or_theme_name이 필요합니다. 예를 들어 Pathauto 모듈을 설치하려면 다음 명령을 실행해야 합니다.

cd /var/www/my_drupal
sudo -u www-data composer require drupal/pathauto

 

 

sudo -u www-data를 미리 입력하여 사용자 www-data로 명령을 실행합니다.

Using version ^1.3 for drupal/pathauto
./composer.json has been updated
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
  - Installing drupal/token (1.5.0): Downloading (100%)         
  - Installing drupal/ctools (3.2.0): Downloading (100%)         
  - Installing drupal/pathauto (1.3.0): Downloading (100%)         
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
> DrupalProject\composer\ScriptHandler::createRequiredFiles

 

 

위의 출력에서 볼 수 있듯이, Composer는 또한 우리를 위해 모든 패키지 종속성을 설치합니다.

 

 

 

8. Drupal core 업데이트

업그레이드하기 전에 항상 파일 및 데이터베이스를 백업하는 것이 좋습니다. 백업 및 마이그레이션 모듈을 사용하거나 데이터베이스와 파일을 수동으로 백업할 수 있습니다.

설치 파일을 백업하려면 다음 rsync 명령을 사용할 수 있습니다. 물론 설치 디렉터리에 대한 올바른 경로를 사용해야 합니다.

sudo rsync -a /var/www/my_drupal/  /var/www/my_drupal_$(date +%F)

 

 

데이터베이스를 백업하려면 표준 mysqldump 명령을 사용할 수 있습니다.

mysqldump -u root -p > /var/www/my_drupal_database_$(date +%F).sql

 

 또는 drush sql-dump를 사용할 수 있습니다.

cd /var/www/my_drupal
vendor/bin/drush sql-dump > /var/www/my_drupal_database_$(date +%F).sql

 

 

이제 백업을 만들었으므로 다음 명령을 실행하여 모든 Druppal 핵심 파일을 업데이트하고 계속 업데이트할 수 있습니다.

sudo -u www-data composer update drupal/core webflo/drupal-core-require-dev symfony/* --with-dependencies
반응형