PHP7 yum Install

Server

(Update : 2019-12-25)

Language :

환경: CentOS7.5 Minimal, Apache 2.4.6

CentOS의 yum은 기본적으로 PHP 5.X를 설치한다.
PHP 7을 설치하기 위해 저장소를 추가한다.

EPEL Repository (Extra Packages for Enterprise Linux)

PHP Package를 가진 Repository를 추가하려면 epel-release가 필요하다.

epel-release는 CentOS의 Extras Repository에 포함되어 있다.

  • Extras Repository 활성화 확인
# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
repo id                                          repo name                                 status
base/7/x86_64                                    CentOS-7 - Base                           9,911
extras/7/x86_64                                  CentOS-7 - Extras                           434
mysql-connectors-community/x86_64                MySQL Connectors Community                   74
mysql-tools-community/x86_64                     MySQL Tools Community                        74
mysql80-community/x86_64                         MySQL 8.0 Community Server                   49
updates/7/x86_64                                 CentOS-7 - Updates                        1,614
repolist: 12,156
  • EPEL Repository 설치
# yum -y install epel-release
(... skip ...)
Installed:
  epel-release.noarch 0:7-11                                                                     

Complete!

- 설치가 안될 경우 RPM을 통해 설치

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm(을)를 복구합니다
경고: /var/tmp/rpm-tmp.t2qq0Z: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
준비 중...                         ################################# [100%]
Updating / installing...
   1:epel-release-7-11                ################################# [100%]
  • Package Update
# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                | 6.7 kB  00:00:00     
 * base: mirror.navercorp.com
 * epel: mirror01.idc.hinet.net
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
epel                                                                                                                                      | 3.2 kB  00:00:00     
epel/x86_64/primary            FAILED               [                                                             ]  0.0 B/s |    0 B  --:--:-- ETA 
http://mirror.horizon.vn/epel/7/x86_64/repodata/4807700d4512e26d1bcf0962b2ad370406fc75086765310124823fb7838aeb18-primary.xml.gz: [Errno 14] curl#52 - "Empty reply from server"ETA 
Trying other mirror.
(1/3): epel/x86_64/updateinfo                                                                                                     | 934 kB  00:00:00     
(2/3): epel/x86_64/group_gz                                                                                                       |  88 kB  00:00:00     
(3/3): epel/x86_64/primary                                                                                                         | 3.6 MB  00:00:05     
epel                                                                                                                                            12724/12724
Resolving Dependencies
(... skip ...)
Install   1 Package
Upgrade  81 Packages

Total download size: 178 M
Is this ok [y/d/N]: y
Downloading packages:
(... skip ...)
Complete!
  • 설치 확인
# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * epel: mirror.premi.st
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
repo id                                                       repo name                                                                            status
base/7/x86_64                                             CentOS-7 - Base                                                                      9,911
epel/x86_64                                                Extra Packages for Enterprise Linux 7 - x86_64                               12,724
extras/7/x86_64                                           CentOS-7 - Extras                                                                       434
mysql-connectors-community/x86_64               MySQL Connectors Community                                                       74
mysql-tools-community/x86_64                       MySQL Tools Community                                                              74
mysql80-community/x86_64                           MySQL 8.0 Community Server                                                         49
updates/7/x86_64                                        CentOS-7 - Updates                                                                  1,614
repolist: 24,880  

IUS Repository (Inline with Upstream Stable)

PHP, MySQL, Python 등의 최신 버전 패키지를 제공한다.

# rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm
https://centos7.iuscommunity.org/ius-release.rpm(을)를 복구합니다
경고: /var/tmp/rpm-tmp.JTleQy: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
준비 중...                         ################################# [100%]
Updating / installing...
   1:ius-release-1.0-15.ius.centos7   ################################# [100%]

- 설치되지 않을 경우 IUS에서 wget을 통해 rpm 파일을 가져와서 설치한다.

PHP 설치

# yum --enablerepo=ius -y install mod_php72u
(... skip ...)
Installed:
  mod_php72u.x86_64 0:7.2.12-1.ius.centos7                                

Dependency Installed:
  libargon2.x86_64 0:20161029-2.el7                                       
  php72u-common.x86_64 0:7.2.12-1.ius.centos7                             

Complete!
# yum --enablerepo=ius -y install php72u-*
(... skip ...)
Complete!

PHP 설정 파일 변경

# vi /etc/php.ini
197 short_open_tag = On
460 error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT ^E_NOTICE
691 default_charset = "UTF-8"
902 date.timezone = "Asia/Seoul"

date.timezone은 주석 제거

Apache PHP 설정

# vi /etc/httpd/conf/httpd.conf
(... skip ...)
160     #
161     # DirectoryIndex: sets the file that Apache will serve if a directory
162     # is requested.
163     #
164     <ifmodule dir_module="">
165         DirectoryIndex index.html index.htm index.php
166     </ifmodule>
(... skip ...)
269     #
270     # AddType allows you to add to or override the MIME configuration
271     # file specified in TypesConfig for specific file types.
272     #
273     #AddType application/x-gzip .tgz
274     #
275     # AddEncoding allows you to have certain browsers uncompress
276     # information on the fly. Note: Not all browsers support this.
277     #
278     #AddEncoding x-compress .Z
279     #AddEncoding x-gzip .gz .tgz
280     #
281     # If the AddEncoding directives above are commented-out, then you
282     # probably should define those extensions to indicate media types:
283     #
284     AddType application/x-compress .Z
285     AddType application/x-gzip .gz .tgz
286     AddType application/x-httpd-php .php .html .htm .inc
287     AddType application/x-httpd-php-source .phps
(... skip ...)

.php 파일 생성

html yum 설치 시 기본 경로: /var/www/html/

# vi /var/www/html/phpinfo.php
<?php phpinfo(); ?>

Apache 재시작

설정 적용

# systemctl restart httpd

PHP 확인

http://localhost/phpinfo.php

민갤

Back-End Developer

백엔드 개발자입니다.