﻿/* ========================================================
NAME : CentOS8_APM
DATE : 2021.09.10
E-MAIL : rf114@daum.net
URL : http://www.rf114.com
======================================================== */
# uname -a = 리눅스버전체크
# cat /etc/redhat-release = CentOS버전체크
# df -h = 하드용량체크
# free -m = 메모리체크
# cat /proc/cpuinfo | grep processor | wc -l = CPU코어수확인
# cat /proc/cpuinfo | grep processor
# cat /proc/cpuinfo
# ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime = 시스템시간설정
# yum list installed | grep 검색어입력
# yum remove -y httpd
# yum remove -y mariadb
-----------------------------------------------------------
[Apache + PHP + MySQL 설치]
-----------------------------------------------------------
[RF114::Apache 2.4 설치]
-----------------------------------------------------------
# yum -y install gcc* openssl* make apr apr-util apr-util-devel pcre-devel
# wget https://dlcdn.apache.org/httpd/httpd-2.4.48.tar.gz
# tar xvfz httpd-2.4.48.tar.gz
# cd httpd-2.4.48
# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --enable-modules=shared --enable-mods-shared=all --enable-apr --with-mpm=prefork --enable-apr-util
# make && make install
#
# 설치중에 에러나면
# gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
# dnf install redhat-rpm-config
#
# vi /etc/systemd/system/apachectl.service
[Unit]
Description=The Apache HTTP Server

[Service]
Type=forking
#EnvironmentFile=/usr/local/apache/bin/envvars
PIDFile=/usr/local/apache/logs/httpd.pid
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/usr/local/apache/bin/apachectl graceful
ExecStop=/usr/local/apache/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
#
# systemctl daemon-reload
# systemctl enable apachectl
# systemctl start apachectl
# netstat -nltp
#
-----------------------------------------------------------
[RF114::mysql YUM 설치]
-----------------------------------------------------------
- https://velog.io/@devyang97/CentOS-8-MariaDB-%EC%84%A4%EC%B9%98
- https://engineeringcode.tistory.com/107
#
# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
# yum install MariaDB-server
# systemctl enable mariadb
# systemctl start mariadb
# mysql_secure_installation
# vi /etc/my.cnf.d/server.cnf
에디터가 열리면 [mysqld] 아래에
port = 3306
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
입력하고 저장
# systemctl restart mariadb
#
# firewall-cmd --permanent --add-port=3306/tcp
# firewall-cmd --reload
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
#
# yum list installed mariadb\*
# yum remove MariaDB-server.x86_64
# rm -rf /etc/my.cnf*
# rm -rf /var/log/mysql
# rm -rf /var/lib/mysql
-----------------------------------------------------------
[RF114::mysql REMI 설치]
-----------------------------------------------------------
# vi /etc/yum.repos.d/mariadb.repo
#
# MariaDB 10.6 CentOS repository list - created 2020-01-19 02:20 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.6/centos8-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

# dnf install boost-program-options
# dnf install MariaDB-server MariaDB-client --disablerepo=AppStream
# systemctl start mariadb
# systemctl stop mariadb
# systemctl status mariadb
-----------------------------------------------------------
[RF114::mysql 컴파일설치]
-----------------------------------------------------------
# wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
# tar xvfz boost_1_59_0.tar.gz
# mv boost_1_59_0 /usr/local/include/boost
# cd /usr/local/include/boost
# ./bootstrap.sh
# ./b2 install
#
# wget http://www.rf114.com/webdir/INSTALL/APM/mysql-5.7.14.tar.gz
# tar xvfz mysql-5.7.14.tar.gz 
# cd /usr/local/src/mysql-5.7.14/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DMYSQL_TCP_PORT=3306 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci
# make && make install
# cp -arp support-files/my-default.cnf /etc/my.cnf
# /usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
#
# chown -R mysql.mysql /usr/local/mysql/
# chmod 711 /usr/local/mysql
# chmod 700 /usr/local/mysql/data
# chmod 751 /usr/local/mysql/bin
# chmod 750 /usr/local/mysql/bin/*
# chmod 755 /usr/local/mysql/bin/mysql
# chmod 755 /usr/local/mysql/bin/mysqldump
# vi /etc/systemd/system/mysql.service 
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
Alias=mysql.service

