웹사이트 검색

CentOS 7에서 PHP-FPM 및 MariaDB와 함께 Lighttpd를 설치하는 방법


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

  • 센트OS 5.6

이 페이지에서

  1. 1 서문
  2. 2 MariaDB를 MySQL 드롭 인 교체로 설치
  3. 3 Lighttpd 설치
  4. 4 PHP 설치

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

1 서문

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

2 MariaDB를 MySQL 드롭 인 교체로 설치

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

yum -y install mariadb mariadb-server

그런 다음 MySQL용 시스템 시작 링크를 만들고(시스템이 부팅될 때마다 MySQL이 자동으로 시작되도록) MySQL 서버를 시작합니다.

systemctl enable  mariadb.service
systemctl start  mariadb.service

MarisDB 루트 계정의 비밀번호를 설정합니다.

mysql_secure_installation
[ ~]# mysql_secure_installation
/usr/bin/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): <-- press 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] <-- y
New password: <-- enter new password
Re-enter new password: <-- enter new password
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!

3 Lighttpd 설치

Lighttpd 및 PHP-FPM은 공식 CentOS 리포지토리에서 사용할 수 없으므로 EPEL 리포지토리를 활성화해야 합니다.

yum -y install epel-release

EPEL GPG 키 가져오기:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

그런 다음 다음을 실행하십시오.

yum update

그런 다음 Lighttpd를 다음과 같이 설치할 수 있습니다.

yum -y install lighttpd

그런 다음 Lighttpd에 대한 시스템 시작 링크를 만들고(시스템이 부팅될 때마다 Lighttpd가 자동으로 시작되도록) 시작합니다.

systemctl enable  lighttpd.service
systemctl start  lighttpd.service

Lighttpd가 다음 오류 메시지와 함께 시작되지 않는 경우...

(network.c.203) socket failed: Address family not supported by protocol

... /etc/lighttpd/lighttpd.conf 열기...

nano /etc/lighttpd/lighttpd.conf

... 그리고 server.use-ipv6을 활성화에서 비활성화로 변경합니다.

[...]
##
## Use IPv6?
##
server.use-ipv6 = "disable"
[...]

그런 다음 Lighttpd를 다시 시작하십시오. 이제 문제 없이 작동합니다.

systemctl start  lighttpd.service

Lighttpd는 /var/www/htdocs(기본 디렉토리 /var/www 및 lighttpd.conf 파일에 따라 하위 디렉토리로 htdocs)에 문서 루트가 있지만 기본 파일을 설치합니다. /var/www/lighthttpd로. 일관성이 없으므로 이와 같이 디렉토리 이름을 바꿔야 합니다.

mv /var/www/lighttpd /var/www/htdocs

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

Lighttpds 기본 문서 루트는 CentOS 7에서 /var/www/htdocs/이고 구성 파일은 /etc/lighthttpd/lighttpd.conf입니다.

4 PHP 설치

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

yum -y install php-fpm lighttpd-fastcgi

PHP-FPM은 포트 9000에서 FastCGI 서버를 실행하는 데몬 프로세스입니다.

열기 /etc/php-fpm.d/www.conf...

nano /etc/php-fpm.d/www.conf

... 사용자 및 그룹을 lighttpd로 설정합니다.

[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd
[...]

PHP-FPM용 시스템 시작 링크를 생성하고 시작합니다.

systemctl enable  php-fpm.service
systemctl start  php-fpm.service