서버 설치 · 6 min read · Dec 06, 2025

CentOS 7.4에 Apache, PHP 7.2 및 MySQL 설치하는 방법 (LAMP)

이 튜토리얼은 CentOS 7 서버에 PHP (mod_php) 및 MySQL 데이터베이스와 함께 Apache 웹 서버를 설치하는 방법을 보여줍니다. LAMP라는 약어는 Linux, Apache, MySQL, PHP의 약자입니다.

이 업데이트된 튜토리얼은 CentOS 7.4에 최신 PHP 버전(7.0, 7.1 및 7.2)을 설치하는 방법을 보여줍니다.

1 사전 참고

이 튜토리얼에서는 호스트 이름 server1.example.com과 IP p 192.168.1.100을 사용합니다. 이러한 설정은 귀하의 경우 다를 수 있으므로 적절한 곳에서 교체해야 합니다.

최신 phpMyAdmin을 설치하기 위해 EPEL 저장소를 추가하겠습니다:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*  
yum -y install epel-release

쉘에서 파일을 편집하기 위해 nano 편집기를 설치하겠습니다. 파일 편집을 위해 vi를 선호하신다면 이 단계를 건너뛰세요.

yum -y install nano

2 MySQL / MariaDB 설치

MariaDB는 원래 MySQL 개발자인 Monty Widenius의 MySQL 포크입니다. MariaDB는 MySQL과 호환되며, 여기서는 MySQL 대신 MariaDB를 사용하기로 선택했습니다. yum을 사용하여 MariaDB를 설치하려면 다음 명령을 실행하세요:

yum -y install mariadb-server mariadb

그런 다음 MySQL의 시스템 시작 링크를 생성하여 시스템 부팅 시 MySQL이 자동으로 시작되도록 하고 MySQL 서버를 시작합니다:

systemctl start mariadb.service  
systemctl enable mariadb.service

MySQL 루트 계정의 비밀번호를 설정합니다:

mysql_secure_installation
[root@server1 ~]# mysql_secure_installation  
  
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB  
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!  
  
In order to log into MariaDB to secure it, we'll need the current  
password for the root user.  If you've just installed MariaDB, and  
you haven't set the root password yet, the password will be blank,  
so you should just press enter here.  
  
Enter current password for root (enter for none): <--ENTER  
OK, successfully used password, moving on...  
  
Setting the root password ensures that nobody can log into the MariaDB  
root user without the proper authorisation.  
  
Set root password? [Y/n]   
New password: <--yourmariadbpassword  
Re-enter new password: <--yourmariadbpassword  
Password updated successfully!  
Reloading privilege tables..  
 ... Success!  
  
By default, a MariaDB installation has an anonymous user, allowing anyone  
to log into MariaDB without having to have a user account created for  
them.  This is intended only for testing, and to make the installation  
go a bit smoother.  You should remove them before moving into a  
production environment.  
  
Remove anonymous users? [Y/n] <--ENTER  
 ... Success!  
  
Normally, root should only be allowed to connect from 'localhost'.  This  
ensures that someone cannot guess at the root password from the network.  
  
Disallow root login remotely? [Y/n] <--ENTER  
 ... Success!  
  
By default, MariaDB comes with a database named 'test' that anyone can  
access.  This is also intended only for testing, and should be removed  
before moving into a production environment.  
  
Remove test database and access to it? [Y/n] <--ENTER  
 - Dropping test database...  
 ... Success!  
 - Removing privileges on test database...  
 ... Success!  
  
Reloading the privilege tables will ensure that all changes made so far  
will take effect immediately.  
  
Reload privilege tables now? [Y/n] <--ENTER  
 ... Success!  
  
Cleaning up...  
  
All done!  If you've completed all of the above steps, your MariaDB  
installation should now be secure.  
  
Thanks for using MariaDB!  
[root@server1 ~]#

3 Apache 설치

CentOS 7은 Apache 2.4와 함께 제공됩니다. Apache는 CentOS 7 패키지로 직접 제공되므로 다음과 같이 설치할 수 있습니다:

yum -y install httpd

설치 과정의 스크린샷입니다.

CentOS에 Apache http 서버 설치

이제 시스템을 구성하여 부팅 시 Apache가 시작되도록 합니다…

systemctl start httpd.service
systemctl enable httpd.service

외부에서 웹 서버에 접근할 수 있도록 HTTP (80) 및 HTTPS (443) 포트를 방화벽에서 열어야 합니다. CentOS의 기본 방화벽은 firewalld이며, firewalld-cmd 명령으로 구성할 수 있습니다.

firewall-cmd --permanent --zone=public --add-service=http   
firewall-cmd --permanent --zone=public --add-service=https  
firewall-cmd --reload

이제 브라우저를 서버의 IP 주소로 이동하면, 제 경우 http://192.168.1.100에서 Apache 자리 표시자 페이지를 볼 수 있습니다:

CentOS 7에서 시작된 Apache 웹 서버

4 PHP 설치

CentOS에 기본으로 제공되는 PHP 버전은 꽤 오래되었습니다 (PHP 5.4). 따라서 이 장에서는 Remi 저장소에서 PHP 7.0 또는 7.1과 같은 최신 PHP 버전을 설치하는 몇 가지 옵션을 보여드리겠습니다.

Remi CentOS 저장소를 추가합니다.

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum-config-manager 유틸리티가 필요하므로 yum-utils를 설치합니다.

yum -y install yum-utils

그리고 yum 업데이트를 실행합니다.

yum update

이제 서버에서 사용할 PHP 버전을 선택해야 합니다. PHP 5.4를 사용하려면 4.1 장으로 진행하세요. PHP 7.0을 설치하려면 4.2 장의 명령을 따르고, PHP 7.1은 4.3 장, PHP 7.2는 4.4 장을 사용하세요. 4.x 장 중 하나만 따르세요. Apache mod_php와 함께 한 번에 하나의 PHP 버전만 사용할 수 있습니다.

