OS Linux[centos,RHEL]/CentOS RHEL7

APM -mysql /apache & Php 연동방법

infra 2021. 11. 20. 23:09

php를 구동하기 방식

 

3가지

 

 

APM 구동 원리

 

 

소스 컴파일 방식이 아닌 yum을 통해 구축방법.

 

1)Apache + PHP(mod_php)+ MySQL

2)Apache + PHP-FPM+ MySQL

 

OS : CentOS7.4

 

 

 

[root@centos7 yum.repos.d]# rpm -qa |grep yum-utils
yum-utils-1.1.31-54.el7_8.noarch
[root@centos7 yum.repos.d]# rpm -qa |grep epel-release
epel-release-7-11.noarch

 

 

 

 

더보기

[root@centos7 yum.repos.d]# rpm -ql wget
package wget is not installed
[root@centos7 yum.repos.d]# yum install wget
Loaded plugins: fastestmirror
base                                    | 3.6 kB  00:00:00
epel/x86_6/metalink                 | 7.1 kB  00:00:00
epel                                        | 4.7 kB  00:00:00
extras                                          | 2.9 kB  00:00:00
updates                                                             | 2.9 kB  00:00:00
(1/2): epel/x86_64/updateinfo                                                                                                                    | 1.0 MB  00:00:02
(2/2): epel/x86_64/primary_db                                                                                                                    | 7.0 MB  00:00:04
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * epel: ftp.iij.ad.jp
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                                   Version                                         Repository                            Size
========================================================================================================================================================================
Installing:
 wget                                 x86_64                                 1.14-18.el7_6.1                                 base                                 547 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Is this ok [y/d/N]: y
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                                                                                                  | 547 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                                                                          1/1
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                                                                          1/1

Installed:
  wget.x86_64 0:1.14-18.el7_6.1

 

 

[root@centos7 yum.repos.d]# yum info httpd
Loaded plugins: fastestmirror

...
Installed Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 97.el7.centos.1
Size        : 9.4 M
Repo        : installed
From repo   : updates
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.

Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 97.el7.centos.2
Size        : 2.7 M
Repo        : updates/7/x86_64
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.

[root@centos7 yum.repos.d]#

 mysql-community-server mysql-community-devel을 yum으로 설치하였 을 때 비로소 /etc/group과 /etc/passwd에

유저와 그룹에서 mysql이라는 default 유저계정/그룹계정이 생성된다.

 

 

더보기

 

[root@centos7 src]# cat /etc/group |wc -l; cat /etc/passwd |wc -l
50
30
[root@centos7 src]# yum -y install mysql-community-server mysql-community-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * epel: ftp.jaist.ac.jp
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.36-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-devel-5.7.36-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.20()(64bit) for package: mysql-community-devel-5.7.36-1.el7.x86_64
---> Package mysql-community-server.x86_64 0:5.7.36-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.36-1.el7 for package: mysql-community-server-5.7.36-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.36-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-client.x86_64 0:5.7.36-1.el7 will be installed
---> Package mysql-community-common.x86_64 0:5.7.36-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:5.7.36-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.36-1.el7 will be obsoleting
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-9.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                                Arch              Version                    Repository                    Size
========================================================================================================================
Installing:
 mysql-community-devel                  x86_64            5.7.36-1.el7               mysql57-community            3.9 M
 mysql-community-libs                   x86_64            5.7.36-1.el7               mysql57-community            2.4 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat            x86_64            5.7.36-1.el7               mysql57-community            1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                 x86_64            5.7.36-1.el7               mysql57-community            174 M
Installing for dependencies:
 mysql-community-client                 x86_64            5.7.36-1.el7               mysql57-community             25 M
 mysql-community-common                 x86_64            5.7.36-1.el7               mysql57-community            310 k
Updating for dependencies:
 postfix                                x86_64            2:2.10.1-9.el7             base                         2.4 M

Transaction Summary
========================================================================================================================
Install  4 Packages (+2 Dependent packages)
Upgrade             ( 1 Dependent package)

Total download size: 209 M
Downloading packages:
No Presto metadata available for base
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.36-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.36-1.el7.x86_64.rpm is not installed
(1/7): mysql-community-common-5.7.36-1.el7.x86_64.rpm                                            | 310 kB  00:00:00
(2/7): mysql-community-devel-5.7.36-1.el7.x86_64.rpm                                             | 3.9 MB  00:00:06
(3/7): mysql-community-libs-5.7.36-1.el7.x86_64.rpm                                              | 2.4 MB  00:00:02
(4/7): mysql-community-client-5.7.36-1.el7.x86_64.rpm                                            |  25 MB  00:00:09
(5/7): postfix-2.10.1-9.el7.x86_64.rpm                                                           | 2.4 MB  00:00:00
(6/7): mysql-community-libs-compat-5.7.36-1.el7.x86_64.rpm                                       | 1.2 MB  00:00:01
(7/7): mysql-community-server-5.7.36-1.el7.x86_64.rpm                                            | 174 MB  00:01:22
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   2.3 MB/s | 209 MB  00:01:32
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-11.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.36-1.el7.x86_64                                                           1/9
  Installing : mysql-community-libs-5.7.36-1.el7.x86_64                                                             2/9
  Installing : mysql-community-client-5.7.36-1.el7.x86_64                                                           3/9
  Installing : mysql-community-libs-compat-5.7.36-1.el7.x86_64                                                      4/9
  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                                                        5/9
  Installing : mysql-community-server-5.7.36-1.el7.x86_64                                                           6/9
  Installing : mysql-community-devel-5.7.36-1.el7.x86_64                                                            7/9
  Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                                                        8/9
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                   9/9
  Verifying  : mysql-community-libs-5.7.36-1.el7.x86_64                                                             1/9
  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                                        2/9
  Verifying  : mysql-community-common-5.7.36-1.el7.x86_64                                                           3/9
  Verifying  : mysql-community-server-5.7.36-1.el7.x86_64                                                           4/9
  Verifying  : mysql-community-devel-5.7.36-1.el7.x86_64                                                            5/9
  Verifying  : mysql-community-client-5.7.36-1.el7.x86_64                                                           6/9
  Verifying  : mysql-community-libs-compat-5.7.36-1.el7.x86_64                                                      7/9
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                   8/9
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                        9/9

