Ubuntu 12.04에서 PHP5(PHP-FPM) 및 MySQL 지원으로 Lighttpd 설치

Ubuntu 12.04에서 PHP5(PHP-FPM) 및 MySQL 지원으로 Lighttpd 설치

2022-10-19 last update

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

1 서문


이 자습서에서는 IP 주소가 192.168.0.100인 호스트 이름 server1.example.com을 사용합니다. 이러한 설정은 사용자에 따라 다를 수 있으므로 적절한 경우 교체해야 합니다.
이 튜토리얼의 모든 단계를 루트 권한으로 실행 중이므로 루트로 로그인했는지 확인하십시오.
sudo su

2 MySQL 5 설치하기


먼저 다음과 같이 MySQL 5를 설치합니다.
apt-get install mysql-server mysql-client
MySQL 루트 사용자의 비밀번호를 제공하라는 메시지가 표시됩니다. 이 비밀번호는 [email protected][email protected] 사용자에게 유효하므로 나중에 MySQL 루트 비밀번호를 수동으로 지정할 필요가 없습니다. :
MySQL "루트"사용자의 새 비밀번호: <-- yourrootsqlpassword MySQL "루트"사용자의 비밀번호 반복: <-- yourrootsqlpassword

3 Lighttpd 설치


Lighttpd는 Ubuntu 패키지로 제공되므로 다음과 같이 설치할 수 있습니다.
apt-get install lighttpd
이제 브라우저를 http://192.168.0.100/index.lighttpd.html로 이동하면 Lighttpd 자리 표시자 페이지가 표시됩니다.

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

4 PHP5 설치


다음과 같이 설치하는 PHP-FPM을 통해 Lighttpd에서 PHP5가 작동하도록 할 수 있습니다.
apt-get install php5-fpm php5
PHP-FPM은 포트 9000에서 FastCGI 서버를 실행하는 데몬 프로세스(초기화 스크립트/etc/init.d/php5-fpm 포함)입니다.

5 Lighttpd 및 PHP5 구성


Lighttpd에서 PHP5를 활성화하려면/etc/php5/fpm/php.ini를 수정하고 cgi.fix_pathinfo=1 라인의 주석을 제거해야 합니다.
vi /etc/php5/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용 Lighttpd 구성 파일/etc/lighttpd/conf-available/15-fastcgi-php.conf는 spawn-fcgi와 함께 사용하기에 적합하지만 PHP-FPM을 사용하기를 원하므로 파일( 15-fastcgi-php-spawnfcgi.conf라는 이름을 지정하고 15-fastcgi-php.conf를 다음과 같이 수정합니다.
cd /etc/lighttpd/conf-available/
cp 15-fastcgi-php.conf 15-fastcgi-php-spawnfcgi.conf
vi 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 php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "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
[email protected]:/etc/lighttpd/conf-available# ls -l /etc/lighttpd/conf-enabled
total 0
lrwxrwxrwx 1 root root 33 May 15 19:50 10-fastcgi.conf -> ../conf-available/10-fastcgi.conf
lrwxrwxrwx 1 root root 41 May 15 19:50 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf
[email protected]:/etc/lighttpd/conf-available#
그런 다음 Lighttpd를 다시 로드합니다.
/etc/init.d/lighttpd force-reload