Rocky Linux에서 sudo dnf install epel-release을 했다는 전제 하에 쓰는 글입니다.
- 테스트 환경: Rocky Linux 9.5 aarch64 Raspberry Pi 3B
php-fpm 설치 #
sudo dnf install php-fpm
systemd 서비스 #
sudo systemctl start php-fpm
rocky에서 systemd 서비스 이름은 php-fpm이였다.
PHP 확장 설치 #
PHP 확장의 패키지 이름은 php-이름 인 식이다.
sudo dnf install php-gd
Nginx #
php-fpm패키지를 설치하면 자동으로 conf.d에 php-fpm.conf라는 파일이 생겨서 추가적인 설정 없이 바로 php를 사용할 수 있었다.
$ cat php-fpm.conf
# PHP-FPM FastCGI server
# network or unix domain socket configuration
upstream php-fpm {
server unix:/run/php-fpm/www.sock;
}
저 내용 만으로 php가 된다는 소린데 어떤 원리로 작동하는지 조금 더 분석이 필요할 것 같다.
저걸 지우고 다른 배포판처럼 써도 된다.
php-fpm 설정 #
ls -la /run/php-fpm/www.sock
srw-rw----+ 1 root root 0 Dec 13 16:41 /run/php-fpm/www.sock
기본적으로 소켓 이름이 www.sock이고 /run/php-fpm 경로에 있고 소유자,그룹이 모두 root였다.
설정파일은 /etc/php-fpm.d/www.conf 에 있는데 일부분을 가져오면
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php-fpm/www.sock
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
; mode is set to 0660
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; When set, listen.owner and listen.group are ignored
listen.acl_users = apache,nginx
;listen.acl_groups =
기본적으로 apache사용자,그룹이 PHP를 실행하게 되고 listen.acl_users 로 접근할 수 있는 사용자를 설졍하면 되는 듯 하다. 기본적으로 apache사용자와, nginx 사용자를 허용하는 것 같다.
소켓 파일의 소유자가 root인 것은 listen.owner = ,listen.group = listen.mode = 0660 이 부분이 주석처리 되어서 그런 것 같다. 만약 소켓 파일의 소유권을 바꿔야 한다면 저 부분을 수정해야 할 것 같다. 그리고 유닉스 소켓 대신 TCP통신으로 하고 싶다면 listen부분을 listen = localhost:9000으로 바꾸면 될 것이다.
사실 SELinux 때문에 복잡할 줄 알았는데 오히려 그것때문인지 패키지 설치할 때 자동으로 해주는지 간단하게 끝났다.