Ubuntu에서 nginx + MySQL + PHP 설치하기
- 공유 링크 만들기
- 이메일
- 기타 앱
Ubuntu에서 nginx + MySQL + PHP 설치하기
Apache 2가 플러그인이 매우 많고 또한 성능도 나름 괜찮다는 것을 알고는 있습니다만, 멀티 프로세스 및 멀티 스레드 방식으로 동작하는 프로그램이기에 아무래도 메모리와 프로세스 우선도에서 많은 제약이 있기 때문에 가볍고 빠른 웹 서버를 찾아 다녔습니다. 물론 웹 서버를 직접 구현할 수도 있겠지만, 솔직히 성능과 메모리 사용량이라는 개미 한 마리 잡자고 초가삼간 다 태울 필요가 없기 때문에 가벼운 웹 서버 중 요즘 많이 사용되고 있는 nginx(엔진-X)를 사용해보기로 했습니다. 사실 nginx도 멀티 프로세스, 멀티 스레드 방식으로도 동작이 되지만, 이벤트 기반 구조로 되어있는 것이 핵심입니다.
nginx(이하 엔진엑스)와 PHP, MySQL의 설치법은 맨 밑의 출처 사이트에서 구했으며, 출처에서의 환경과 제가 설치한 환경은 아래와 같습니다.
출처 사이트에서의 환경
Description Ubuntu Version 11.10
본 포스트에서의 환경
Description Ubuntu Version 12.04 LTS Server version Machine x64 on VMware Player 4.0.4
먼저 우리가 해야 할 것은 각 항목의 설치입니다. Ubuntu에서 설치한 이유는 APT 패키지 관리자를 이용하여 설치하면 많은 부분을 건드리지 않고도 사용할 수 있기 때문입니다.
또한 대부분의 명령은 root 권한으로 수행하기 때문에 root로 접속하셔서 설치 및 설정을 하시거나 본 포스트에서와 같이 맨 앞에 일시적 관리자 권한 부여 명령(sudo)를 이용하시기 바랍니다.
sudo apt-get install nginx php5-fpm mysql-server mysql-client php5-mysql
위 명령어를 이용하여 각 패키지를 설치합니다. PHP를 FPM(FastCGI Process Manager)로 설치하는 이유는 엔진엑스에서는 Apache 2와 같이 플러그인이 제공되지 않기 때문입니다. 때문에 FastCGI 프로세스를 통해 통신해야 하죠.
sudo /etc/init.d/nginx start
위 명령을 통해 엔진엑스를 실행함으로써 웹 서버를 동작시킵니다. 물론 실행하면 엔진엑스에서 기본으로 제공하는 색인 페이지가 나타납니다. 나타나지 않는다면 설치가 잘 되지 않은 것이므로 다시 한번 확인해보시기 바랍니다.
이제 엔진엑스 최적화를 수행합니다.
sudo vi /etc/nginx/nginx.conf
위 명령을 이용해 엔진엑스 설정 파일을 열고 아래와 같이 수정합니다.
user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 2; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ##
위 설정 파일 내용은 상단의 일부만 담았습니다. keepalive_timeout 2; 부분을 잘 보시기 바랍니다. worker_process 4; 부분도 수정해주시는 것이 좋습니다. worker_process는 CPU의 개수 또는 코어의 개수로 해주시면 좋습니다.
이제 사이트 설정 파일을 편집해야 합니다.
sudo vi /etc/nginx/sites-available/default
위 명령을 입력하여 사이트 설정 파일을 열고 아래와 같이 수정해줍니다.
server { listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default ipv6only=on; ## listen for ipv6 root /usr/share/nginx/www; index index.html index.htm index.php; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; deny all; } # Only for nginx-naxsi : process denied requests #location /RequestDenied { # For example, return an error code #return 418; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php5-fpm: #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }
위 설정 파일은 상단의 일부만 담았습니다. 잘 보시면 달라진 부분들이 많이 보일 것입니다. PHP FastCGI 설정 부분에서 주의해야 할 점은 설정 옵션 중에 주석을 해제하지 않는 줄이 한 줄 있다는 점입니다. 주석을 해제하면 오류가 발생할 것입니다.
마지막으로 아래 명령을 입력해주면 끝입니다. PHP 코드를 작성하셔서 실행해보시기 바랍니다.
sudo /etc/init.d/php5-fpm start sudo /etc/init.d/nginx reload
출처 : HowtoForge - Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support on Ubuntu 11.10
from http://daramkun.tistory.com/49 by ccl(S)
- 공유 링크 만들기
- 이메일
- 기타 앱
댓글
댓글 쓰기