AWS EC2 ์„œ๋ฒ„ ๊ตฌ์ถ•/ํ™˜๊ฒฝ์„ค์ •+ DB ์™ธ๋ถ€ ์ ‘์†
Web/Server

AWS EC2 ์„œ๋ฒ„ ๊ตฌ์ถ•/ํ™˜๊ฒฝ์„ค์ •+ DB ์™ธ๋ถ€ ์ ‘์†

๐ŸŒŸGoal : AWS EC2 ์ธ์Šคํ„ด์Šค์— ๋ฆฌ๋ˆ…์Šค ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•˜๊ณ , Nginx, PHP, MySQL๋“ฑ์„ ์„ค์น˜ํ•ด ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ์„ค์ •ํ•œ๋‹ค. ๋งˆ์ง€๋ง‰์œผ๋กœ ์™ธ๋ถ€์—์„œ ์„œ๋ฒ„์™€ ์„œ๋ฒ„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†๊นŒ์ง€ ์™„๋ฃŒํ•ด๋ณด์ž.

 

 

1. AWS EC2 ๋ฆฌ๋ˆ…์Šค ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#ec2-launch-instance

 

Tutorial: Get started with Amazon EC2 Linux instances - Amazon Elastic Compute Cloud

Tutorial: Get started with Amazon EC2 Linux instances Use this tutorial to get started with Amazon Elastic Compute Cloud (Amazon EC2). You'll learn how to launch, connect to, and use a Linux instance. An instance is a virtual server in the AWS Cloud. With

docs.aws.amazon.com

: EC2 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์€ ๋งค์šฐ ์‰ฝ๋‹ค. ์ฝ˜์†”์˜ ์„ค์ •์„ ์ญ‰ ๋”ฐ๋ผ๊ฐ€๋ฉด ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค. ์ด๋ฒˆ์—๋Š” free tier ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด Ubuntu 20.04 ๋ฒ„์ „์„ ์„ค์น˜ํ–ˆ๊ณ , ์šฉ๋Ÿ‰ 30GB ์„ค์ • ์ •๋„๋งŒ ํ•˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ๊ธฐ๋ณธ ์„ค์ •์„ ๋”ฐ๋ž๋‹ค.

 

 

- ๋งˆ์ง€๋ง‰ ๊ณผ์ •์—์„œ SSH๋ฅผ ํ™œ์„ฑํ™” ์‹œ์ผœ ์›๊ฒฉ์œผ๋กœ ์ปดํ“จํ„ฐ์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์˜€๋‹ค.

 

์ฐธ ์‰ฝ์ฃ ?


2. ์™ธ๋ถ€์—์„œ AWS ์„œ๋ฒ„ ์ ‘์†

https://winscp.net/eng/download.php

 

WinSCP :: Official Site :: Download

WinSCP 5.19 Download WinSCP 5.19 is a major application update. New features and enhancements include: A complete list of files that are part of a background transfer can be shown. Support for PPK version 3 keys from PuTTY 0.75. Stream interface in .NET as

winscp.net

: WinSCP๋Š” windows์šฉ ๋ฌด๋ฃŒ SFTP/FTP ํด๋ผ์ด์–ธํŠธ์ด๋‹ค. SFTP๋Š” ํŒŒ์ผ์„ ์„œ๋ฒ„์— ์—…/๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ๋Š” FTP์˜ ํ˜•ํƒœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€๋งŒ, ๊ทธ ์•ˆ์—์„œ SSH๋ฅผ ์ด์šฉํ•ด ์—ฐ๊ฒฐ์„ ํ•˜์—ฌ ํ›จ์”ฌ ๋ณด์•ˆ ๋ฉด์—์„œ ์•ˆ์ „ํ•˜๋ฉฐ, ์ถ”๊ฐ€ ๊ธฐ๋Šฅ์— ๊ถŒํ•œ ์ž‘์—…, ์†์„ฑ ์กฐ์ž‘ ๋“ฑ์˜ ๋” ๋งŽ์€ ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ  ์žˆ๋‹ค.

 

ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์—๋Š” aws ์„œ๋ฒ„ public ip ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

+) ์—ฌ๊ธฐ์„œ AWS private ip๋Š” AWS ๋‚ด๋ถ€ ์„œ๋ฒ„๋ผ๋ฆฌ ํ†ต์‹ ํ•˜๋Š” ip์ด๋ฏ€๋กœ, ์™ธ๋ถ€ ์ ‘์†์„ ์œ„ํ•ด์„œ๋Š” public ip๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

