맛집 여행 캠핑 일상 생활

[CentOS] 8 Stream APACHE + PHP-FPM PHP Multiple 설치 방법 본문

LAMP

[CentOS] 8 Stream APACHE + PHP-FPM PHP Multiple 설치 방법

영은파더♥ 2023. 1. 31. 17:13

이번에는 오라클 클라우드 VM에 CentOS 8 Stream 버전에서 아파치 + PHP-FPM 여러버전 설치하는 방법입니다.

 

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf -y install httpd nginx mod_ssl
dnf -y install php php-fpm
dnf -y module reset php
dnf -y module enable php:remi-7.3
dnf -y update

디폴트 PHP 버전은 7.3으로 설정하겠습니다. ( CentOS 8 Stream은 PHP 디폴트가 v7.2 )

디폴트 버전 7.3 버전으로 설정해서 dnf update 를 하면 PHP 기본 버전이 변경됩니다.
PHP 8.2 버전을 설치하려면 php 패키지가 설치된 상태에서 아래 두줄로 8.2버전으로 업데이트가 가능합니다.
    dnf -y module reset php
    dnf -y module enable php:remi-7.3
    dnf -y update
CentOS 7.x 버전의 yum-config-manager --enable remi-php73 이렇게 해주는 것과는 방식이 다릅니다.

이제 PHP 다른 버전을 설치합니다.

dnf -y install php74 php74-php-fpm
dnf -y install php81 php81-php-fpm
dnf -y install php82 php82-php-fpm

설치가 되면 각 버전별로 php.ini 파일을 수정하셔야 합니다. ( default 는 /etc/php.ini )

vi /etc/opt/remi/php74/php.ini
vi /etc/opt/remi/php81/php.ini
vi /etc/opt/remi/php82/php.ini

그리고 conf 파일을 수정합니다.

vi /etc/opt/remi/php74/php-fpm.d/www.conf
vi /etc/opt/remi/php81/php-fpm.d/www.conf
vi /etc/opt/remi/php82/php-fpm.d/www.conf

[www] 이부분을 원하시는 도메인으로 변경합니다.

; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www.example.com]

user = apache
group = apache

; 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 = example
; RPM: Keep a group allowed to write in log dir.
group = example

이 부분도 유저아이디로 변경합니다.

이번엔 listen 부분은 소켓 방식으로 하겠습니다.

 

useradd example
mkdir /home/example/www /home/example/www/v81 /home/example/www/v82
cat << EOF > /home/example/www/index.html
<?
  phpinfo();
?>
EOF
cp /home/example/www/index.html /home/example/www/v81/index.html
cp /home/example/www/index.html /home/example/www/v82/index.html
chown -R example:example /home/example/www

CentOS 8 Stream 버전에서는 chmod 755 /home/example 명령어로 퍼미션을 조절해야 작동하네요~

이제 VirtualHost 설정을 합니다.

<VirtualHost *:80>
    ServerName www.example.com
    DocumentRoot /home/example/www
    <Directory "/home/example/www">
        <FilesMatch \.(php|htm|html)$>
            #SetHandler "proxy:fcgi://127.0.0.1:9074/"
            SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost
        </FilesMatch>
    </Directory>
    <Directory "/home/example/www/v81">
        <FilesMatch \.(php|htm|html)$>
            #SetHandler "proxy:fcgi://127.0.0.1:9081/"
            SetHandler "proxy:unix:/var/opt/remi/php81/run/php-fpm/www.sock|fcgi://localhost
        </FilesMatch>
    </Directory>
    <Directory "/home/example/www/v82">
        <FilesMatch \.(php|htm|html)$>
            #SetHandler "proxy:fcgi://127.0.0.1:9082/"
            SetHandler "proxy:unix:/var/opt/remi/php82/run/php-fpm/www.sock|fcgi://localhost
        </FilesMatch>
    </Directory>
</VirtualHost>

CentOS 8 Stream 버전에서는 루트 디렉토리도 SetHandler로 php 버전을 지정해주어야 작동하는군요~
설정을 안해주면 php가 실행되지 않고 그냥 브라우저에서 파일로 다운로드가 되는 문제점이 있습니다.

systemctl enable php74-php-fpm
systemctl enable php81-php-fpm
systemctl enable php82-php-fpm
systemctl start php74-php-fpm
systemctl start php81-php-fpm
systemctl start php82-php-fpm
systemctl restart httpd

브라우저에서 한번 확인해보시기 바랍니다.

 

 

 

Trackback : | Comments :