웹사이트 검색

Ubuntu 16.04 LTS에 PHP 7(PHP-FPM) 및 MySQL 5.7과 함께 Lighttpd 설치


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

  • Ubuntu 10.04(Lucid Lynx)

이 페이지에서

  1. 1 서문
  2. 2 MySQL 5.7 설치
  3. 3 Lighttpd 설치
  4. 4 PHP 7.0 설치
  5. 5 Lighttpd 및 PHP 7.0 구성
  6. 6 PHP 7.0 테스트/PHP 설치에 대한 세부 정보 얻기\n
  7. 7 PHP에서 MySQL 지원 받기
  8. 8 phpMyAdmin
  9. 9 PHP-FPM에서 TCP 연결 사용(선택 사항)\n
  10. 10개의 링크

Lighttpd는 속도가 중요한 환경을 위해 설계된 안전하고 빠른 표준 준수 웹 서버입니다. 이 튜토리얼은 PHP 7 지원(PHP-FPM을 통해) 및 MySQL 5.7을 사용하여 Ubuntu 16.04 서버에 Lighttpd를 설치하는 방법을 보여줍니다. PHP-FPM(FastCGI Process Manager)은 모든 규모의 사이트, 특히 사용량이 많은 사이트에 유용한 몇 가지 추가 기능이 있는 대체 PHP FastCGI 구현입니다. 이 튜토리얼에서는 Lighttpds spawn-fcgi 대신 PHP-FPM을 사용합니다.

1 서문

이 자습서에서는 호스트 이름 server1.example.com을 IP 주소 192.168.1.100과 함께 사용합니다. 이러한 설정은 사용자에 따라 다를 수 있으므로 적절하게 교체해야 합니다.

루트 권한으로 이 튜토리얼의 모든 단계를 실행하고 있으므로 루트로 로그인했는지 확인하십시오.

sudo -s

2 MySQL 5.7 설치

먼저 다음과 같이 MySQL을 설치합니다.

apt-get -y install mysql-server mysql-client

MySQL 루트 사용자의 비밀번호를 입력하라는 메시지가 표시됩니다. 이 비밀번호는 [이메일 보호] 사용자에게 유효하므로 나중에 수동으로 MySQL 루트 비밀번호를 지정할 필요가 없습니다.

MySQL "root" 사용자의 새 비밀번호: <-- yourrootsqlpassword
MySQL "root" 사용자의 비밀번호 반복: <-- yourrootsqlpassword

설치 프로그램이 MySQL 루트 암호를 설정했지만 안전한 MySQL 설치를 위해 변경해야 하는 몇 가지 추가 설정이 있습니다. 이는 mysql_secure_installation 명령으로 수행할 수 있습니다.

mysql_secure_installation

이 명령은 대화식입니다.

:~# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: <-- Enter the MySQL root password
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: <-- Press y if you want this function or press Enter otherwise.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : <-- Press enter
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : <-- 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? (Press y|Y for Yes, any other key for No) : <-- y
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : <-- 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? (Press y|Y for Yes, any other key for No) : <-- y
Success.
All done!

3 Lighttpd 설치

Lighttpd는 Ubuntu 패키지로 제공됩니다. 따라서 Ubuntu Xenial Xerus 패키지 저장소에서 apt로 직접 설치할 수 있습니다.

apt-get -y install lighttpd

이제 브라우저에서 http://192.168.1.100/으로 이동하면 Lighttp 자리 표시자 페이지가 표시됩니다.

Lighttpds 기본 문서 루트는 Ubuntu의 /var/www/html이고 구성 파일은 /etc/lighttpd/lighttpd.conf입니다. 추가 구성은 /etc/lighttpd/conf-available 디렉토리의 파일에 저장됩니다. 이러한 구성은 /etc/lighttpd/conf-enabled 디렉토리에서 적절한 구성으로 symlink를 생성하는 lighttpd-enable-mod 명령으로 활성화할 수 있습니다. 파일은 /etc/lighttpd/conf-available.conf에 있습니다. lighttpd-disable-mod 명령으로 구성을 비활성화할 수 있습니다.

4 PHP 7.0 설치

다음과 같이 설치하는 PHP-FPM을 통해 Lighttpd에서 PHP가 작동하도록 만들 수 있습니다.

apt-get -y install php7.0-fpm php7.0

PHP-FPM은 소켓 /var/run/php/php7.0-fpm.sock에서 FastCGI 서버를 실행하는 데몬 프로세스(init 스크립트 php5-fpm 포함)입니다.

5 Lighttpd 및 PHP 7.0 구성

Lighttpd에서 PHP를 활성화하려면 /etc/php/7.0/fpm/php.ini를 수정하고 cgi.fix_pathinfo=1 행의 주석 처리를 제거해야 합니다.

nano /etc/php/7.0/fpm/php.ini
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1
[...]