Installed:
  mysql-community-devel.x86_64 0:5.7.36-1.el7                   mysql-community-libs.x86_64 0:5.7.36-1.el7
  mysql-community-libs-compat.x86_64 0:5.7.36-1.el7             mysql-community-server.x86_64 0:5.7.36-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.36-1.el7               mysql-community-common.x86_64 0:5.7.36-1.el7

Dependency Updated:
  postfix.x86_64 2:2.10.1-9.el7

Replaced:
  mariadb-libs.x86_64 1:5.5.56-2.el7

Complete!
[root@centos7 src]# cat /etc/group |wc -l; cat /etc/passwd |wc -l
51
31
[root@centos7 src]# cat /etc/group |grep -i mysql; cat /etc/passwd |grep -i mysql
mysql:x:27:
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/false

 

/etc/my.cnf 수정 전

 

user=mysql
innodb_buffer_pool_size = 384M
innodb_file_per_table=ON
bind-address=0.0.0.0
character-set-client-handshake=OFF
skip-character-set-client-handshake
init-connect=SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci'
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
secure-file-priv=""
show_compatibility_56 = On
log_timestamps=SYSTEM
innodb_buffer_pool_load_at_startup = ON
innodb_buffer_pool_dump_at_shutdown = ON
max_connections = 1000
 
[mysqld_safe]
open-files-limit = 16384
 
 
 
을 /etc/my.cnf에 추가한다.
 

ulimit 설정 추가

[root]# vi /etc/security/limits.conf
apache 와 mysql 유저에 대한 ulimit 값을 추가로 설정을 합니다.

 
apache hard nofile 65536
apache soft nofile 65536
apache soft nproc 16384
apache hard nproc 16384
 
mysql hard nofile 65536
mysql soft nofile 65536
mysql soft nproc 16384
mysql hard nproc 16384

 


[root@centos7 ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper

 


2. PHP 설치

 

php 최신버젼을 더 추가해서 확인하려면, remi repository를 받아야 한다.

 

#yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

 

remi 관련 파일은 15개가 있다.

여기서 remi.repo에 vi editor 를 활용하여, 10번째 줄 enabled=0이었던 것을 1로 변경하면 된다.

 

 

remi repository 다운 받은 후의 관련 파일 경로(/etc/yum.repos.d)

yum list |grep php 로도 확인 가능함.

 

enabled=0 -&amp;gt;1 로 변경

 

 

설정 변경하기 (mod_php & php-fpm 방식에서도 동일하게 설정하는 것)

 

# vi /etc/opt/remi/php74/php.ini

아래 5개는 주석 제거 및 내용을 해당 정보로 수정


date.timezone = Asia/Seoul
expose_php = Off

post_max_size = 500M
upload_max_filesize = 200M
memory_limit = 512M

 

설명
/etc/opt/remi/php74/php.ini 의 줄 위치
변경 전의 default value 변경 후
날짜/ 시간장소 , 925번째 줄 #date.timezone = date.timezone = Asia/Seoul
php 노출 On-> Off  379번째 줄 expose_php = On expose_php = Off
post 최대 사이즈  696번째 줄 post_max_size = 8M post_max_size = 500M
업로드 최대 파일 사이즈   849번째 줄 upload_max_filesize = 2M upload_max_filesize = 200M
메모리 제한   411번째 줄 memory_limit = 128M memory_limit = 512M

apache 와 php 연동 방식 2가지 중

 

우선 apache와 mod_php 와의 연동 방법부터 알아보고, 나중에 apache와 php-fpm 연동방법을 알아보자

1. apache mod_php 연동

1-1 apache 설정 변경하기

설명
/etc/httpd/conf/httpd.conf 의 줄 위치
변경 전의 default value 변경 후
 95번째 줄 #ServerName www.example.com:80 ServerName www.example.com:80
144번째 줄
#Options Indexes FollowSymLinks
Options MultiViews FollowSymLinks
151번째 줄 #AllowOverride None AllowOverride All

 

 

1-2. php 연동 확인 하기 위해 phpinfo.php 파일 생성 후 테스트

 

 #vi /var/www/html/phpinfo.php

<?php

phpinfo();
?>

 

1-3. OS 방화벽 open

# 80 포트 추가(http)  /https : 443 포트

 

firewall-cmd --permanent --add-port=80/tcp

# 정책 재반영 및 방화벽 정책 확인
firewall-cmd --reload;firewall-cmd --list-all

 

1-4 apache 재시작 및 php load 파악

http://ip주소/phpinfo.php 후 해당 서버의 IP를 입력해서 확인하기

 


apache와 php-fpm 연동방법

 

1. apache  설정 변경하기

 

 

vi /etc/httpd/conf/httpd.conf

 

-> 아래 쪽에 2개 내용추가
ServerTokens Prod
ServerSignature Off

 

: 사용자 요청에 대해서 Apache Http 서버의 Version이나,

OS 정보를 Response로 전달하는데, 이를 전달하지 않아야 한다.

 

 

'OS Linux[centos,RHEL] > CentOS RHEL7' 카테고리의 다른 글

device eth0 has different MAC address than expected, ignoring.  (0) 2022.03.20
mysql 로그  (0) 2021.11.20