search
HomeSystem TutorialLINUXInstalling the Lighttpd web server in Linux

Installing the Lighttpd web server in Linux

Aug 14, 2024 am 10:08 AM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

Lighttpd is an open source web server software. Lighttpd is secure, fast, industry-standard, adaptable and optimized for high-configuration environments. Compared with other web servers, Lighttpd takes up less memory; it stands out from many web servers in terms of efficiency and speed because of its small CPU usage and optimization of processing speed. And Lighttpd's advanced features such as FastCGI, CGI, authentication, output compression, URL rewriting and other advanced features are even better news for servers facing performance pressure.

Here is our brief process for installing Lighttpd web server on a machine running Ubuntu 15.04 or CentOS 7 Linux distribution.

Install Lighttpd
Install using package manager

Here we install Lighttpd in the simplest way using the package manager. Just enter the following command in the terminal or console in sudo mode.

CentOS 7

Since Lighttpd is not provided in the official CentOS 7.0 repository, we need to install additional software source epel repository in the system. Use the yum command below to install epel.

# yum install epel-release

Then, we need to update the system and prepare for the installation of Lighttpd.

# yum update
# yum install lighttpd

在 Linux 中安装 Lighttpd Web 服务器

Ubuntu 15.04

Lighttpd is included in the official Ubuntu 15.04 repository, so just update your local repository index and use the apt-get command to install Lighttpd.

# apt-get update
# apt-get install lighttpd

在 Linux 中安装 Lighttpd Web 服务器

Install Lighttpd from source

If you want to install the latest version (for example 1.4.39) from the Lighttpd source code, we need to compile the source code locally and install it. First we need to install the dependency packages required to compile the source code.

# cd /tmp/
# wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.39.tar.gz

After the download is completed, execute the following instructions to decompress it.

# tar -zxvf lighttpd-1.4.39.tar.gz

Then use the following instructions to compile.

# cd lighttpd-1.4.39
# ./configure
# make

Note: In this tutorial, we installed Lighttpd with the default configuration. Other extended functions, such as support for SSL, modrewrite, modredirect, etc., need to be configured by yourself.

When the compilation is completed, we can install it into the system.

# make install
Setting up Lighttpd

If there are higher requirements, we can further set up Lighttpd by modifying the default settings file, such as /etc/lighttpd/lighttpd.conf. In this tutorial we will use the default settings and not modify the settings file. If you have made changes and want to check whether there are errors in the settings file, you can execute the following command.

# lighttpd -t -f /etc/lighttpd/lighttpd.conf
Using CentOS 7

In CentOS 7, we need to create a webroot folder set in the Lighttpd default configuration file, such as /src/www/htdocs.

# mkdir -p /srv/www/htdocs/

Then copy the default welcome page from /var/www/lighttpd to the newly created directory:

# cp -r /var/www/lighttpd/* /srv/www/htdocs/
Start service

Now, restart the web service by executing the systemctl command.

# systemctl start lighttpd

Then we set it to run automatically on system startup.

# systemctl enable lighttpd
Set up firewall

如要让我们运行在 Lighttpd 上的网页或网站能在 Internet 或同一个网络内被访问,我们需要在防火墙程序中设置打开 80 端口。由于 CentOS 7 和 Ubuntu15.04 都附带 Systemd 作为默认初始化系统,所以我们默认用的都是 firewalld。如果要打开 80 端口或 http 服务,我们只需执行下面的命令:

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success
连接至 Web 服务器

在将 80 端口设置为默认端口后,我们就可以直接访问 Lighttpd 的默认欢迎页了。我们需要根据运行 Lighttpd 的设备来设置浏览器的 IP 地址和域名。在本教程中,我们令浏览器访问 http://lighttpd.linoxide.com/ ,同时将该子域名指向上述 IP 地址。如此一来,我们就可以在浏览器中看到如下的欢迎页面了。

在 Linux 中安装 Lighttpd Web 服务器

此外,我们可以将网站的文件添加到 webroot 目录下,并删除 Lighttpd 的默认索引文件,使我们的静态网站可以在互联网上访问。

如果想在 Lighttpd Web 服务器中运行 PHP 应用,请参考下面的步骤:

安装 PHP5 模块

在 Lighttpd 成功安装后,我们需要安装 PHP 及相关模块,以在 Lighttpd 中运行 PHP5 脚本。

使用 Ubuntu 15.04
# apt-get install php5 php5-cgi php5-fpm php5-mysql php5-curl php5-gd php5-intl php5-imagick php5-mcrypt php5-memcache php-pear
使用 CentOS 7
# yum install php php-cgi php-fpm php-mysql php-curl php-gd php-intl php-pecl-imagick php-mcrypt php-memcache php-pear lighttpd-fastcgi
设置 Lighttpd 的 PHP 服务

