nginx를 설치하지 않으신 분들은 이전 강의(#1)를 참고해주세요.
PHP 설치하기
homebrew에 php 패키지가 있는지 확인해봅시다.
1 2 3 4 5 6
| ==> Formulae brew-php-switcher php-cs-fixer php@7.4 phpmd phpunit php php@7.2 phpbrew phpmyadmin php-code-sniffer php@7.3 phplint phpstan ==> Casks homebrew/cask/eclipse-php homebrew/cask/netbeans-php
|
php 패키지가 존재한다.
info 명령어로 좀 더 자세하게 확인해봅시다.
1 2 3 4 5
| php: stable 8.0.3 (bottled), HEAD ... The php.ini and php-fpm.ini file can be found in: /opt/homebrew/etc/php/8.0/ ...
|
php 8 버전이군요.
7 버전을 원하시면 php@7.x 이렇게 설치하시면 될 것 같다.
설치 후 php.ini
라는 파일이 중요하니 대충 저런곳에 있구나라고 기억해둡시다.
PHP 백그라운드에서 실행
위 명령어를 실행하면 PHP 프로그램을 백그라운드에서 실행하기 위한 php-fpm이 9000번 포트에 실행된다.
NGINX와 연동
nginx.conf 파일을 열어줍니다.
1
| sudo vim /opt/homebrew/etc/nginx/nginx.conf
|
index에 index.php를 추가해주시고 fastcgi 부분을 활성화해준다.
또, fastcgi_param 부분에서 /scripts를 $document_root로 바꿔줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13
| location / { root html; index index.html index.htm index.php; }
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
|
$document_root는 웹 루트 디렉토리 값 이다.
저는 웹 루트 경로가 /opt/homebrew/Cellar/nginx/1.19.8/html
이다.
웹 루트에서 index.html을 지우고 index.php를 작성한다.
.
1 2
| rm index.html echo '<?php phpinfo(); ?>' > index.php
|
nginx를 다시 시작한다.
1
| brew services restart nginx
|
http://localhost에 접속해봅니다.

완료!