[Service]
User=mysql
Group=mysql
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables etc.
#ExecStartPre=
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld_safe
# Don't signal startup success before a ping works
#ExecStartPost=
# Give up if ping don't get an answer
TimeoutSec=300
Restart=always
PrivateTmp=false
#
# systemctl daemon-reload
# systemctl enable mysql
# systemctl start mysql
# netstat -nltp
# vi /etc/profile
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
alias mysqldump='/usr/local/mysql/bin/mysqldump'
#
# source /etc/profile
# cat /root/.mysql_secret
# mysqladmin -u root -p password
#
# 비번분실시
# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
# mysql -uroot -p
# > UPDATE mysql.user SET authentication_string = PASSWORD('qwer@1234') WHERE User = 'root' AND Host = 'localhost';
#
# ./mysql -u root -p mysql -S /tmp/mysql.sock
#
출처: https://yoo-hyeok.tistory.com/67 [유혁의 개발 스토리]
#
# vi /etc/my.cnf
#
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
#
[mysql]
no-auto-rehash
show-warnings
prompt = \u@\h:\d\_\R:\m:\\s>
pager = "less -n -i -F -X -E"
#
[mysqldump]
max_allowed_packet = 16M
#
[mysqld_safe]
socket = /tmp/mysql.sock
nice = 0
#
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
character-set-client-handshake = FALSE
init_connect = "SET collation_connection = utf8_general_ci"
init_connect = "SET NAMES utf8"
#
socket = /tmp/mysql.sock
pid-file = /tmp/mysqld.pid
log-error = /usr/local/mysql/data/mysqld.log
datadir = /usr/local/mysql/data
basedir = /usr/local/mysql
user = mysql
#
skip-host-cache
skip-external-locking
skip-name-resolve
event-scheduler = off
sysdate-is-now
log-slave-updates
explicit_defaults_for_timestamp
expire_logs_days = 10
key_buffer_size = 384M
max_allowed_packet = 1M
#
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
#
query_cache_size = 32M
back_log = 100
max_connections = 1000
max_connect_errors = 1000
max_allowed_packet = 32M
max_aheap_table_size = 32M
thread_cache_size = 8
tmp_table_size = 512K
table_open_cache = 512
wait_timeout= 120
symbolic-links = 0
#
[innoDB]
default-storage-engine = InnoDB
skip-innodb
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 512M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 50
innodb_flush_method = O_DSYNC
innodb_buffer_pool_chunk_size = 3006477107
innodb_buffer_pool_instances = 16
innodb_buffer_pool_size = 1024M

-----------------------------------------------------------
[RF114::php 설치]
-----------------------------------------------------------
- https://susoterran.github.io/websrv/php_install/

# yum -y install gmp gmp-devel pam-devel libicu-devel net-snmp-devel libxml2-devel bzip2-devel curl-devel libpng-devel libjpeg-devel gdbm-devel freetype-devel
#
# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz --no-check-certificate
# tar zxvf libiconv-1.15.tar.gz
# cd libiconv-1.15
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64
# make && make install
#
# wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz --no-check-certificate
# tar xvfz libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8/
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64
# make && make install
# /sbin/ldconfig
# cd libltdl/
# ./configure --enable-ltdl-install --libdir=/usr/local/lib64
# make && make install
#
# wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz --no-check-certificate
# tar xvfz mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64
# make && make install
#
# wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz --no-check-certificate
# tar xvfz mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8/
# vi /etc/ld.so.conf
/usr/local/lib64
# /sbin/ldconfig
# ./configure --prefix=/usr/local --libdir=/usr/local/lib64
# make && make install
#
# 기타 의존성 라이브러리 설치
# yum -y install make zlib curl gcc cpp gcc-c++ libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
# OS가 CentOS 7 이상 인 경우
# yum -y install epel-release
# yum -y install uw-imap-devel
#
# wget http://www.rf114.com/webdir/INSTALL/APM/php-5.6.40.tar.gz
# tar zxvf php-5.6.40.tar.gz
# cd  php-5.6.40/
# LIBS="-liconv"
# export LIBS
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd --with-png-dir --with-zlib-dir --with-jpeg-dir --with-kerberos --with-freetype-dir --enable-mbstring --enable-sockets --disable-debug --enable-gd-native-ttf --enable-dba=shared --with-iconv-dir=/usr/local/lib64 --with-mhash --with-curl --enable-opcache --with-mcrypt --with-mysqli=/usr/local/mysql/bin/mysql_config
# make && make install
# 에러해결 : https://darksharavim.tistory.com/42
#
# vi /usr/local/apache/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html index.php   -> index.php를 추가
</IfModule>
~~~
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
-> 아래의 옵션 2개를 추가
AddType application/x-httpd-php .php .htm
AddType application/x-httpd-php-source .phps
#
# cp php.ini-production /usr/local/php/lib/php.ini
# vi /usr/local/php/lib/php.ini

zend_extension=/home/rf114/public_html/data/ioncube_loader_lin_5.6.so
zend_extension=/home/rf114/public_html/data/ixed.5.6.lin
short_open_tag = On     (Off -> On 변경)
-> php 태그 단순화 (<?php ?> -> <? ?>)
; http://php.net/expose-php
expose_php = On          (On -> Off 변경)

#
# vi /etc/ld.so.conf
/usr/local/mysql/lib       (OS가 32bit일 경우)
/usr/local/mysql/lib64    (OS가 64bit일 경우)
# /sbin/ldconfig
# /usr/local/apache/bin/httpd -t
# /usr/local/apache/bin/apachectl restart
-----------------------------------------------------------
