LoginSignup
0
0

More than 1 year has passed since last update.

CentOS 8にPHP 7.4をRemi Repositoryからインストールする

Posted at

What's?

CentOS 8に標準リポジトリからPHP 7.4をインストールする記事を書いてみたのですが、今度はRemi Repositoryからインストールしてみたいと思います。

環境

今回の環境は、こちら。CentOS 8.4です。

/etc/redhat-release
CentOS Linux release 8.4.2105


$ uname -srvmpio
Linux 4.18.0-305.19.1.el8_4.x86_64 #1 SMP Wed Sep 15 15:39:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Remi Repository

Remi Repositoryがなんであるかは、こちらを。

利用については自己責任ですが、最新のPHPスタックが使えるリポジトリです。

Which are the goals of this repository ?

Remi Repositoryを有効にして、PHP 7.4をインストールする

Remi Repositoryのインストール方法は、こちらに記載されています。

Remi Repositoryのインストール。

$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

これくらいのバージョンのPHPが使用できるようになります。

$ dnf search php | grep -E '^php..-' | perl -wp -e 's!^(php\d\d)-.+!$1!' | sort -u
Last metadata expiration check: 0:01:43 ago on 2021年11月09日 19時15分56秒.
php56
php70
php71
php72
php73
php74
php80
php81

dnf module listで見た場合。

$ dnf module list php
Last metadata expiration check: 0:00:11 ago on 2021年11月09日 19時15分56秒.
CentOS Linux 8 - AppStream
Name        Stream          Profiles                          Summary
php         7.2 [d]         common [d], devel, minimal        PHP scripting language
php         7.3             common [d], devel, minimal        PHP scripting language
php         7.4             common [d], devel, minimal        PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name        Stream          Profiles                          Summary
php         remi-7.2        common [d], devel, minimal        PHP scripting language
php         remi-7.3        common [d], devel, minimal        PHP scripting language
php         remi-7.4        common [d], devel, minimal        PHP scripting language
php         remi-8.0        common [d], devel, minimal        PHP scripting language
php         remi-8.1        common [d], devel, minimal        PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

dnf dnf install php74と、モジュールインストールするののどちらが良いかで迷うのですが。
それぞれ見てみましょう。

sudo dnf install php74の場合にインストールされるパッケージ。

$ sudo dnf install php74
Last metadata expiration check: 0:06:04 ago on 2021年11月09日 19時18分13秒.
Dependencies resolved.
==========================================================================================
 Package                       Arch    Version                           Repository  Size
==========================================================================================
Installing:
 php74                         x86_64  1.0-3.el8.remi                    remi-safe  6.8 k
Installing dependencies:
 checkpolicy                   x86_64  2.9-1.el8                         baseos     348 k
 environment-modules           x86_64  4.5.2-1.el8                       baseos     421 k
 php74-php-cli                 x86_64  7.4.25-1.el8.remi                 remi-safe  3.1 M
 php74-php-common              x86_64  7.4.25-1.el8.remi                 remi-safe  710 k
 php74-php-json                x86_64  7.4.25-1.el8.remi                 remi-safe   81 k
 php74-runtime                 x86_64  1.0-3.el8.remi                    remi-safe  1.1 M
 policycoreutils-python-utils  noarch  2.9-14.el8                        baseos     252 k
 python3-audit                 x86_64  3.0-0.17.20191104git1c2f876.el8   baseos      86 k
 python3-libsemanage           x86_64  2.9-6.el8                         baseos     127 k
 python3-policycoreutils       noarch  2.9-14.el8                        baseos     2.2 M
 python3-setools               x86_64  4.3.0-2.el8                       baseos     626 k
 scl-utils                     x86_64  1:2.0.2-13.el8                    appstream   47 k
 tcl                           x86_64  1:8.6.8-2.el8                     baseos     1.1 M

sudo dnf module install php:remi-7.4の場合にインストールされるパッケージ。

$ sudo dnf module install php:remi-7.4
Last metadata expiration check: 0:00:28 ago on 2021年11月09日 19時18分13秒.
Dependencies resolved.
==========================================================================================
 Package           Arch    Version                                    Repository     Size
