1. YUM 설치를 위한 저장소 추가
CentOS 7에서 기본적으로 제공하는 PHP버전은 5.X 버전이다.
최신버전인 PHP7을 설치하기 위해서 Webtatic EL 저장소를 추가한다.
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2. Apache 설치
# yum --enablerepo=epel,remi install httpd mod_ssl
# systemctl start httpd
# systemctl enable httpd
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
Apache 설정
# cp -av /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.original
# sed -i 's/AddDefaultCharset UTF-8/#AddDefaultCharset UTF-8/' /etc/httpd/conf/httpd.conf
# sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html Index.html Index.php index.php/' /etc/httpd/conf/httpd.conf
# sed -i 's/Options Indexes FollowSymLinks/Options FollowSymLinks/' /etc/httpd/conf/httpd.conf
# echo 'KeepAlive On
ServerTokens Prod
' >> /etc/httpd/conf/httpd.conf
# systemctl restart httpd
Apache SSL 설정 - 빨갛게 된 부분의 도메인은 SSL 인증서를 사용할 자신의 도메인을 입력하면 된다. crt 파일과 key파일을 발급은 SSL 발급업체에서..
# sed -i 's/#DocumentRoot "\/var\/www\/html"/DocumentRoot "\/home\/oerun\/public_html"/' /etc/httpd/conf.d/ssl.conf
# sed -i 's/#ServerName www.example.com:443/ServerName www.oerun.com:443/' /etc/httpd/conf.d/ssl.conf
# sed -i 's/SSLCertificateFile \/etc\/pki\/tls\/certs\/localhost.crt/SSLCertificateFile \/etc\/pki\/tls\/certs\/cert_www.oerun.com.crt/' /etc/httpd/conf.d/ssl.conf
# sed -i 's/SSLCertificateKeyFile \/etc\/pki\/tls\/certs\/localhost.key/SSLCertificateKeyFile \/etc\/pki\/tls\/certs\/prv_www.oerun.com.key/' /etc/httpd/conf.d/ssl.conf
# systemctl restart httpd
3. PHP 7 설치
먼저 PHP7 본 패키지를 설치한다.
# yum install php70w
기타 필요한 모듈을 설치한다. yum search php70w 명령으로 설치할 수 있는 모듈을 찾아볼 수 있다.
# yum install php70w-cli php70w-common php70w-dba php70w-devel php70w-fpm php70w-gd php70w-imap
# yum install php70w-ldap php70w-mbstring php70w-mcrypt php70w-mysqlnd php70w-odbc php70w-opcache
# yum install php70w-pdo php70w-pdo_dblib php70w-pear php70w-pecl-imagick php70w-pecl-imagick-devel
# yum install php70w-pgsql php70w-phpdbg php70w-process php70w-snmp php70w-soap php70w-tidy php70w-xml php70w-xmlrpc
PHP 설정
# cp -av /etc/php.ini /etc/php.ini.original
# sed -i 's/short_open_tag = Off/short_open_tag = On/' /etc/php.ini
# sed -i 's/expose_php = On/expose_php = Off/' /etc/php.ini
# sed -i 's/display_errors = Off/display_errors = On/' /etc/php.ini
# sed -i 's/;error_log = php_errors.log/error_log = php_errors.log/' /etc/php.ini
# sed -i 's/error_reporting = E_ALL \& ~E_DEPRECATED/error_reporting = E_ALL \& ~E_NOTICE \& ~E_DEPRECATED \& ~E_USER_DEPRECATED/' /etc/php.ini
# sed -i 's/variables_order = "GPCS"/variables_order = "EGPCS"/' /etc/php.ini
# sed -i 's/post_max_size = 8M/post_max_size = 100M/' /etc/php.ini
# sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/' /etc/php.ini
# sed -i 's/;date.timezone =/date.timezone = "Asia\/Seoul"/' /etc/php.ini
# sed -i 's/session.gc_maxlifetime = 1440/session.gc_maxlifetime = 86400/' /etc/php.ini
# systemctl restart httpd
# echo '<?
echo __FILE__;
phpinfo();
?>' >> /var/www/html/phpinfo.php
브라우저에서 http://서버IP/phpinfo.php 실행하면 php 정보가 출력된다.
4. MariaDB 설치
설치 전, 아래 주소에 접속하여 원하는 버전을 선택하여 저장소 파일을 만든다.
https://downloads.mariadb.org/mariadb/repositories/#mirror=kaist&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.1
# echo '# MariaDB 10.1 CentOS repository list - created 2016-10-13 00:14 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
' >> /etc/yum.repos.d/MariaDB.repo
# yum install MariaDB-server MariaDB-client
# systemctl restart mysql
# mysql_secure_installation
# systemctl restart mysql
# firewall-cmd --permanent --zone=public --add-service=mysql
# firewall-cmd --reload
# mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'DB암호' WITH GRANT OPTION;
# systemctl restart mysql
MariaDB 설정
# rpm -ql MariaDB-server.x86_64 | grep cnf
* 환경설정 파일이 어디 있는지 확인
# mv /etc/my.cnf /etc/my.cnf.original
# cp -f /usr/share/mysql/my-huge.cnf /etc/my.cnf
InnoDB로 사용하기
# cp -f /usr/share/mysql/my-innodb-heavy-4G.cnf /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\ntransaction-isolation = READ-COMMITTED/' /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\nlog-bin-trust-function-creators = 1/' /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\nlower_case_table_names = 1/' /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\nexpire_logs_days = 5/' /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\nwait_timeout = 90000/' /etc/my.cnf
# sed -i 's/max_allowed_packet = 16M/max_allowed_packet = 128M/' /etc/my.cnf
# sed -i 's/default-storage-engine = MYISAM/default-storage-engine = InnoDB/' /etc/my.cnf
# sed -i 's/transaction_isolation = REPEATABLE-READ/transaction_isolation = READ-COMMITTED/' /etc/my.cnf
# sed -i 's/log-bin=mysql-bin/#log-bin=mysql-bin/' /etc/my.cnf
# sed -i 's/long_query_time = 2/long_query_time = 3/' /etc/my.cnf
# sed -i 's/innodb_buffer_pool_size = 2G/innodb_buffer_pool_size = 24G/' /etc/my.cnf
# sed -i 's/innodb_data_file_path = ibdata1:10M:autoextend/innodb_data_file_path = ibdata1:2000M;ibdata2:2000M;ibdata3:2000M:autoextend/' /etc/my.cnf
# sed -i 's/innodb_flush_log_at_trx_commit = 1/innodb_flush_log_at_trx_commit = 0/' /etc/my.cnf
# sed -i 's/innodb_log_file_size = 256M/innodb_log_file_size = 4G/' /etc/my.cnf
MariaDB를 EUC-KR로 사용하기
# sed -i 's/\[client\]/\[client\]\ndefault-character-set = euckr/' /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\ncharacter-set-client-handshake = FALSE\ninit_connect = \"SET collation_connection = euckr_korean_ci\"\ninit_connect = \"SET NAMES euckr\"\ncharacter-set-server = euckr\ncollation-server = euckr_korean_ci/' /etc/my.cnf
# sed -i 's/\[mysqldump\]/\[mysqldump\]\ndefault-character-set = euckr/' /etc/my.cnf
# sed -i 's/\[mysql\]/\[mysql\]\ndefault-character-set = euckr/' /etc/my.cnf
# systemctl restart mysql
MariaDB를 UTF-8로 사용하기
# sed -i 's/\[client\]/\[client\]\ndefault-character-set = utf8/' /etc/my.cnf
# sed -i 's/\[mysqld\]/\[mysqld\]\ncharacter-set-client-handshake = FALSE\ninit_connect = \"SET collation_connection = utf8_general_ci\"\ninit_connect = \"SET NAMES utf8\"\ncharacter-set-server = utf8\ncollation-server = utf8_general_ci/' /etc/my.cnf
# sed -i 's/\[mysqldump\]/\[mysqldump\]\ndefault-character-set = utf8/' /etc/my.cnf
# sed -i 's/\[mysql\]/\[mysql\]\ndefault-character-set = utf8/' /etc/my.cnf
# systemctl restart mysql
DB 경로 수정하기 - 최근 버전부터는 오류가 발생함 ㅜ.ㅜ
# mkdir /home/mysql
# chown mysql.mysql mysql
# chown -R mysql:mysql /home/mysql
# service mysql stop
# cp -rap /var/lib/mysql/* /home/mysql/
설정파일의 데이터 경로 수정(#vi /etc/my.cnf)
# sed -i 's/\[mysqld\]/\[mysqld\]\ndatadir = \/home\/mysql/' /etc/my.cnf
# sed -i 's/#innodb_data_home_dir = <directory>/innodb_data_home_dir = \/home\/mysql/' /etc/my.cnf
# sed -i 's/#innodb_log_group_home_dir/innodb_log_group_home_dir = \/home\/mysql/' /etc/my.cnf
# service mysql start
5. 설치된 버전 확인
# php -v
PHP 7.0.6 (cli) (built: May 1 2016 10:24:20) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
# mysql -V
mysql Ver 15.1 Distrib 10.1.14-MariaDB, for Linux (x86_64) using readline 5.1
● phpMyAdmin 4.6.1 설치
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum --enablerepo=remi,remi-test install -y phpMyAdmin
# cp -a /etc/httpd/conf.d/phpMyAdmin.conf /etc/httpd/conf.d/phpMyAdmin.conf.original
# sed -i 's/Alias \/phpMyAdmin/Alias \/phpMyAdmin_oerun/' /etc/httpd/conf.d/phpMyAdmin.conf
# sed -i 's/Alias \/phpmyadmin/Alias \/phpmyadmin_oerun/' /etc/httpd/conf.d/phpMyAdmin.conf
# sed -i '15,17s/Require local/Require all granted/' /etc/httpd/conf.d/phpMyAdmin.conf
# systemctl restart httpd
* 접속 URL : http://서버IP/phpmyadmin_oerun