Warning: require_once(): open_basedir restriction in effect. File(/var/www/config.php) is not within the allowed path(s): (/var/www/html) in /var/www/html/loginView.php on line 11 Warning: require_once(/var/www/config.php): failed to open stream: Operation not permitted in /var/www/html/loginView.php on line 11 Fatal error: require_once(): Failed opening required '.././config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/loginView.php on line 11
3Tier 구조에서 PHP-FPM 설치 옵션을 제거하면 3Tier 로 동작되는지 여부를 확인하기 위해서 해봤다.
# yum 외부 저장소 추가 (이 과정은 생략해도 된다) cd /etc/yum.repos.d/ vi nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
:wq 저장하고 나온다.
#Step 3. Nginx 설치 yum -y install nginx
# Apache를 설치한 경우에는 아파치 동작 중지 systemctl stop httpd
#Step 4. Nginx 데몬 실행 systemctl start nginx systemctl enable nginx systemctl status nginx
# 기존에 설치된 php가 있다면 제거 (필요하면 사용하라) yum remove -y 'yum list installed | cut -d " " -f 1 | grep php'
### PHP 설치 #### #Step 5. Repository 설치 yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
#Step 6. yum Utilities Package 설치 yum -y install yum-utils
#Step 7. – Install PHP and PHP-FPM # Disable repo for PHP 5.4 yum-config-manager --disable remi-php54 yum-config-manager --enable remi-php73
# Step 10 : Configure PHP-FPM vi /etc/php.ini cgi.fix_pathinfo=0 short_open_tag = On post_max_size = 30M ;// 8M 으로 되어 있었음. upload_max_filesize = 30M ;// 기본 2M 으로 되어 있었음
date.timezone ="Asia/Seoul" expose_php=Off
;PHP에서 세션은 일단 생성 된 뒤에, 가비지 콜렉터 관리로직에 의해 소멸된다. session.gc_divisor = 1 ;이값이 100이면 1/100 즉 1%의 확률로 가비지콜렉션이 실행된다. ;1이면 정확하게 유효기간이 넘은 데이타가 삭제될 것이다.
# 저장하고 나온다.
#Step 11. 서비스 재시작 systemctl restart php-fpm systemctl restart nginx
Redirecting vhost in /etc/httpd/conf.d/default.conf to ssl vhost in /etc/httpd/conf.d/default-le-ssl.conf
자동으로 default.conf 에 설정한 VirtualHost 정보를 읽어서 default-le-ssl.conf 에 추가를 해주더라.
# 저장소 추가 yum -y install epel-release
yum -y install certbot
# 설치 : 웹서버가 Apache 인 경우 yum -y install python2-certbot-apache mod_ssl
# 설치하면 cd /etc/letsencrypt cd /etc/httpd/conf.d/ default-le-ssl.conf 파일이 자동 생성된다.
cd /var/log/letsencrypt 에 로그가 쌓인다.
인증서 발급 # 자동으로 Redirecting vhost in /etc/httpd/conf.d/default.conf to ssl vhost in /etc/httpd/conf.d/default-le-ssl.conf # VirtualHost 정보를 읽어서 설정을 해주더라.
# vi /etc/httpd/conf.d/default.conf 에 먼저 Virtual Host를 추가 등록해줘야 한다.
# 추가하면 자동으로 /etc/httpd/conf.d/default-le-ssl.conf 에 자동으로 추가된다.
vi /etc/httpd/conf/httpd.conf
ServerName localhost
# 불필요한 Methods 차단 설정 : method 허용은 GET, POST 만 허용
# Directory 태그를 사용하면 Directory 별로 모두 제한을 걸어줘야 하므로
# URL pattern 을 이용하여 일괄적으로 제한하는 방법
<Location />
<LimitExcept GET POST>
Order deny,allow
Deny from all
</LimitExcept>
</Location>
<Directory "/var/www/html">
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
<LimitExcept GET POST>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
# 서버 정보 노출 방지
ServerTokens Prod
ServerSignature Off
# Trace Method 처리
TraceEnable off
ErrorDocument 400 /error.html
ErrorDocument 401 /error.html
ErrorDocument 402 /error.html
ErrorDocument 403 /error.html
ErrorDocument 404 /error.html
ErrorDocument 405 /error.html
ErrorDocument 408 /error.html
ErrorDocument 500 /error.html
ErrorDocument 501 /error.html
ErrorDocument 502 /error.html
ErrorDocument 503 /error.html
저장하고 나온다.
# Apache HTTPOXY 취약점 방지
echo "RequestHeader unset Proxy early" >> /etc/httpd/conf/httpd.conf
# Step 5 : Configure PHP-FPM
vi /etc/php.ini
cgi.fix_pathinfo=0
short_open_tag = On
post_max_size = 60M ;// 8M 으로 되어 있었음.
upload_max_filesize = 50M ;// 기본 2M 으로 되어 있었음
;PHP 버전정보 노출 방지
expose_php=Off
date.timezone ="Asia/Seoul"
;PHP에서 세션은 일단 생성 된 뒤에, 가비지 콜렉터 관리로직에 의해 소멸된다.
session.gc_probability = 1
session.gc_divisor = 1
;이값이 100이면 1/100 즉 1%의 확률로 가비지콜렉션이 실행된다.
;1이면 정확하게 유효기간이 넘은 데이타가 삭제될 것이다.
session.gc_maxlifetime = 3600
;세션과 쿠키를 동시에 사용
session.use_cookies = 1
;PHP 시작과 동시에 세션 사용(1), 사용하지 않음(0)
session.auto_start = 0
# 저장하고 나온다.
# 반드시 추가구현해야 문제없이 동작한다.
cd /var/www/html/
vi .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} !^(POST|GET)\ /.*\ HTTP/1\.1$
RewriteRule .* - [R=405,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ error.html?/$1 [QSA,PT,L]
</IfModule>
#Step 13 – Apache SSL 설정 파일(ssl.conf) 수정 vi /etc/httpd/conf.d/ssl.conf # shift + g 눌러서 파일의 맨 아래로 이동한다. # 설정파일의 맨 끝 </VirtualHost> 앞에 아래 내용 추가 SuexecUserGroup apache apache
#Step 15 – httpd.conf 파일 수정 vi /etc/httpd/conf/httpd.conf ServerName localhost <IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
<Directory "/var/www/html"> Options +FollowSymLinks -Indexes AllowOverride All Require all granted <LimitExcept GET POST> Order deny,allow Deny from all </LimitExcept> </Directory>
# Step 17 – Configure PHP-FPM vi /etc/php.ini cgi.fix_pathinfo=0 short_open_tag = On post_max_size = 60M ; // 8M 으로 되어 있었음. memory_limit = 128M upload_max_filesize = 50M ; // 기본 2M 으로 되어 있었음 allow_url_fopen = On ;PHP Excel Libray 설치가 안되는 현상이 있어서 On으로 변경함. date.timezone ="Asia/Seoul"
;PHP 버전정보 노출 방지 expose_php=Off
;PHP에서 세션은 일단 생성 된 뒤에, 가비지 콜렉터 관리로직에 의해 소멸된다. session.gc_probability = 1 session.gc_divisor = 1 ;이값이 100이면 1/100 즉 1%의 확률로 가비지콜렉션이 실행된다. ;1이면 정확하게 유효기간이 넘은 데이타가 삭제될 것이다. session.gc_maxlifetime = 3600
CentOS 7 에서 Apache 와 PHP 7.3 yum 설치하고 MariaDB 10.3 을 yum 설치하는 스크립트를 적어둔다.
################################ ##### MariaDB 10.3 버전 설치 ##### ################################
vi /etc/yum.repos.d/MariaDB.repo # MariaDB 10.3 CentOS repository list - created 2019-01-13 00:47 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
yum -y install MariaDB-server MariaDB-client
# mariadb 부팅 시 자동 시작 설정 systemctl enable mariadb
# mariadb 시작 (둘 중 하나 실행) systemctl start mariadb service mariadb start
# mariadb 상태 확인 service mariadb status
# Maria DB 보안 설정하기 mysql_secure_installation 비밀번호 설정
vi /etc/my.cnf.d/server.cnf [mysqld] character-set-server = utf8 collation-server = utf8_general_ci
service mariadb restart mysql -u root -p status quit
############################ ### root 패스워드 분실 복구 #### ############################ # 서비스 정지 systemctl stop mariadb
# mariadb 안전모드 실행 sudo /usr/bin/mysqld_safe --skip-grant &
# 패스워드 변경 mysql -uroot mysql update user set password=password('변경할비밀번호') where user='root'; flush privileges; exit;
# 접속 테스트 mysql -uroot -p 비밀번호 입력
# 서비스 재시작 systemctl restart mariadb
############################################# ######### CentOS 7 버전 확인 ################## ############################################# cat /etc/redhat-release
## 현재 설치된 PHP 버전 확인 yum list php
yum install expat-devel
## 설치확인 yum list installed | grep httpd yum list installed | grep php yum list installed | grep MariaDB
# 설치 확인 rpm -qa | grep httpd rpm -qa | grep php rpm -qa | grep MariaDB
## 설치된 것 한꺼번에 지우기 rpm -qa | grep php >list
# vi list로 해서 삭제 안할 리스트는 선별 제거한다. sudo yum -y remove $(awk '{print $1}' <list)
systemctl stop httpd systemctl restart httpd systemctl status httpd
# openssl 버전 확인 openssl version
## httpd.conf 파일 수정 vi /etc/httpd/conf/httpd.conf ServerName localhost User nobody Group nobody <IfModule dir_module> DirectoryIndex index.html index.php index.jsp </IfModule>
<Directory "/var/www/html"> Options IncludesNoExec AllowOverride None Require all granted </Directory>
vi /etc/php.ini short_open_tag = On post_max_size = 60M ;// 8M 으로 되어 있었음. memory_limit = 128M upload_max_filesize = 50M ;// 기본 2M 으로 되어 있었음
포트를 9000 번으로 변경해서 테스트를 해보고 싶은데 PHP-FPM 설정 방법을 완벽하게 이해하지 못했다.
설정을 제대로 이해하고 한 것인지는 모르겠는데 동작은 이상없이 잘 된다는 건 확인했다.
##################################### ### [Apache] Reverse Proxy 설정 ### #####################################
# 설치 확인 rpm -qa | grep httpd
## 설치된 것 한꺼번에 지우기 rpm -qa | grep httpd >list
# vi list로 해서 삭제 안할 리스트는 선별 제거한다. sudo yum -y remove $(awk '{print $1}' <list)
#Step 1 – Install Apache2 yum -y install httpd
#Step 2 httpd.conf 파일 수정 vi /etc/httpd/conf/httpd.conf ServerName localhost User nobody Group nobody <IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
<Directory "/var/www/html"> Options IncludesNoExec AllowOverride None Order deny,allow Allow from all </Directory>
#Step 3 Virtual Host 설정
# Reverse Proxy : 외부에서 접속했을 때 내부서버나 다른 곳으로 연결해 주는 방법 vi /etc/httpd/conf.d/default-site.conf <VirtualHost *:80> ProxyPreserveHost On