Ubuntu下Lighttpd服务器安装,并支持PHP

news2024/7/6 18:35:12

1、说明

        Lighttpd 是一个德国人领导的开源Web服务器软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销、cpu占用率低、效能好以及丰富的模块等特点。

        Lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI,CGI,Auth,输出压缩(output compress),URL重写,Alias等重要功能。

        PHP(PHP: Hypertext Preprocessor)即“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。

本系统已经安装好,仅做过程演示;

2、安装步骤

  sudo apt update
  sudo apt install lighttpd
  sudo apt-get install php7.2 php7.2-fpm php7.2-cgi
  php -v
  lighttpd -v

sunny@ubuntu:~$ uname -a
Linux ubuntu 5.4.0-150-generic #167~18.04.1-Ubuntu SMP Wed May 24 00:51:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

sunny@ubuntu:~$ sudo apt update
[sudo] password for sunny: 
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease                    
Hit:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease            
Hit:3 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease        
Hit:5 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
11 packages can be upgraded. Run 'apt list --upgradable' to see them.

sunny@ubuntu:~$ sudo apt install lighttpd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
lighttpd is already the newest version (1.4.45-1ubuntu3.18.04.1).
The following packages were automatically installed and are no longer required:
  gir1.2-goa-1.0 gir1.2-snapd-1
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

sunny@ubuntu:~$ sudo apt-get install php7.2 php7.2-fpm php7.2-cgi
Reading package lists... Done
Building dependency tree       
Reading state information... Done
php7.2 is already the newest version (7.2.24-0ubuntu0.18.04.17).
php7.2-cgi is already the newest version (7.2.24-0ubuntu0.18.04.17).
php7.2-fpm is already the newest version (7.2.24-0ubuntu0.18.04.17).
The following packages were automatically installed and are no longer required:
  gir1.2-goa-1.0 gir1.2-snapd-1
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

sunny@ubuntu:~$ lighttpd -v
lighttpd/1.4.45 (ssl) - a light and fast webserver
Build-Date: Jun 15 2021 14:44:25