AWS ์„ค์ • ๋งˆ์ง€๋ง‰์—์„œ ๋ฐ›์•˜๋˜ SSHํŒŒ์ผ๋กœ ์ธ์ฆํ•œ๋‹ค.

 

๋กœ๊ทธ์ธ ์™„๋ฃŒ!
putty๋ฅผ ํ†ตํ•ด ์›๊ฒฉ ์ ‘์† ํ• ์ˆ˜๋„ ์žˆ๋‹ค,


3. Nginx, PHP, MySQL ์„ค์น˜

โฌ‡๏ธํ•˜๋‹จ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•˜์˜€๋‹ค.

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04

 

How To Install Linux, Nginx, MySQL, PHP (LEMP stack) in Ubuntu 16.04 | DigitalOcean

 

www.digitalocean.com

 

1) Nginx ์„ค์น˜

sudo apt-get update
sudo apt-get install nginx

: Nginx ๋ฅผ ์„ค์น˜ํ•œ ์ดํ›„์— AWS ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™์„ ์„ค์ •ํ•ด์ค˜์•ผ Nginx ์„œ๋ฒ„์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

HTTP ์ ‘๊ทผํ•˜๋Š” ๊ทœ์น™์„ ์„ค์ •ํ•ด ์ฃผ์—ˆ๋‹ค.
์ ‘๊ทผ ์™„๋ฃŒ^~^

 

2) MySQL ์„ค์น˜ ๋ฐ ์„ค์ •

sudo apt-get install mysql-server

#mysql ๋ณด์•ˆ ์„ค์ • - ์ „๋ถ€ y๋กœ ํ•˜๊ณ , ๋น„๋ฐ€๋ฒˆํ˜ธ๋งŒ ๋”ฐ๋กœ ์„ค์ •ํ•ด์ฃผ์ž.
sudo mysql_secure_installation

#๋กœ๊ทธ์ธ ์‹œ
sudo mysql -u root -p

๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ž˜ ์„ค์ •๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

3)PHP ์„ค์น˜ ๋ฐ ์„ค์ •

sudo apt-get install php-fpm php-mysql #php-fpm์€ nginx-php ์—ฐ๋™์— ํ•„์š”ํ•œ ๋„๊ตฌ์ด๋‹ค.

๐Ÿ“Œ Apache/Nginx PHP ์—ฐ๋™ ์‹œ ์ฐจ์ด์  

: Apache๋Š” php์™€ ์—ฐ๋™์‹œํ‚ค๋Š” ๋ชจ๋“ˆ์„ config๋ฅผ ํ†ตํ•ด ์ž๋™์œผ๋กœ ์„ค์ •ํ•ด์ฃผ๋Š” ๋ชจ๋“ˆ์ด ๋‚ด๋ถ€์— ์žˆ์ง€๋งŒ, nginx ์—์„œ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋”ฐ๋กœ ์„ค์น˜ํ•˜๊ณ , Nginx configuration์—์„œ ์„ค์ •์„ ์ˆ˜๋™์œผ๋กœ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

 

  • Nginx Configuration ํŒŒ์ผ ์„ค์ •
sudo nano /etc/nginx/sites-avaliable/default

1) 56,57,60 ๋ฒˆ์งธ ์ฃผ์„ ํ•ด์ œ. 63๋ฒˆ์งธ ์ค„ { ์ฃผ์„๋„ ํ•ด์ œ

2) fastcgi_pass์˜ php ๋ฒ„์ „์€ ์ž์‹ ์ด ์„ค์น˜๋˜์–ด์žˆ๋Š” ๋ฒ„์ „์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•ด์ค€๋‹ค.

 

  • Nginx ๊ธฐ๋ณธ ๋””๋ ‰ํ† ๋ฆฌ์— php ํŒŒ์ผ ์ถ”๊ฐ€
cd /var/www/html
sudo vim index.php

<?php
phpinfo();
?>

 

  • ์„œ๋ฒ„ ์žฌ์‹œ์ž‘
sudo service nginx restart


โ—์—๋Ÿฌ ๋ฐœ์ƒ

Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

systemctl status nginx.service

์˜ค๋ฅ˜๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‚˜๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์•„๊นŒ ์„ค์ • ํŒŒ์ผ์„ ์ž˜๋ชป ๊ฑด๋“œ๋ ค์„œ ํ•ด๋‹น ๋‚ด์šฉ ์‚ญ์ œํ–ˆ๋”๋‹ˆ ํ•ด๊ฒฐ
์—ฐ๋™ ์™„๋ฃŒ!


4. MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์™ธ๋ถ€์ ‘์†

  • MySQL ์‚ฌ์šฉ์ž ์ƒ์„ฑ

: ์™ธ๋ถ€์—์„œ์˜ ์›๊ฒฉ์ ‘์†์ด๋ฏ€๋กœ  root๋ณด๋‹ค๋Š” ์‚ฌ์šฉ์ž๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ์ ‘๊ทผํ•˜๋Š”๊ฒŒ ํ›จ์”ฌ ์•ˆ์ „ํ•˜๋‹ค.

sudo mysql -u root -p

mysql > show databases;
mysql > use mysql;
mysql > select user, host from user;
mysql > create user '์„ค์ •ํ•  ์ด๋ฆ„'@'%' identified by '๋น„๋ฐ€๋ฒˆํ˜ธ'; #์™ธ๋ถ€์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋„๋ก ์ƒ์„ฑ
mysql > flush privileges;
  • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ถŒํ•œ ๋ถ€์—ฌ
mysql > grant all privileges on *.* to '์‚ฌ์šฉ์ž'@'%' with grant option; # MySQL 8 ๋ฒ„์ „ ์ปค๋งจ๋“œ
mysql > flush privileges;
  • ์™ธ๋ถ€ ์ ‘์†์„ ์œ„ํ•œ ์„ค์ • ํŒŒ์ผ ์ˆ˜์ •
cd /etc/mysql/mysql.conf.d
sudo vim mysqld.cnf

: bind-address / mysqlx-bind-address ๋ฅผ 0.0.0.0์œผ๋กœ ์„ค์ •ํ•ด์ค€๋‹ค.

sudo service mysql restart #์ ์šฉ์„ ์œ„ํ•ด ์žฌ์‹œ์ž‘

 

 

  • aws ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ ์ˆ˜์ •

MySQL ๊ทœ์น™์„ ์ถ”๊ฐ€ํ•ด๋„ฃ์—ˆ๋‹ค.

 

  • MySQL workbench์—์„œ ์™ธ๋ถ€ ์ ‘์†

: Hostname์— ์„œ๋ฒ„์˜ IP๋ฅผ ์ž…๋ ฅํ•˜๊ณ , ์•„๊นŒ ๋”ฐ๋กœ ์™ธ๋ถ€์ ‘์†์„ ์œ„ํ•ด ์ƒ์„ฑํ–ˆ๋˜ ์‚ฌ์šฉ์ž๋ช…๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ค€๋‹ค.

test connection์ด ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰ ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.
์ ‘์† ์™„๋ฃŒ~


5. phpMyAdmin ์„ค์น˜

sudo apt update
sudo apt-get install phpmyadmin

#nginx ์›น ์„œ๋ฒ„๊ฐ€ phpmyadmin ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋„๋ก Nginx ๋ฌธ์„œ root dir๋กœ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.
sudo ln -s /usr/share/phpmyadmin /var/www/html/pma_hidden

 

phpmyadmin ํ™œ์„ฑํ™” ์™„๋ฃŒ!

๐Ÿ™ ์ฐธ๊ณ  ์ž๋ฃŒ

https://nhj12311.tistory.com/76

 

ftp, ftps, sftp(ssh) ๊ฐœ๋… ์ •๋ฆฌ

IT๋ฅผ ์ „๊ณตํ•˜๊ฑฐ๋‚˜ ์•„๋‹ˆ๋ฉด ์‹ค๋ฌด๋ฅผ ์ ‘ํ•˜๋‹ค๋ณด๋ฉด ์ด ๋†ˆ์˜ ftp, ftps, sftp(ssh) ํ”„๋กœํ† ์ฝœ์— ๋Œ€ํ•ด์„œ ์ด์•ผ๊ธธ ํ•˜๊ฒŒ ๋˜๊ฑฐ๋‚˜ ๋“ฃ๊ฑฐ๋‚˜ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค๋งŒ ๊ฐœ๋…์ด๋ผ๋„ ์ข€ ์ •ํ™•ํ•˜๊ฒŒ ๊ฐˆ๋ฌด๋ฆฌํ•˜๊ณ  ์ ‘ํ•ด์•ผํ•œ๋‹ค๋Š” ์ƒ๊ฐ์ด

nhj12311.tistory.com