백엔드 서버를 LEMP 스택(Linux + Nginx + MySQL + PHP/Python) 으로 구성하는 것은 매우 효율적인 선택임.
LEMP 스택 구성 요소 개요
구성 요소 | 설명 |
---|---|
Linux | 서버 운영체제 (Ubuntu, Debian, CentOS 등) |
Nginx | 고성능 웹 서버, 정적 파일 처리 및 리버스 프록시 역할 |
MySQL | 관계형 데이터베이스 시스템 |
PHP/Python | 동적 웹 애플리케이션의 서버 사이드 언어 |
시스템 구성 예시 (Ubuntu 기준)
1. Linux (Ubuntu 22.04 이상 권장)
- 보안 업데이트 및 패키지 관리를 쉽게 할 수 있고, 커뮤니티 지원이 뛰어남
2. Nginx 설치
sudo apt update
sudo apt install nginx
sudo systemctl enable nginx
sudo systemctl start nginx
3. MySQL 설치
sudo apt install mysql-server
sudo mysql_secure_installation
- 데이터베이스 사용자 생성 및 권한 설정도 필요합니다.
4. PHP 설치 (Laravel 등 사용 시)
sudo apt install php-fpm php-mysql
- Laravel 사용 시 PHP 8.1 이상 추천
- PHP 확장 모듈도 필요에 따라 설치 (예:
php-curl
,php-mbstring
,php-xml
등)
또는 Python (Flask, Django 등 사용 시)
sudo apt install python3 python3-pip
pip install flask # 또는 django
- WSGI 서버로 Gunicorn 또는 uWSGI 설치 필요
- 예:
pip install gunicorn
5. Nginx 설정 예시 (PHP와 연동)
server {
listen 80;
server_name your-domain.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Python 앱과 연결 시 (예: Flask)
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
- Python 앱은
gunicorn app:app
등으로 8000포트에서 실행
선택 기준: PHP vs Python
항목 | PHP (Laravel 등) | Python (Django/Flask 등) |
---|---|---|
배우기 쉬움 | 비교적 쉬움 | 쉬움 (Flask) / 복잡함 (Django) |
생태계 | 웹 전용 도구 풍부 | 다양한 분야 확장성 (AI, 데이터) |
성능 | 우수 | 비슷하거나 우수 |
문법 및 유연성 | 웹에 최적화된 문법 | 범용 언어로 더 유연 |
LEMP의 장점
- 리소스 절약형 구성 (특히 Apache 대신 Nginx 사용)
- 정적/동적 요청 분리로 성능 향상
- 확장성과 보안 설정이 유연함
- PHP와 Python 모두 지원 가능