PHP /etc/lighttpd/conf-available/15-fastcgi-php.conf용 Lighttpd 구성 파일은 spawn-fcgi와 함께 사용하기에 적합하지만 PHP-FPM을 사용하고 싶으므로 파일의 백업을 만듭니다( 15-fastcgi-php.conf.bak로 이름 지정) 다음과 같이 15-fastcgi-php.conf를 수정합니다.

cd /etc/lighttpd/conf-available/
cp 15-fastcgi-php.conf 15-fastcgi-php.conf.bak
nano 15-fastcgi-php.conf
# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php7.0-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/var/run/php/php7.0-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

fastcgi 구성을 활성화하려면 다음 명령을 실행합니다.

lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php

이렇게 하면 /etc/lighttpd/conf-available/10-fastcgi.conf 및 /etc/lighttpd/conf-enabled/15-fastcgi-php를 가리키는 심볼릭 링크 /etc/lighttpd/conf-enabled/10-fastcgi.conf가 생성됩니다. /etc/lighttpd/conf-available/15-fastcgi-php.conf를 가리키는 .conf:

ls -l /etc/lighttpd/conf-enabled
:/etc/lighttpd/conf-available#

그런 다음 Lighttpd를 다시 로드합니다.

service lighttpd force-reload

참고: 로케일 오류가 발생하면 다음을 사용하여 오류를 제거할 수 있습니다.

apt-get -y install language-pack-en-base  
dpkg-reconfigure locales

6 PHP 7.0 테스트/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 라인에 표시된 것처럼 FPM/FastCGI를 통해 작동합니다. 더 아래로 스크롤하면 PHP5에서 이미 활성화된 모든 모듈이 표시됩니다. MySQL은 거기에 나열되어 있지 않습니다. 즉, 아직 PHP에서 MySQL을 지원하지 않는다는 의미입니다.

7 PHP에서 MySQL 지원 받기

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

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 php7.0-mbstring php-gettext

APCu는 PHP 7과 함께 제공되는 PHP Opcache 모듈의 확장으로, APC 캐시를 지원하는 소프트웨어(예: Wordpress 캐시 플러그인)에 대한 일부 호환성 기능을 추가합니다.

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

apt-get -y install php-apcu

이제 PHP-FPM을 다시 로드합니다.

service php7.0-fpm reload

이제 브라우저에서 http://192.168.1.100/info.php를 다시 로드하고 모듈 섹션으로 다시 스크롤하십시오. 이제 mysqli 및 mysqlnd 모듈을 포함하여 많은 새 모듈을 찾을 수 있습니다.

8 phpMyAdmin

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

apt-get -y install phpmyadmin

다음과 같은 질문이 표시됩니다.

Web server to reconfigure automatically: <-- lighttpd
Configure database for phpmyadmin with dbconfig-common? <-- Yes
MySQL application password for phpmyadmin: <-- Press Enter

다음과 같은 오류가 발생하는 경우:

Run /etc/init.d/lighttpd force-reload to enable changes
dpkg: error processing package phpmyadmin (--configure):
subprocess installed post-installation script returned error exit status 2
E: Sub-process /usr/bin/dpkg returned an error code (1)

그런 다음 다음 명령을 실행합니다.

/etc/init.d/lighttpd force-reload
apt-get -y install phpmyadmin

그런 다음 http://192.168.1.100/phpmyadmin/에서 phpMyAdmin에 액세스할 수 있습니다.

9 PHP-FPM이 TCP 연결을 사용하도록 만들기(선택 사항)

기본적으로 PHP-FPM은 /var/run/php/php7.0-fpm.sock 소켓에서 수신 대기합니다. PHP-FPM이 TCP 연결을 사용하도록 만드는 것도 가능합니다. 이렇게 하려면 /etc/php/7.0/fpm/pool.d/www.conf...를 엽니다.

nano /etc/php/7.0/fpm/pool.d/www.conf

... 다음과 같이 청취 라인을 만듭니다.

[...]
;listen = /var/run/php/php7.0-fpm.sock
listen = 127.0.0.1:9000
[...]

이렇게 하면 PHP-FPM이 IP 127.0.0.1(localhost)의 포트 9000에서 수신 대기하게 됩니다. 시스템에서 사용하지 않는 포트를 사용하고 있는지 확인하십시오.

그런 다음 PHP-FPM을 다시 로드합니다.

service php7.0-fpm reload

다음으로 Lighttpds PHP 구성 파일 /etc/lighttpd/conf-available/15-fastcgi-php.conf를 열고 소켓 행을 호스트 및 포트 행으로 바꿉니다.

nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php7.0-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

마지막으로 Lighttpd를 다시 로드합니다.

service lighttpd force-reload

10 링크

  • Lighttpd: http://www.lighttpd.net/
  • PHP: http://www.php.net/
  • PHP-FPM: http://php-fpm.org/
  • MySQL: http://www.mysql.com/
  • 우분투: http://www.ubuntu.com/
  • phpMyAdmin: http://www.phpmyadmin.net/