티스토리 뷰

Ubuntu 에서 간단하게 apt를 이용하여 nginx 와 php를 설치하는 방법입니다.

apt 를 이용함으로 기본적으로 root 사용자를 이용합니다.


1. nginx 설치

$apt-get install nginx

설치하셨다면 IP로 http 접속시 아래와 같은 화면을 보실수 있으실것입니다.





nginx 의 버전 체크는 

$nginx -v

로 확인하실수 있습니다.






2. php-fpm 설치하기


php 역시 빠르게 설치하기위해 apt-get install 을 이용하여 설치해 주도록합니다.

$apt-get install php5-fpm


3. nginx 설정 및 php 연동하기


nginx 를 설정하여 php를 연결할 차례 입니다. 아래와 같이 /etc/nginx/sites-available/default 를 열어 수정하도록 합니다.

$vim /etc/nginx/sites-available/default

일단 기본 주소를 이용하기때문에 index에 index.php 를 추가해주시고 root 를 변경 후 php 부분의 주석을 제거해주도록 합니다.

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; #default root /var/www/; #Your root directory index index.php index.html index.htm; # ADD 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 displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests #location /RequestDenied { # proxy_pass http://127.0.0.1:8080; #} #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/html; #} # 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파일을 만들어 주도록합니다. 위의 설정에서 root /var/www/ 에서 보다시피 저는 root를 /var/www/ 에 연결 하였기 때문에 해당 폴더로 이동 혹은 생성하여 index.php 를 생성하여 주도록 합니다.

$cd /var
$mkdir www
$chown user:user www
$cd www/
$vim index.php

파을을 생성하고 아래와 같이 php 정보를 읽는 코드를 써줍니다.

<?php
        phpinfo();
?>

이제 저장 후 index.php 의 권한을 다시 user 로 설정 그리고 nginx 를 reload 혹은 restart 해주도록 합니다.

$chown user:user ./index.php
$service nginx reload

이제 이전에 nginx 를 테스트 하였던 페이지로 이동하여 phpinfo() 를 통해 만들어진 정보 페이지를 확인합니다.




위와 같이 php 의 정보를 보여주는 페이지가 뜬다면 php 를 개발할수 있는 기본적인 환경이 완료된 것 입니다.


공유하기 링크
댓글