서버 튜토리얼 · 5 min read · Feb 02, 2026

Debian 9 LAMP 서버 튜토리얼: Apache, PHP 7 및 MariaDB

LAMP는 Linux, Apache, MySQL, PHP의 약자입니다. 이 튜토리얼에서는 PHP 7 (mod_php) 및 MariaDB 지원과 함께 Debian Stretch (9) 서버에 Apache 웹 서버를 설치하는 방법을 보여줍니다. MariaDB는 잘 알려진 MySQL 데이터베이스 서버의 포크로, MySQL과 호환되는 기능 세트를 제공하며, 제가 인터넷에서 찾은 벤치마크에 따르면 약간 더 빠릅니다. MariaDB는 Wordpress, Joomla 등과 같은 MySQL을 요구하는 모든 애플리케이션과 함께 작동합니다.

LAMP 설정은 Joomla, Wordpress 또는 Drupal과 같은 CMS 시스템의 완벽한 기반입니다.

1 사전 참고

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

2 MySQL 대체로서의 MariaDB 설치

먼저, 다음과 같이 MariaDB를 설치합니다:

apt-get -y install mariadb-server mariadb-client

다음으로, mysql_secure_installation 명령어로 MariaDB를 보안합니다. 아래 명령어를 실행하고 마법사를 따르세요.

mysql_secure_installation

권장 입력 사항은 빨간색으로 표시됩니다.

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): <-- Hit return  
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] <-- y  
New password: <-- Enter the new password for the MariaDB root user  
Re-enter new password: <-- Enter the password again  
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] <-- y  
... 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] <-- y  
... 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] <-- y  
- 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] <-- y  
... 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!

이제 MariaDB 설정이 보안되었습니다.

3 Apache 웹 서버 설치

Apache는 Debian 패키지로 제공되므로 다음과 같이 설치할 수 있습니다:

apt-get -y install apache2

이제 브라우저를 http://192.168.1.100으로 이동하면 Apache2 자리 표시자 페이지(작동 중!)를 볼 수 있습니다:

Debian 9 Apache 기본 페이지

Apache의 기본 문서 루트는 Debian에서 /var/www이며, 구성 파일은 /etc/apache2/apache2.conf입니다. 추가 구성은 /etc/apache2 디렉토리의 하위 디렉토리인 /etc/apache2/mods-enabled (Apache 모듈용), /etc/apache2/sites-enabled (가상 호스트용), /etc/apache2/conf-enabled에 저장됩니다.

4 PHP 7.1 설치

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

apt-get -y install php7.0 libapache2-mod-php7.0

그 후 Apache를 재시작해야 합니다:

service apache2 restart

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

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

nano /var/www/html/info.php

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

Debian 9에서 Apache로 설치된 PHP

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

6 PHP에서 MySQL 및 MariaDB 지원 얻기

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

apt-cache search php7.0

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

apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl

이제 Apache를 재시작합니다:

service apache2 restart

7 PHP 속도를 높이기 위한 PHP 캐시

PHP 속도를 높이기 위해 Opcache를 설치해야 합니다. PHP Opcache 모듈이 올바르게 설치되고 활성화되었는지 확인하세요. 이 명령어를 실행합니다:

php --version

출력에는 제가 빨간색으로 표시한 줄이 포함되어야 합니다.

PHP 7.0.27-0+deb9u1 (cli) (built: Jan 5 2018 13:51:52) ( NTS )  
Copyright (c) 1997-2017 The PHP Group  
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies  
with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies

결과에서 Opcache 모듈이 보이지 않으면 다음 명령어로 설치합니다:

apt-get -y install php7.0-opcache

유용할 수 있는 또 다른 캐시가 있습니다. 이름은 APCu입니다. APCu는 PHP 중간 코드를 캐시하고 최적화하기 위한 무료 PHP opcode 캐셔입니다.

APCu는 다음과 같이 설치할 수 있습니다:

apt-get -y install php-apcu

이제 Apache를 재시작합니다:

service apache2 restart

이제 브라우저에서 http://192.168.1.100/info.php를 새로 고치고 모듈 섹션으로 다시 스크롤합니다. 이제 MariaDB 드라이버로 사용되는 MySQL 모듈을 포함하여 많은 새로운 모듈을 찾아야 합니다:

PHP 7에서 활성화된 MySQL 지원

8 phpMyAdmin

phpMyAdmin은 MySQL 및 MariaDB 데이터베이스를 관리할 수 있는 웹 인터페이스입니다. 설치하는 것이 좋습니다:

apt-get -y install phpmyadmin

다음 질문을 보게 됩니다:

Apache용 phpMyAdmin 구성

Web server to reconfigure automatically: <-- apache2
Configure database for phpmyadmin with dbconfig-common?<-- Yes
MySQL application password for phpmyadmin: <-- Press enter, apt will create a random password automatically.

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

Debian 9의 PHPMyAdmin

9 phpMyAdmin을 위한 MySQL 루트 로그인 활성화

쉘에서 MariaDB에 루트 사용자로 로그인할 수 있지만, phpMyAdmin에서는 루트 로그인이 작동하지 않습니다. 루트 사용자가 phpMyAdmin을 사용할 수 있도록 하려면 쉘에서 다음 명령어를 실행합니다:

echo "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';FLUSH PRIVILEGES;" | mysql -u root -p

10 링크

Share: X/Twitter LinkedIn

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

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