웹사이트 검색

Ubuntu 22.04에서 무료 Let's Encrypt SSL로 PhpMyAdmin을 설치하는 방법


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

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 11.04(Natty Narwhal)

이 페이지에서

  1. 전제 조건
  2. Nginx, MariaDB 및 PHP 설치
  3. phpMyAdmin 설치
  4. MariaDB 데이터베이스 구성
  5. phpMyAdmin용 Nginx 구성
  6. Let's Encrypt SSL로 phpMyAdmin 보안
  7. phpMyAdmin 액세스
  8. 결론

phpMyAdmin은 웹 브라우저를 통해 데이터베이스를 관리하는 데 사용되는 무료 오픈 소스 웹 기반 애플리케이션입니다. 데이터베이스 관리자가 여러 작업을 수행하고, 사용자 계정 및 권한을 관리하고, 데이터를 가져오고 내보내고, SQL 문을 실행하는 데 도움이 되는 간단하고 사용자 친화적인 웹 인터페이스를 제공합니다. 초보 사용자가 MySQL 데이터베이스와 상호 작용할 수 있는 기능을 제공하는 PHP로 작성되었습니다.

이 튜토리얼에서는 Ubuntu 22.04에서 Nginx와 함께 phpMyAdmin을 설치하는 방법을 설명합니다.

전제 조건

  • Ubuntu 22.04를 실행하는 서버
  • 유효한 도메인 이름이 서버를 가리키고 있습니다.
  • 서버에 루트 암호가 구성되어 있습니다.

Nginx, MariaDB 및 PHP 설치

먼저 서버에 Nginx 웹 서버, MariaDB, PHP 및 기타 필수 PHP 확장을 설치해야 합니다. 다음 명령으로 모두 설치할 수 있습니다.

apt-get install nginx mariadb-server php php-cli php-mysql php-mbstring php-zip php-gd php-json php-curl php-fpm -y

모든 패키지가 설치되면 다음 단계로 진행할 수 있습니다.

phpMyAdmin 설치

기본적으로 phpMyAdmin 패키지는 Ubuntu 22.04 기본 리포지토리에서 사용할 수 있습니다. 다음 명령을 실행하여 설치할 수 있습니다.

apt-get install phpmyadmin -y

Nginx 웹 서버를 사용하고 있으므로 TAB을 누른 다음 ENTER를 누르면 이 프롬프트를 무시할 수 있습니다. phpMyAdmin이 사용할 데이터베이스를 구성하라는 메시지가 표시됩니다.

예를 선택하고 Enter 키를 눌러 계속합니다. 아래와 같이 phpMyAdmin 애플리케이션의 비밀번호를 선택하고 확인하라는 메시지가 표시됩니다.

원하는 암호를 입력하고 Enter 키를 눌러 설치를 마칩니다.

MariaDB 데이터베이스 구성

기본적으로 MariaDB는 보안되지 않습니다. 따라서 MariaDB를 보호하고 다음 명령을 사용하여 MariaDB 루트 암호를 설정합니다.

mysql_secure_installation

아래와 같이 모든 질문에 답하십시오.

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

MariaDB를 확보한 후 별도의 사용자를 생성하여 phpMyAdmin에 연결하여 데이터베이스를 관리하는 것이 좋습니다.

이렇게 하려면 다음 명령을 사용하여 MariaDB 셸에 로그인합니다.

mysql -u root -p

프롬프트가 표시되면 루트 암호를 제공하고 다음 명령을 사용하여 새 사용자를 만듭니다.

MariaDB [(none)]> create user  identified by 'password';

그런 다음 다음 명령을 사용하여 사용자에게 모든 권한을 부여합니다.

MariaDB [(none)]> grant all privileges on *.* to  with grant option;

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

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

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

phpMyAdmin용 Nginx 구성

다음으로 phpMyAdmin을 호스팅할 Nginx 가상 호스트 서버 블록을 생성해야 합니다. 다음 명령을 사용하여 만들 수 있습니다.

nano /etc/nginx/conf.d/phpmyadmin.conf

다음 줄을 추가합니다.

server {
  listen 80;
  listen [::]:80;
  server_name phpmyadmin.example.com;
  root /usr/share/phpmyadmin/;
  index index.php index.html index.htm index.nginx-debian.html;

  access_log /var/log/nginx/phpmyadmin_access.log;
  error_log /var/log/nginx/phpmyadmin_error.log;

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

  location ~ ^/(doc|sql|setup)/ {
    deny all;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

  location ~ /\.ht {
    deny all;
  }
}

파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 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 Sun 2022-06-12 04:37:05 UTC; 6s ago
       Docs: man:nginx(8)
    Process: 20020 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 20021 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 20022 (nginx)
      Tasks: 2 (limit: 2292)
     Memory: 2.6M
        CPU: 33ms
     CGroup: /system.slice/nginx.service
             ??20022 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??20023 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jun 12 04:37:05 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 12 04:37:05 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

다음으로 phpMyAdmin 디렉토리의 소유권과 권한을 변경합니다.

chown -R www-data:www-data /usr/share/phpmyadmin/
chmod -R 755

Let's Encrypt SSL로 phpMyAdmin 보안 유지

시작하기 전에 Let's Encrypt SSL을 다운로드하고 설치하려면 Certbot 클라이언트를 설치해야 합니다.

먼저 다음 명령을 사용하여 Certbot 리포지토리를 추가합니다.

add-apt-repository ppa:ahasenack/certbot-tlssni01-1875471

다음으로 다음 명령을 사용하여 리포지토리를 업데이트하고 Certbot 클라이언트를 설치합니다.

apt-get update -y
apt-get install certbot python3-certbot-nginx -y

Certbot이 설치되면 다음 명령을 실행하여 도메인용 Let's Encrypt SSL을 다운로드하고 설치합니다.

certbot --nginx -d phpmyadmin.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 phpmyadmin.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/phpmyadmin

다음으로 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/sites-enabled/phpmyadmin

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/phpmyadmin.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/phpmyadmin.example.com/privkey.pem
   Your cert will expire on 2022-09-12. 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"
 - 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

phpMyAdmin에 액세스

이제 웹 브라우저를 열고 URL https://phpmyadmin.eample.com을 입력합니다. phpMyAdmin 로그인 페이지로 리디렉션됩니다.

관리자 사용자 이름, 비밀번호를 제공하고 이동 버튼을 클릭합니다. 다음 페이지에 phpMyAdmin 기본 대시보드가 표시되어야 합니다.

결론

축하합니다! phpMyAdmin을 성공적으로 설치하고 Ubuntu 22.04에서 Let's Encrypt SSL로 보안을 설정했습니다. 이제 웹 브라우저를 통해 phpMyAdmin에 연결하고 데이터베이스를 관리하고 여러 작업을 수행할 수 있습니다.