DEV LOGS
[Centos7]PHP 설치 및 nginx와 연동하기
라디스타
2018. 7. 29. 02:22
1. PHP, PHP-RPM , PHP-FPM 설치
1 | sudo yum install php php-mysql php-fpm | cs |
2. PHP-FPM의 www.conf를 수정하여 PHP로 접속 받을 주소를 수정
- Terminal
1 | sudo vi /etc/php-fpm.d/www.conf | cs |
- vi 에디터
(1) listen = 127.0.0.1:9000 해당 부분을 찾아 아래와 같이 수정
1 | listen = /var/run/php-fpm/php-fpm.sock | cs |
3. PHP-FPM을 시작 및 부팅시 자동 실행 활성화
1 2 | system start php-fpm system enable php-fpm.service | cs |
4. nginx 설정 파일을 수정
1 | vi /etc/nginx/conf.d/default.conf | cs |
- 다음과 같이 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; root /usr/share/nginx/html; location / { index index.html index.htm index.php; } #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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } | cs |
8줄 |
바로 아래에 location 구문 안에 있던 root를 밖으로 가져왔다. |
10줄 |
index.php 를 추가하였다. |
30-35줄 |
.php에 대한 처리 과정을 추가하였다. |
5. nginx를 다시 시작
1 | systemctl restart nginx; | cs |
6. 다시 시작이 잘되었다면 연동이 완료 된것이다. 간단한 phpinfo()를 호출하는 php파일을 추가하여 각자 테스트 해보기