웹사이트 검색

Nginx로 OpenCart를 설치하고 Debian 10에서 암호화하는 방법


이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. LEMP 서버 설치
  4. MariaDB 데이터베이스 구성
  5. OpenCart 다운로드
  6. OpenCart용 Nginx 구성
  7. Lets Encrypt SSL로 OpenCart 보안 유지
  8. OpenCart 웹 인터페이스에 액세스
  9. 결론

Opencart는 완전한 기능을 갖춘 전자 상거래 웹 사이트를 호스팅하는 데 도움이 되는 인기 있는 오픈 소스 쇼핑 카트 솔루션입니다. Opencart는 Amazon 및 Flipcart와 같은 온라인에서 제품을 판매할 수 있는 간단하고 사용자 친화적인 인터페이스를 제공합니다. 중소기업을 위해 특별히 설계되었으며 온라인 상점에 필요한 모든 표준 전자 상거래 기능을 갖추고 있습니다. 다중 통화, 언어, 무제한 카테고리, 제품, 제품 리뷰, 멀티 스토어 등을 포함한 다양한 기능을 제공합니다.

이 튜토리얼에서는 Debian 10에서 Nginx와 함께 OpenCart를 설치하고 Lets Encrypt SSL로 보호하는 방법을 보여줍니다.

전제 조건

  • Debian 10을 실행하는 서버.\n
  • 서버에 루트 암호가 구성되어 있습니다.\n

시작하기

먼저 다음 명령을 사용하여 시스템을 최신 버전으로 업데이트합니다.

apt-get update -y
apt-get upgrade -y

서버가 업데이트되면 다시 시작하여 변경 사항을 적용하십시오.

LEMP 서버 설치

먼저 다음 명령을 실행하여 Nginx 웹 서버, MariaDB 데이터베이스 서버, PHP 및 기타 필수 PHP 확장을 설치합니다.

apt-get install nginx mariadb-server php-common php-cli php-fpm php-opcache php-gd php-mysql php-curl php-intl php-xsl php-mbstring php-zip php-bcmath php-soap unzip git -y

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

nano /etc/php/7.3/fpm/php.ini

다음 줄을 변경합니다.

memory_limit = 256M
upload_max_filesize = 100M
opcache.save_comments=1
max_execution_time = 300
date.timezone = Asia/Kolkata

완료되면 파일을 저장하고 닫습니다.

MariaDB 데이터베이스 구성

다음으로 Debian 10에 설정되어 있지 않은 MariaDB 루트 암호를 설정해야 합니다.

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

mysql

로그인하면 다음 명령을 사용하여 MariaDB 루트 암호를 설정합니다.

MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("yournewrootpassword");

다음으로 다음 명령을 사용하여 MariaDB 인증 플러그인을 mysql_native_password로 설정합니다.

MariaDB [(none)]> SET GLOBAL innodb_fast_shutdown = 0;
MariaDB [(none)]> UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root';

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

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

다음으로 루트 사용자로 MariaDB에 로그인합니다.

mysql -u root -p

루트 암호를 제공하고 다음 명령을 사용하여 OpenCart용 데이터베이스 및 사용자를 생성합니다.

MariaDB [(none)]> CREATE DATABASE opencartdb;
MariaDB [(none)]> GRANT ALL ON opencartdb.* TO 'opencart'@'localhost' IDENTIFIED BY 'password';

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

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

MariaDB가 구성되면 다음 단계로 진행할 수 있습니다.

오픈카트 다운로드

다음 명령을 사용하여 Git 저장소에서 최신 버전의 OpenCart를 다운로드할 수 있습니다.

wget https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip

OpenCart를 다운로드한 후 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

unzip opencart-3.0.3.2.zip

그런 다음 다음 명령을 사용하여 업로드 디렉터리를 Nginx 웹 루트 디렉터리로 이동합니다.

mv upload /var/www/html/opencart

다음으로 디렉토리를 opencart로 변경하고 config-dist.php 파일의 이름을 바꿉니다.

cd /var/www/html/opencart/
mv config-dist.php config.php
mv admin/config-dist.php admin/config.php

그런 다음 다음 명령을 사용하여 opencart 디렉토리에 적절한 권한을 부여하십시오.

chown -R www-data:www-data /var/www/html/opencart/
chmod -R 775 /var/www/html/opencart/

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

OpenCart용 Nginx 구성

다음으로 OpenCart를 제공하기 위해 Nginx 가상 호스트 구성 파일을 생성해야 합니다. 다음 명령으로 만들 수 있습니다.

nano /etc/nginx/sites-available/opencart.conf

다음 콘텐츠를 추가합니다.

server {
    listen 80;
    server_name opencart.linuxbuz.com;
    root /var/www/html/opencart;
    index index.php;
    access_log /var/log/nginx/opencart_access.log;
    error_log /var/log/nginx/opencart_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 / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

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

}

파일을 저장하고 닫은 후 다음 명령을 사용하여 구문 오류가 있는지 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 가상 호스트 파일을 활성화합니다.

ln -s /etc/nginx/sites-available/opencart.conf /etc/nginx/sites-enabled/

다음으로 Nginx 및 PHP-FPM 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart nginx
systemctl restart php7.3-fpm

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

Lets Encrypt SSL로 OpenCart 보호

다음으로 웹사이트에 Lets Encrypt를 설치 및 설정하려면 Certbot 클라이언트를 설치해야 합니다.

기본적으로 Certbot은 Debian 10 기본 리포지토리에서 사용할 수 없습니다. 따라서 시스템에 Certbot 리포지토리를 추가해야 합니다.

다음 명령으로 추가할 수 있습니다.

echo "deb http://ftp.debian.org/debian buster-backports main" >> /etc/apt/sources.list

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

apt-get update -y
apt-get install python3-certbot-nginx -t buster-backports

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

certbot --nginx -d opencart.linuxbuz.com

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

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
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 opencart.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/nginx/sites-available/opencart-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/nginx/sites-available/opencart-le-ssl.conf
Enabling available site: /etc/nginx/sites-available/opencart-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 vhost in /etc/nginx/sites-enabled/opencart.conf to ssl vhost in /etc/nginx/sites-available/opencart-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://opencart.linuxbuz.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/opencart.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/opencart.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-04-30. 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

이 시점에서 OpenCart는 Lets Encrypt SSL로 보호됩니다.

OpenCart 웹 인터페이스에 액세스

이제 웹 브라우저를 열고 URL https://opencart.linuxbuz.com을 입력하십시오. OpenCart 라이선스 계약 페이지로 리디렉션됩니다.

계속 버튼을 클릭하여 라이선스 계약에 동의합니다. 다음 페이지가 표시됩니다.

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

데이터베이스 자격 증명, 관리자 사용자 이름, 암호를 제공하고 계속 버튼을 클릭합니다. 설치가 완료되면 다음 페이지가 표시됩니다.

이제 터미널을 열고 다음 명령을 사용하여 설치 디렉토리를 제거하십시오.

rm -rf /var/www/html/opencart/install/

다음으로 GO TO YOUR ONLINE SHOP을 클릭합니다. 다음 페이지에 OpenCart 상점이 표시됩니다.

그런 다음 관리자에 로그인 버튼을 클릭하십시오. OpenCart 로그인 페이지가 표시됩니다.

관리자 사용자 이름, 암호를 제공하고 로그인 버튼을 클릭합니다. 다음 페이지에 OpenCart 관리 패널이 표시됩니다.

결론

축하합니다! Debian 10에 OpenCart를 성공적으로 설치하고 보호했습니다. 이제 OpenCart를 사용하여 온라인 쇼핑 카트를 호스팅할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.