4.1 PHP 5.4 설치

PHP 5.4를 설치하려면 다음 명령을 실행하세요:

yum -y install php

4.2 PHP 7.0 설치

다음과 같이 PHP 7.0 및 Apache PHP 7.0 모듈을 설치할 수 있습니다:

yum-config-manager --enable remi-php70
yum -y install php php-opcache

4.3 PHP 7.1 설치

대신 PHP 7.1을 사용하려면 다음을 사용하세요:

yum-config-manager --enable remi-php71
yum -y install php php-opcache

4.4 PHP 7.2 설치

대신 PHP 7.2를 사용하려면 다음을 사용하세요:

yum-config-manager --enable remi-php72
yum -y install php php-opcache

이 예제와 다운로드 가능한 가상 머신에서는 PHP 7.2를 사용할 것입니다.

변경 사항을 적용하려면 Apache를 다시 시작해야 합니다:

systemctl restart httpd.service

5 PHP 테스트 / PHP 설치에 대한 세부정보 얻기

기본 웹사이트의 문서 루트는 /var/www/html입니다. 해당 디렉토리에 작은 PHP 파일(info.php)을 만들고 브라우저에서 호출하여 PHP 설치를 테스트합니다. 이 파일은 설치된 PHP 버전과 같은 PHP 설치에 대한 유용한 세부정보를 표시합니다.

nano /var/www/html/info.php

이제 브라우저에서 해당 파일을 호출합니다 (예: http://192.168.1.100/info.php):

CentOS 7에 설치된 PHP 7.2

보시다시피, PHP 7.2가 작동하고 있으며, 서버 API 줄에 표시된 대로 Apache 2.0 핸들러를 통해 작동하고 있습니다. 아래로 스크롤하면 PHP에서 이미 활성화된 모든 모듈을 볼 수 있습니다. MySQL은 거기에 나열되어 있지 않으므로 PHP에서 MySQL 지원이 아직 없습니다.

6 PHP에서 MySQL 지원 얻기

PHP에서 MySQL 지원을 얻으려면 php-mysqlnd 패키지를 설치할 수 있습니다. 애플리케이션에 필요할 수 있는 다른 PHP 모듈도 설치하는 것이 좋습니다. 다음과 같이 사용 가능한 PHP5 모듈을 검색할 수 있습니다:

yum search php

필요한 모듈을 선택하고 다음과 같이 설치합니다:

yum -y install php-mysqlnd php-pdo

다음 단계에서는 Wordpress, Joomla 및 Drupal과 같은 CMS 시스템에서 필요한 몇 가지 일반적인 PHP 모듈을 설치하겠습니다:

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel

이제 Apache 웹 서버를 다시 시작합니다:

systemctl restart httpd.service

이제 브라우저에서 http://192.168.1.100/info.php를 다시 로드하고 모듈 섹션으로 다시 스크롤합니다. 이제 curl 등과 같은 많은 새로운 모듈을 찾을 수 있어야 합니다:

CentOS에서 PHP 7.2에 추가된 MySQL 지원

더 이상 PHP 정보 출력을 필요로 하지 않으면 보안상의 이유로 해당 파일을 삭제하세요.

rm /var/www/html/info.php

7 phpMyAdmin 설치

phpMyAdmin은 MySQL 데이터베이스를 관리할 수 있는 웹 인터페이스입니다.
phpMyAdmin은 이제 다음과 같이 설치할 수 있습니다:

yum -y install phpMyAdmin

이제 phpMyAdmin을 구성합니다. Apache 구성을 변경하여 phpMyAdmin이 localhost에서만 연결을 허용하지 않도록 합니다 ( 구문을 주석 처리하고 ‘Require all granted’ 줄을 추가합니다):

nano /etc/httpd/conf.d/phpMyAdmin.conf
[...]  
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

  
 AddDefaultCharset UTF-8  
  
   
 # Apache 2.4  
#   
# Require ip 127.0.0.1  
# Require ip ::1  
#   
 Require all granted  
   
   
 # Apache 2.2  
 Order Deny,Allow  
 Deny from All  
 Allow from 127.0.0.1  
 Allow from ::1  
   
  
  
  
        Options none
        AllowOverride Limit
        Require all granted
  
  
[...] 

다음으로 phpMyAdmin의 인증을 쿠키에서 http로 변경합니다:

nano /etc/phpMyAdmin/config.inc.php
[...]  
$cfg['Servers'][$i]['auth_type']     = 'http';    // 인증 방법 (config, http 또는 cookie 기반)?  
[...]  

Apache를 다시 시작합니다:

systemctl restart  httpd.service

그 후, http://192.168.1.100/phpmyadmin/에서 phpMyAdmin에 접근할 수 있습니다:

CentOS 7.4에 설치된 PHPMyAdmin

8 가상 머신으로 다운로드

이 설정은 howtoforge 구독자를 위해 ova/ovf 형식의 가상 머신 다운로드로 제공됩니다 (VMWare 및 Virtualbox와 호환됨).

VM의 로그인 세부정보

  • Linux 루트 비밀번호는: howtoforge입니다.
  • MySQL 루트 비밀번호는: howtoforge입니다.

첫 로그인 시 두 비밀번호를 모두 변경하세요.

  • VM의 IP 주소는 192.168.1.100입니다.

9 링크

Apache: http://httpd.apache.org/
PHP: http://www.php.net/
MySQL: http://www.mysql.com/
CentOS: http://www.centos.org/
phpMyAdmin: http://www.phpmyadmin.net/

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.