웹사이트 검색

Apache, PHP 7 및 MariaDB를 사용한 Debian 9 LAMP 서버 자습서


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 데비안 9(스트레치)
  • 데비안 6(압축)

이 페이지에서

  1. 1 서문
  2. 2 MySQL 대체품으로 MariaDB 설치\n
  3. 3 Apache 웹 서버 설치
  4. 4 PHP 7.1 설치
  5. 5 PHP 테스트/PHP 설치에 대한 세부 정보 얻기\n
  6. 6 PHP에서 MySQL 및 MariaDB 지원 받기
  7. PHP 속도를 향상시키는 7개의 PHP 캐시\n
  8. 8 phpMyAdmin
  9. 9 phpMyAdmin에 대한 MySQL 루트 로그인 활성화\n
  10. 10개의 링크

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 자리 표시자 페이지가 표시됩니다(작동합니다!).

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

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
<?php
phpinfo();

이제 브라우저에서 해당 파일을 호출합니다(예: http://192.168.1.100/info.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

PHP 속도를 향상시키는 7 PHP 캐시

PHP 속도를 높이려면 Opcache를 설치해야 합니다. PHP Opcache 모듈이 올바르게 설치되고 활성화되었는지 확인하십시오. 다음 명령을 실행하십시오.

php --version

출력에는 빨간색으로 표시된 라인 I가 포함됩니다.

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 모듈을 포함하여 많은 새 모듈을 찾을 수 있습니다.

8 phpMyAdmin

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

apt-get -y install 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에 액세스할 수 있습니다.

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 링크

  • 아파치: http://httpd.apache.org/
  • PHP: http://www.php.net/
  • MySQL: http://www.mysql.com/
  • 데비안: http://www.debian.org/
  • phpMyAdmin: http://www.phpmyadmin.net/