Raspberry Pi에서 간단하게 웹서버를 구성하는 방법을 정리한다.
일반적으로 많이 사용하는 Apache웹서버를 대체할 수 있는 엔진엑스(Nginx)를 기반으로 Raspberry Pi환경에서 가벼운 웹서버를 구축하고자 한다.
여기서는 웹서버 구축 및 PHP엔진까지 추가하는것으로 한다.
Nginx + PHP5-FPM 환경 구성하기
Nginx 참조 : http://nginx.org
먼저 Raspberry Pi의 기본 패키지를 업데이터 한다.
$sugo apt-get update
1. 패키지 설치하기
> Nginx 설치하기
$sudo apt-get install -y nginx
> PHP5-FPM 모듈 설치하기
$sudo apt-get install -y php5-fpm php5-cli php5-mcrypt php5-gd php5-common
$ sudo apt-get install php5-mysql
2. 패키지 설치 파일 정보 확인
> Nginx 파일정보
- 기본 웹서버 root 폴더 : /usr/share/nginx/www
- 웹서버 환경설정 : /etc/nginx 폴더의 nginx.conf 파일과 sites-available, sites-enable 폴더 등에서 설정할 수있다.
> PHP5-FPM 파일정보
- 패키지 환경설정 : /etc/php5/fpm폴더에 설정 파일이 있다.
3. 웹서버 설정
> Nginx 환경 설정
여기서는 기본설정을 PHP-FPM 실행 가능한 정도로 설정하였다.
설정파일은 /etc/nignx/sites-available/default 파일에 내용을 확인 및 수정하였다.
server {
root /usr/share/nginx/www;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
>PHP5-FPM 설정
PHP설정은 /etc/php5/fpm/pool.d/www.conf에서 아래 사항이 활성화 되었는지 확인한다.
listen = /var/run/php5-fpm.sock
4. 웹서버 가동하기
설정이 끝나면 저장하고 웹서버를 재가동이 필요하다.
$sudo service php5-fpm restart
$sudo service nginx restart
웹서버가 정상적으로 가동되면 해당 웹페이지로 가면 아래와 같이 화면이 표시된다.
PHP 실행 확인을 위해서는 웹서버 Root 폴더에 index.php파일을 만들어서 phpinfo를 출력하여 확인할 수 있다.
$sudo vi /usr/share/nginx/www/index.php
<?
phpinfo();
?>
파일 작성 후 웹브라우저에서 Raspberry Pi IP로 접속하고 index.php파일 오픈하면 아래와 같은 화면이 표시된다.
'IOE > Single Board' 카테고리의 다른 글
Raspberry Pi 웹 하드(Pydio) 구성하기 (0) | 2014.01.18 |
---|---|
[Raspberry Pi] 모니터, 키보드 없이 원격으로 사용하기(VNC) (0) | 2013.12.28 |