sunny@ubuntu:~$ php -v
PHP 7.2.24-0ubuntu0.18.04.17 (cli) (built: Feb 23 2023 13:29:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.17, Copyright (c) 1999-2018, by Zend Technologies

3、修改lighttpd配置文件

server.document-root     = "/home/sunny/www"
server.upload-dirs          = ( "/home/sunny/www/lighttpd/uploads" )
server.errorlog               = "/home/sunny/www/lighttpd/error.log"
server.port                     = 8080

root@ubuntu:/usr/bin# cd /etc/lighttpd/
root@ubuntu:/etc/lighttpd# ls
conf-available  conf-enabled  lighttpd.conf
root@ubuntu:/etc/lighttpd# cat lighttpd.conf 
server.modules = (
	"mod_access",
	"mod_alias",
	"mod_compress",
 	"mod_redirect",
)

server.document-root        = "/home/sunny/www"
server.upload-dirs          = ( "/home/sunny/www/lighttpd/uploads" )
server.errorlog             = "/home/sunny/www/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 8080

index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

4、启动lighttpd

sudo /etc/init.d/lighttpd start

sudo /etc/init.d/lighttpd start    // 启动
sudo /etc/init.d/lighttpd stop     // 停止
sudo /etc/init.d/lighttpd restart  // 重启,修改配置文件会后,需要执行后生效

查看服务情况:
ps aux | grep lighttpd
lsof -i :8080
netstat -nlpt|grep 8080

root@ubuntu:/etc/lighttpd# ps aux | grep lighttpd
www-data    858  0.0  0.2  57616  4900 ?        Ss   13:25   0:00 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
root       3988  0.0  0.0  14432  1040 pts/0    S+   13:53   0:00 grep --color=auto lighttpd

root@ubuntu:/etc/lighttpd# lsof -i :8080
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
lighttpd 858 www-data    4u  IPv4  46670      0t0  TCP *:http-alt (LISTEN)

root@ubuntu:/etc/lighttpd# netstat -nlpt|grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      858/lighttpd   

5、创建测试文件

/home/sunny/www/index.php

sunny@ubuntu:~/www$ pwd
/home/sunny/www

sunny@ubuntu:~/www$ mkdir lighttpd
sunny@ubuntu:~/www$ touch lighttpd/error.log

sunny@ubuntu:~/www$ chmod  777  lighttpd
sunny@ubuntu:~/www$ chmod  777  lighttpd/error.log

sunny@ubuntu:~/www$ tree ./
./
├── index.php
└── lighttpd
    ├── error.log
    └── uploads

2 directories, 2 files

sunny@ubuntu:~/www$ vi index.php
<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
echo phpinfo();
?>

</body>
</html>

6、访问WEB

方法1:curl http://192.168.0.143:8080/

sunny@ubuntu:~/www$ curl http://192.168.0.143:8080/
<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

Hello World!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
a:link {color: #009; text-decoration: none; background-color: #fff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse; border: 0; width: 934px; box-shadow: 1px 2px 3px #ccc;}
.center {text-align: center;}
.center table {margin: 1em auto; text-align: left;}
.center th {text-align: center !important;}
td, th {border: 1px solid #666; font-size: 75%; vertical-align: baseline; padding: 4px 5px;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccf; width: 300px; font-weight: bold;}
.h {background-color: #99c; font-weight: bold;}
.v {background-color: #ddd; max-width: 300px; overflow-x: auto; word-wrap: break-word;}
.v i {color: #999;}
img {float: right; border: 0;}
hr {width: 934px; background-color: #ccc; border: 0; height: 1px;}
</style>
<title>phpinfo()</title><meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" /></head>
<body><div class="center">
......

方法2,浏览器访问:

7、PHP FastCgi

示例中已经配置了PHP FastCgi,配置步骤如下:

1、放开如下配置项
sudo vi /etc/php/7.2/fpm/php.ini
cgi.fix_pathinfo=1

sudo vi /etc/lighttpd/conf-available/15-fastcgi-php.conf 
"socket" => "/var/run/lighttpd/php7.2.socket",

2、重启php fpm
systemctl restart php7.2-fpm.service 

3、查询php状态
sunny@ubuntu:/home$ ps aux | grep php
root      14974  0.3  0.8 290452 16744 ?        Ss   16:01   0:00 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
www-data  14975  0.0  0.3 292748  7620 ?        S    16:01   0:00 php-fpm: pool www
www-data  14976  0.0  0.3 292748  7620 ?        S    16:01   0:00 php-fpm: pool www
sunny     14980  0.0  0.0  14432  1032 pts/0    S+   16:02   0:00 grep --color=auto php

4、使能php fastcgi
sunny@ubuntu:/home$ sudo lighttpd-enable-mod fastcgi fastcgi-php
Enabling fastcgi: ok
Met dependency: fastcgi
Enabling fastcgi-php: ok
already enabled
Run "service lighttpd force-reload" to enable changes

5、重启lighttpd
sudo /etc/init.d/lighttpd stop
sudo /etc/init.d/lighttpd start

6、便能看到第6步的效果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1366948.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C++力扣题目--94,144,145二叉树非递归(迭代)遍历

为什么可以用迭代法&#xff08;非递归的方式&#xff09;来实现二叉树的前后中序遍历呢&#xff1f; 我们在栈与队列&#xff1a;匹配问题都是栈的强项 (opens new window)中提到了&#xff0c;递归的实现就是&#xff1a;每一次递归调用都会把函数的局部变量、参数值和返回地…

使用 vue-json-viewer 工具在界面显示json格式数据

安装vue-json-viewer npm install vue-json-viewer --save 引入&#xff1a; import JsonViewer from vue-json-viewer Vue.use(JsonViewer) 使用&#xff1a; <json-viewer :value"jsonData" show-double-quotes :preview-mode"true" :show-array…

excel中相同类型的数据归到一起显示

1.选中所有数据 2.开始菜单-排序和筛选-自定义排序 3.选择分类关键字 此处&#xff0c;以属性为例 4.效果 归类后的数据&#xff1a;

JetPack组件学习ViewModel

ViewModel的使用 1.需要先创建ViewModel类&#xff0c;继承自ViewModel重写onclear方法&#xff0c;使得页面销毁的时候能够走到自定义的onClear方法中 class MyViewModel : ViewModel() {//共享数据的核心在于拿到同一个LiveData实例&#xff0c;也就是拿到同一个ViewModel实…

面试算法102:加减的目标值

题目 给定一个非空的正整数数组和一个目标值S&#xff0c;如果为每个数字添加“”或“-”运算符&#xff0c;请计算有多少种方法可以使这些整数的计算结果为S。例如&#xff0c;如果输入数组[2&#xff0c;2&#xff0c;2]并且S等于2&#xff0c;有3种添加“”或“-”的方法使…

商中在线(商务中国)域名外部入库流程

注册商是商中在线&#xff0c;且在商中在线管理的&#xff0c;请使用此教程外部入库。 如您的域名注册商是商中在线但在聚名管理&#xff0c;请参考教程&#xff1a;聚名平台域名外部入库流程 -西部数码帮助中心 一、在我司提交入库 1、在【业务管理】-【域名管理】-【外…

Qt/QML编程学习之心得:一个音频播放器的实现(29)

在window下&#xff0c;打开音乐播放器&#xff0c;然后打开一个.mp3文件&#xff0c;就可以实现播放了&#xff0c;那么在Qt/QML中如何实现呢&#xff1f;首先所有的设计都是基于音乐播放器的&#xff0c;嵌入式linux下同样也有音乐播放器&#xff0c;比如mplayer。其调用方法…

2_工厂设计_工厂方法和抽象工厂

工厂设计模式-工厂方法 1.概念 工厂方法模式(Fatory Method Pattern ) 是指定义一个创建对象的接口&#xff0c;但让实现这个接口的类来决定实例化哪个类&#xff0c;工厂方法让类的实例化推迟到子类中进行。 在工厂方法模式中用户只需要关心所需产品对应的工厂&#xff0c;…

阿里开源AnyText:可在图像中生成任意精准文本,支持中文!

‍随着Midjourney、Stable Difusion等产品的出现&#xff0c;文生图像领域获得了巨大突破。但是想在图像中生成/嵌入精准的文本却比较困难。 经常会出现模糊、莫名其妙或错误的文本&#xff0c;尤其是对中文支持非常差&#xff0c;例如&#xff0c;生成一张印有“2024龙年吉祥…

数据分析基础之《pandas(1)—pandas介绍》

一、pandas介绍 1、2008年Wes McKinney&#xff08;韦斯麦金尼&#xff09;开发出的库 2、专门用于数据分析的开源python库 3、以numpy为基础&#xff0c;借力numpy模块在计算方面性能高的优势 4、基于matplotlib能够简便的画图 5、独特的数据结构 6、也是三个单词组合而…

2024年数学建模美赛能用chatGPT之类的AI吗?官方给了明确规定!

这两年chatGPT等大语言模型火了&#xff0c;能对话&#xff0c;自然也能回答数学建模方面的问题。 那美赛能不能用这些AI呢&#xff1f;2024年美赛官方对chatGPT等的使用做出了明确的规定&#xff08;其中的VI. Contest Instructions部分&#xff09;&#xff1a; https://ww…

《2024 AIGC 应用层十大趋势白皮书》:近屿智能OJAC带您一起探索AI未来

Look&#xff01;&#x1f440;我们的大模型商业化落地产品&#x1f4d6;更多AI资讯请&#x1f449;&#x1f3fe;关注Free三天集训营助教在线为您火热答疑&#x1f469;&#x1f3fc;‍&#x1f3eb; 近日国际知名咨询机构IDC发布《2024 AIGC 应用层十大趋势白皮书》的发布&am…

水文模型(科普类)

SWMM 模型概况&#xff1a; SWMM5 系列拥有编辑区域数据的功能&#xff0c;而且能模拟水文、 水力和水质。其核心部分是管道汇流计算模块&#xff0c;提供了恒定流法、运动波法和动力波法三种水动力学 方法。其中动力波法通过求解完整的圣维南方 程组进行计算&#xff0c;能够…

WPF自定义漂亮顶部工具栏 WPF自定义精致最大化关闭工具栏 wpf导航栏自定义 WPF快速开发工具栏

在WPF应用程序开发中&#xff0c;自定义一个漂亮的顶部工具栏具有多重关键作用&#xff0c;它不仅增强了用户体验&#xff0c;还提升了整体应用的专业性和易用性。以下是对这一功能的详细介绍&#xff1a; 首先&#xff0c;自定义顶部工具栏是用户界面设计的重要组成部分&…

508基于51单片机的火灾检测与报警系统设计

基于51单片机的火灾检测与报警系统设计[proteus仿真] 火灾检测与报警系统这个题目算是课程设计和毕业设计中常见的题目了&#xff0c;本期是一个基于51单片机的火灾检测与报警系统设计 需要的源文件和程序的小伙伴可以关注公众号【阿目分享嵌入式】&#xff0c;赞赏任意文章 …

BigDecimal的性能问题

BigDecimal 是 Java 中用于精确计算的数字类&#xff0c;它可以处理任意精度的小数运算。由于其精确性和灵活性&#xff0c;BigDecimal 在某些场景下可能会带来性能问题。 BigDecimal的性能问题 BigDecimal的性能问题主要源于以下几点&#xff1a; 内存占用&#xff1a;BigDec…

华为OD机试 - 反射计数(Java JS Python C)

题目描述 给定一个包含 0 和 1 的二维矩阵。 给定一个初始位置和速度,一个物体从给定的初始位置出发,在给定的速度下进行移动,遇到矩阵的边缘则发生镜面发射。 无论物体经过 0 还是 1,都不影响其速度。 请计算并给出经过 t 时间单位后,物体经过 1 点的次数。 矩阵以左…

国产编程语言炫彩,界面库ui dll,有人了解吗

中文编程: 中英文双语编程, 中英一键切换, 中英对照, 中文为主, UNICODE/ANSI编码都支持; 完全免费: 炫语言免费, 调试器免费, IDE绿色版无需安装; 纯文本: 纯文本格式代码, 随意复制粘贴, GIT代码托管, 多人合作开发; PY风格: PY风格代码, 通过代码缩进确定作用域 非 大花括…

B+树索引及其原理

MySQL索引的底层结构是B树&#xff0c;为什么它会选择这个结构&#xff1f;联合索引是怎么实现的&#xff1f;最左侧匹配原则的原理是什么&#xff1f;本文将一一解答这些疑惑。 1 前置知识 在学习B树之前&#xff0c;我们先了解下其他的树形结构&#xff1a;二叉树、平衡二叉…