서버 설치 · 5 min read · Jan 26, 2026
페도라 19에 PHP5 (및 PHP-FPM) 및 MySQL 지원으로 Nginx 설치하기
Nginx (“engine x”로 발음됨)는 무료, 오픈 소스, 고성능 HTTP 서버입니다. Nginx는 안정성, 풍부한 기능 세트, 간단한 구성 및 낮은 리소스 소비로 잘 알려져 있습니다. 이 튜토리얼에서는 PHP5 지원( PHP-FPM을 통해) 및 MySQL 지원과 함께 페도라 19 서버에 Nginx를 설치하는 방법을 보여줍니다.
이것이 당신에게 작동할 것이라는 보장은 하지 않습니다!
1 사전 참고
이 튜토리얼에서는 호스트 이름 server1.example.com과 IP 주소 192.168.0.100을 사용합니다. 이러한 설정은 귀하의 경우 다를 수 있으므로 적절한 곳에서 교체해야 합니다.
2 MySQL/MariaDB 5 설치하기
먼저 다음과 같이 MySQL 5를 설치합니다:
yum install mysql mysql-server그런 다음 MySQL의 시스템 시작 링크를 생성하여 시스템 부팅 시 MySQL이 자동으로 시작되도록 하고 MySQL 서버를 시작합니다:
systemctl enable mysqld.service
systemctl start mysqld.service이제 네트워킹이 활성화되었는지 확인합니다. 다음을 실행합니다:
netstat -tap | grep mysql다음과 같은 결과가 표시되어야 합니다:
[root@server1 ~]# netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 1116/mysqld
[root@server1 ~]#만약 그렇지 않다면 /etc/my.cnf를 편집하고 skip-networking 옵션을 주석 처리합니다:
vi /etc/my.cnf[...]
#skip-networking
[...]그런 다음 MySQL 서버를 재시작합니다:
systemctl restart mysqld.service다음 명령을 실행하여
mysql_secure_installationroot 사용자에 대한 비밀번호를 설정합니다(그렇지 않으면 누구나 MySQL 데이터베이스에 접근할 수 있습니다!):
[root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
MariaDB에 로그인하여 보안을 설정하려면 현재
root 사용자에 대한 비밀번호가 필요합니다.
MariaDB를 방금 설치했으며,
아직 root 비밀번호를 설정하지 않았다면,
비밀번호는 비어 있으므로,
여기서 그냥 Enter를 누르십시오.
Enter current password for root (enter for none): <– ENTER
OK, successfully used password, moving on…
root 비밀번호를 설정하면
누구도 적절한 권한 없이 MariaDB root 사용자로 로그인할 수 없습니다.
Set root password? [Y/n] <– ENTER
New password: <– yourrootsqlpassword
Re-enter new password: <– yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
… Success!
기본적으로 MariaDB 설치에는
익명 사용자가 있어,
누구나 사용자 계정을 만들지 않고도
MariaDB에 로그인할 수 있습니다.
이는 테스트 용도로만 의도되었으며,
설치를 좀 더 원활하게 하기 위한 것입니다.
생산 환경으로 이동하기 전에
그들을 제거해야 합니다.
Remove anonymous users? [Y/n] <– ENTER
… Success!
보통 root는
‘localhost’에서만 연결할 수 있어야 합니다.
이는 누군가가 네트워크에서
root 비밀번호를 추측할 수 없도록 보장합니다.
Disallow root login remotely? [Y/n] <– ENTER
… Success!
기본적으로 MariaDB에는
누구나 접근할 수 있는
‘test’라는 데이터베이스가 있습니다.
이는 또한 테스트 용도로만 의도되었으며,
생산 환경으로 이동하기 전에
제거해야 합니다.
Remove test database and access to it? [Y/n] <– ENTER
- Dropping test database…
… Success! - Removing privileges on test database…
… Success!
권한 테이블을 다시 로드하면
지금까지 변경된 모든 사항이
즉시 적용됩니다.
Reload privilege tables now? [Y/n] <– ENTER
… Success!
정리 중…
모든 작업이 완료되었습니다!
위의 모든 단계를 완료했다면,
당신의 MariaDB 설치는 이제
안전해야 합니다.
MariaDB를 사용해 주셔서 감사합니다!
[root@server1 ~]#
3 Nginx 설치하기
Nginx는 페도라 19의 패키지로 제공되며, 다음과 같이 설치할 수 있습니다:
yum install nginx그런 다음 nginx의 시스템 시작 링크를 생성하고 시작합니다:
systemctl enable nginx.service
systemctl start nginx.service웹 서버의 IP 주소 또는 호스트 이름을 브라우저에 입력합니다(예: http://192.168.0.100), 그러면 nginx 환영 페이지가 표시되어야 합니다:

4 PHP5 설치하기
PHP5를 nginx에서 PHP-FPM을 통해 작동하게 할 수 있습니다(PHP-FPM(FastCGI Process Manager)은 모든 크기의 사이트, 특히 바쁜 사이트에 유용한 몇 가지 추가 기능이 있는 대체 PHP FastCGI 구현입니다). 공식 페도라 19 저장소에 php-fpm 패키지가 있으므로, php-cli 및 MySQL을 PHP 스크립트에서 사용하려면 필요한 php-mysqlnd와 같은 몇 가지 PHP5 모듈과 함께 php-fpm을 설치할 수 있습니다:
yum install php-fpm php-cli php-mysqlnd php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidyZend OPcache는 PHP 중간 코드를 캐싱하고 최적화하기 위한 무료 및 오픈 PHP opcode 캐셔입니다. 이는 APC 및 Xcache와 같은 다른 PHP opcode 캐셔와 유사합니다. PHP 페이지 속도를 높이기 위해 이러한 것 중 하나를 설치하는 것이 강력히 권장됩니다. Zend OPcache는 이제 PHP 5.5에 공식적으로 포함되어 있으므로, 다른 opcode 캐셔 대신 이를 사용합니다.
Zend OPcache는 다음과 같이 설치할 수 있습니다:
yum install php-opcache다음과 같은 오류를 피하기 위해:
[13-Nov-2011 22:13:16] PHP Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /usr/share/nginx/html/info.php on line 2… /var/log/php-fpm/www-error.log에서 PHP 스크립트를 브라우저에서 호출할 때, /etc/php.ini를 열고 date.timezone을 설정해야 합니다:
vi /etc/php.ini[...]
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Berlin"
[...]다음으로 php-fpm의 시스템 시작 링크를 생성하고 시작합니다:
systemctl enable php-fpm.service
systemctl start php-fpm.servicePHP-FPM은 포트 9000에서 FastCGI 서버를 실행하는 데몬 프로세스입니다.
5 Nginx 구성하기
nginx 구성은 /etc/nginx/nginx.conf에 있으며, 지금 열어보겠습니다:
vi /etc/nginx/nginx.conf구성은 이해하기 쉽습니다(여기에서 더 많은 것을 배울 수 있습니다: http://wiki.codemongers.com/NginxFullExample 및 http://wiki.codemongers.com/NginxFullExample2)
먼저(선택 사항) 작업 프로세스 수를 늘리고 keepalive_timeout을 합리적인 값으로 설정할 수 있습니다:
[...]
worker_processes 4;
[...]
keepalive_timeout 2;
[...]가상 호스트는 server {} 컨테이너에서 정의됩니다. 기본 vhost는 /etc/nginx/nginx.conf 파일의 아래쪽에 정의되어 있습니다 - 이를 다음과 같이 수정해 보겠습니다:
vi /etc/nginx/nginx.conf[...]
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
[...]servername ;는 이를 기본 catchall vhost로 만듭니다(물론 여기에서 www.example.com과 같은 호스트 이름을 지정할 수도 있습니다).
location / 부분에서 index.php를 index 줄에 추가했습니다. root /usr/share/nginx/html;는 문서 루트가 /usr/share/nginx/html 디렉토리임을 의미합니다.
PHP에 중요한 부분은 location ~ .php$ {} 구문입니다. 이를 활성화하려면 주석을 제거하십시오. root 줄을 웹 사이트의 문서 루트로 변경하십시오(예: root /usr/share/nginx/html;). fastcgi_param 줄을 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;로 변경해야 합니다. 그렇지 않으면 PHP 인터프리터가 브라우저에서 호출하는 PHP 스크립트를 찾지 못합니다.
또한, 제로 데이 익스플로잇을 방지하기 위해 try_files $uri =404; 줄을 추가했습니다(자세한 내용은 http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHP 및 http://forum.nginx.org/read.php?2,88845,page=3 참조). 대안으로, try_files $uri =404; 줄을 사용하고 싶지 않다면, /etc/php5/fpm/php.ini에서 cgi.fix_pathinfo = 0;를 설정할 수 있습니다(그런 다음 PHP-FPM을 다시 로드하는 것을 잊지 마십시오).
이제 파일을 저장하고 nginx를 다시 로드합니다:
systemctl reload nginx.service이제 문서 루트 /usr/share/nginx/html에 다음 PHP 파일을 생성합니다…
vi /usr/share/nginx/html/info.php이제 브라우저에서 해당 파일을 호출합니다(예: http://192.168.0.100/info.php):

보시다시피, PHP5가 작동하고 있으며, 서버 API 줄에 표시된 대로 FPM/FastCGI를 통해 작동하고 있습니다. 아래로 스크롤하면 MySQL 모듈을 포함하여 PHP5에서 이미 활성화된 모든 모듈을 볼 수 있습니다:

6 링크
- nginx: http://nginx.org/
- nginx 위키: http://wiki.nginx.org/
- PHP: http://www.php.net/
- PHP-FPM: http://php-fpm.org/
- MySQL: http://www.mysql.com/
- 페도라: http://fedoraproject.org/
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.