==========================================================================================
Installing group/module packages:
 php-cli           x86_64  7.4.25-1.el8.remi                          remi-modular  4.6 M
 php-common        x86_64  7.4.25-1.el8.remi                          remi-modular  1.2 M
 php-fpm           x86_64  7.4.25-1.el8.remi                          remi-modular  1.6 M
 php-mbstring      x86_64  7.4.25-1.el8.remi                          remi-modular  530 k
 php-xml           x86_64  7.4.25-1.el8.remi                          remi-modular  217 k
Installing dependencies:
 httpd-filesystem  noarch  2.4.37-39.module_el8.4.0+950+0577e6ac.1    appstream      39 k
 libxslt           x86_64  1.1.32-6.el8                               baseos        250 k
 oniguruma5php     x86_64  6.9.7.1-1.el8.remi                         remi-safe     210 k
 php-json          x86_64  7.4.25-1.el8.remi                          remi-modular   78 k
Installing weak dependencies:
 nginx-filesystem  noarch  1:1.14.1-9.module_el8.0.0+184+e34fea82     appstream      24 k
Installing module profiles:
 php/common
Enabling module streams:
 httpd                     2.4
 nginx                     1.14
 php                       remi-7.4

sudo dnf module install php:remi-7.4の方が、FPMやApacheやnginxの設定ファイルが入るなどすぐに使い始められそうなので、こちらを使うことにします。

$ sudo dnf module install php:remi-7.4

バージョン確認。現時点でのPHP 7.4の最新バージョンが入りました。

$ php --version
PHP 7.4.25 (cli) (built: Oct 19 2021 15:18:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

dnf module list phpで確認。

$ dnf module list php
Last metadata expiration check: 0:13:34 ago on 2021年11月09日 19時15分56秒.
CentOS Linux 8 - AppStream
Name      Stream            Profiles                            Summary
php       7.2 [d]           common [d], devel, minimal          PHP scripting language
php       7.3               common [d], devel, minimal          PHP scripting language
php       7.4               common [d], devel, minimal          PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name      Stream            Profiles                            Summary
php       remi-7.2          common [d], devel, minimal          PHP scripting language
php       remi-7.3          common [d], devel, minimal          PHP scripting language
php       remi-7.4 [e]      common [d] [i], devel, minimal      PHP scripting language
php       remi-8.0          common [d], devel, minimal          PHP scripting language
php       remi-8.1          common [d], devel, minimal          PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

この時点で、Apacheやnginxの設定ファイルもインストールされます。

$ find /etc/nginx /etc/httpd -type f
/etc/nginx/conf.d/php-fpm.conf
/etc/nginx/default.d/php.conf
/etc/httpd/conf.d/README
/etc/httpd/conf.d/php.conf

Apacheをインストールして動作確認する

インストールされた、Apacheの設定ファイルを確認してみます。

$ grep -v '^ *#' /etc/httpd/conf.d/php.conf
<Files ".user.ini">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
    </IfModule>
</Files>

AddType text/html .php

DirectoryIndex index.php

<IfModule  mod_php7.c>
    <FilesMatch \.(php|phar)$>
        SetHandler application/x-httpd-php
    </FilesMatch>


    php_value session.save_handler "files"
    php_value session.save_path    "/var/lib/php/session"
    php_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"

</IfModule>

<IfModule !mod_php5.c>
  <IfModule !mod_php7.c>
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch \.(php|phar)$>
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
  </IfModule>
</IfModule>

mod_php、FPMの両方で使えそうです。今回は、FPMを使うことになります。

Apacheをインストール。

$ sudo dnf install httpd

バージョン確認。

$ httpd -V
Server version: Apache/2.4.37 (centos)
Server built:   Oct 12 2021 23:35:12
Server's Module Magic Number: 20120211:83
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

DocumentRootにPHPファイルを用意して

/var/www/html/index.php
<?php

phpinfo();

Apacheを起動。

$ sudo systemctl enable httpd
$ sudo systemctl start httpd

http://localhostにアクセスすると、PHPが動作しているのが確認できます。

image.png

Server APIFPM/FastCGIですね。

余談

一緒にインストールされた、nginx用の設定ファイルも載せておきます。

/etc/nginx/conf.d/php-fpm.conf
# PHP-FPM FastCGI server
# network or unix domain socket configuration

upstream php-fpm {
        server unix:/run/php-fpm/www.sock;
}
/etc/nginx/default.d/php.conf
# pass the PHP scripts to FastCGI server
#
# See conf.d/php-fpm.conf for socket configuration
#
index index.php index.html index.htm;

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_intercept_errors on;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_pass   php-fpm;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0