如要让 PHP 与 Lighttpd 协同工作,我们只要根据所使用的发行版执行如下对应的指令即可。

使用 CentOS 7

首先要做的便是使用文件编辑器编辑 php 设置文件(例如/etc/php.ini)并取消掉对cgi.fix_pathinfo=1这一行的注释。

# nano /etc/php.ini

完成上面的步骤之后,我们需要把 PHP-FPM 进程的所有权从 Apache 转移至 Lighttpd。要完成这些,首先用文件编辑器打开/etc/php-fpm.d/www.conf文件。

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

然后在文件中增加下面的语句:

user = lighttpd
group = lighttpd

做完这些,我们保存并退出文本编辑器。然后从/etc/lighttpd/modules.conf设置文件中添加 FastCGI 模块。

# nano /etc/lighttpd/modules.conf

然后,去掉下面语句前面的#来取消对它的注释。

include "conf.d/fastcgi.conf"

最后我们还需在文本编辑器设置 FastCGI 的设置文件。

# nano /etc/lighttpd/conf.d/fastcgi.conf

在文件尾部添加以下代码:

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

在编辑完成后保存并退出文本编辑器即可。

使用 Ubuntu 15.04

如需启用 Lighttpd 的 FastCGI,只需执行下列代码:

# lighttpd-enable-mod fastcgi

Enabling fastcgi: ok
Run /etc/init.d/lighttpd force-reload to enable changes

# lighttpd-enable-mod fastcgi-php

Enabling fastcgi-php: ok
Run `/etc/init.d/lighttpd` force-reload to enable changes

然后,执行下列命令来重启 Lighttpd。

# systemctl force-reload lighttpd
检测 PHP 工作状态

如需检测 PHP 是否按预期工作,我们需在 Lighttpd 的 webroot 目录下新建一个 php 文件。本教程中,在 Ubuntu 下 /var/www/html 目录,CentOS 下 /src/www/htdocs 目录下使用文本编辑器创建并打开 info.php。

使用 CentOS 7
# nano  /var/www/info.php
使用 Ubuntu 15.04
# nano /srv/www/htdocs/info.php

然后只需将下面的语句添加到文件里即可。

<?php phpinfo(); ?>

在编辑完成后保存并推出文本编辑器即可。

现在,我们需根据路径 http://lighttpd.linoxide.com/info.php 下的 info.php 文件的 IP 地址或域名,来让我们的网页浏览器指向系统上运行的 Lighttpd。如果一切都按照以上说明进行,我们将看到如下图所示的 PHP 页面信息。

在 Linux 中安装 Lighttpd Web 服务器

总结

至此,我们已经在 CentOS 7 和 Ubuntu 15.04 Linux 发行版上成功安装了轻巧快捷并且安全的 Lighttpd Web 服务器。现在,我们已经可以上传网站文件到网站根目录、配置虚拟主机、启用 SSL、连接数据库,在我们的 Lighttpd Web 服务器上运行 Web 应用等功能了。

The above is the detailed content of Installing the Lighttpd web server in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Does the internet run on Linux?Does the internet run on Linux?Apr 14, 2025 am 12:03 AM

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

What are Linux operations?What are Linux operations?Apr 13, 2025 am 12:20 AM

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Boost Productivity with Custom Command Shortcuts Using Linux AliasesBoost Productivity with Custom Command Shortcuts Using Linux AliasesApr 12, 2025 am 11:43 AM

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

What is Linux actually good for?What is Linux actually good for?Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

Essential Tools and Frameworks for Mastering Ethical Hacking on LinuxEssential Tools and Frameworks for Mastering Ethical Hacking on LinuxApr 11, 2025 am 09:11 AM

Introduction: Securing the Digital Frontier with Linux-Based Ethical Hacking In our increasingly interconnected world, cybersecurity is paramount. Ethical hacking and penetration testing are vital for proactively identifying and mitigating vulnerabi

How to learn Linux basics?How to learn Linux basics?Apr 10, 2025 am 09:32 AM

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

What is the most use of Linux?What is the most use of Linux?Apr 09, 2025 am 12:02 AM

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

What are the disadvantages of Linux?What are the disadvantages of Linux?Apr 08, 2025 am 12:01 AM

The disadvantages of Linux include user experience, software compatibility, hardware support, and learning curve. 1. The user experience is not as friendly as Windows or macOS, and it relies on the command line interface. 2. The software compatibility is not as good as other systems and lacks native versions of many commercial software. 3. Hardware support is not as comprehensive as Windows, and drivers may be compiled manually. 4. The learning curve is steep, and mastering command line operations requires time and patience.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools