웹사이트 검색

CentOS/RHEL 8/7에 PHP 및 MariaDB와 함께 Lighttpd를 설치하는 방법


Lighttpd는 다른 웹 서버에 비해 메모리 사용량이 적고 속도가 중요한 환경을 위해 설계된 안전하고 빠르고 유연하며 더욱 최적화된 오픈 소스 웹 서버입니다.

효과적인 CPU 로드 관리를 통해 하나의 서버에서 최대 10,000개의 연결을 병렬로 처리할 수 있으며 FastCGI, SCGI, 인증, 출력 압축, URL 재작성 등과 같은 고급 기능 세트가 함께 제공됩니다.

Lighttpd는 다른 대체 웹 서버보다 동일한 하드웨어로 몇 배 더 나은 성능을 확장할 수 있는 고속 IO 인프라 덕분에 모든 Linux 서버에 탁월한 솔루션입니다.

이 튜토리얼에서는 PHP, PHP-FPMMariaDB와 함께 Lighttpd설치하는 방법을 설명합니다. Strong>CentOS/RHEL 8/7 호스트 이름이 linux-console.net이고 IP 주소가 192.168.0.103인 배포판.

1단계: Lighttpd 웹 서버 설치

1. Lighttpd를 설치하려면 먼저 다음 yum 명령을 사용하여 시스템 소프트웨어 패키지와 사용 가능한 저장소를 업데이트해야 합니다.

yum -y update

2. 다음으로, 다음 명령을 사용하여 시스템에서 EPEL 저장소를 활성화하고 소프트웨어 패키지를 업데이트해야 합니다.

yum -y install epel-release
yum -y update

3. EPEL 저장소를 활성화하고 나면 이제 다음 명령을 실행하여 Lighttpd를 설치할 수 있습니다.

yum install lighttpd

4. Lighttpd 패키지가 설치되면 서비스를 시작하고 부팅 시 자동으로 시작되도록 활성화하고 다음 명령을 사용하여 상태를 확인할 수 있습니다.

systemctl start lighttpd
systemctl enable lighttpd
systemctl status lighttpd

5. 이제 다음 명령을 사용하여 시스템에 설치된 Lighttpd 버전을 확인하세요.

lighttpd -v

lighttpd/1.4.55 (ssl) - a light and fast webserver

6. 이제 방화벽에서 HTTPHTTPS 트래픽을 허용해야 합니다.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

7. 이제 브라우저를 열고 다음 URL을 가리켜 Lighttpd 웹 서버가 작동하는지 확인하세요.

http://Your-Domain.com
OR
http://Your-IP-addr

Lighttpd의 기본 문서 루트 디렉터리는 /var/www/lighttpd/이고 기본 구성 파일은 /etc/lighttpd/lighttpd.conf 아래에 있습니다.

2단계: CentOS 7에 MariaDB를 MySQL로 설치

8. 다음으로, 다음 명령을 사용하여 Lighttpd에 대한 MySQL 지원을 설치합니다.

yum -y install mariadb mariadb-server

9. 설치가 완료되면 다음 명령을 사용하여 MariaDB를 시작하고 활성화하고 상태를 확인하세요.

systemctl start mariadb.service
systemctl enable mariadb.service
systemctl status mariadb.service

10. 마지막으로 다음 명령을 실행하여 MariaDB 설치를 보호해야 합니다.

mysql_secure_installation

MariaDB 설치 및 보안 방법에 관한 몇 가지 질문이 표시됩니다. 데이터베이스 루트 사용자 비밀번호를 변경하고, 테스트 데이터베이스를 비활성화하고, 익명 사용자를 비활성화하고, 루트 로그인을 원격으로 비활성화할 수 있습니다.

샘플 출력
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): Enter OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. Set root password? [Y/n] y New password: Re-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!

11. MySQL 서버에 연결을 시도하고 터미널에서 다음 명령을 사용하여 데이터베이스 서버의 기존 데이터베이스를 검토합니다.

mysql -u root -p
샘플 출력
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>

3단계: CentOS 7에 FastCGI를 사용하여 PHP 및 PHP-FPM 설치

12. FastCGI 지원과 함께 PHP-FPM을 활성화하려면 먼저 필요한 확장 프로그램과 함께 PHP를 설치해야 합니다. 다음 명령을 사용합니다.

yum -y install php php-mysqlnd php-pdo php-gd php-mbstring

13. PHP가 설치되면 이제 LighttpdPHP-FPMFastCGI 지원을 활성화합니다. > 이렇게 하려면 이 패키지도 설치해야 합니다.

yum -y install php-fpm lighttpd-fastcgi

14. 이제 /etc/php-fpm.d/www.conf라는 파일을 엽니다.

vi /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은 기본적으로 /var/run/php/php7.0-fpm.sock 소켓을 사용하므로 PHP-FPM을 만들어야 합니다. Strong> TCP 연결을 사용합니다. listen 줄을 다음과 같이 만드세요:

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

15. 이제 PHP-FPM 서비스를 시작하고 다음 명령을 사용하여 부팅 시 자동으로 시작되도록 활성화합니다.

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

4단계: Lighttpd에서 FastCGI를 사용하여 PHP 및 PHP-FPM 활성화

16. 여기서는 /etc/php.ini, /etc/lighttpd/modules.conf 세 개의 파일을 수정해야 합니다. /etc/lighttpd/conf.d/fastcgi.conf를 사용하여 Lighttpd에 대한 PHP 지원을 활성화합니다.

첫 번째 파일 /etc/php.ini를 엽니다.

vi /etc/php.ini

cgi.fix_pathinfo=1 라인이라는 다음 라인의 주석 처리를 제거하세요.

; 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

그런 다음 /etc/lighttpd/modules.conf라는 두 번째 파일을 엽니다.

vi /etc/lighttpd/modules.conf

include “conf.d/fastcgi.conf”라는 다음 줄의 주석 처리를 제거하세요.

##
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"

다음으로 /etc/lighttpd/conf.d/fastcgi.conf라는 세 번째 파일을 엽니다.

vi /etc/lighttpd/conf.d/fastcgi.conf

이제 파일 하단에 다음 컨테이너를 추가하고 저장합니다.

fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

변경 사항을 반영하고 PHP 지원을 활성화하려면 Lighttpd 서비스를 다시 시작하세요.

systemctl restart lighttpd

5단계: Lighttpd에서 FastCGI 지원으로 PHP 및 PHP-FPM 테스트

17. 위에서 말했듯이 Lighttpd의 기본 문서 루트는 /var/www/lighttpd/입니다. 따라서 여기서는 이 디렉토리에 phpinfo.php 파일을 생성하겠습니다.

vi /var/www/lighttpd/info.php

다음 줄을 추가하십시오. 이 작은 코드 조각은 해당 버전과 함께 PHP 설치에 대한 정보를 표시합니다.

<?php
phpinfo();
?>

18. 브라우저를 열고 다음 링크로 이동하세요.

http://Your-Domain.com/info.php
OR
http://Your-IP-addr/info.php

이미 활성화된 다른 많은 모듈과 함께 PHP, PHP-FPMMySQL의 작동 정보를 볼 수 있습니다.