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

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.mfbz.cn/a/303575.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

DSP2335的时钟PLL配置

PLL模块框图 xclkin是直接进来的外部时钟&#xff1b; 而下面的是振荡器&#xff08;晶振出来&#xff09;的时钟 PLLSTS 锁相环状态寄存器 PLLCR 锁相环控制寄存器 PLLSTS【oscoff】 决定着外部时钟的输入 PLLSTS【plloff】 锁相器关闭位 0使能PLL 锁相环控制寄存器…

day6:进程间的通信

思维导图&#xff1a; 实现多个进程之间的收发信息操作 create.c&#xff1a; #include <head.h> int main(int argc, const char *argv[]) {if(mkfifo("a_send_b",0664)!0){perror("");return -1;}if(mkfifo("b_send_a",0664)!0){perro…

vue3 封装一个按钮组件(可自定义按钮样式)

效果图 鼠标悬浮有对应的文字提示&#xff0c;且图标出现背景色和颜色 实现 目前提供五个固定样式的图标及三个用户自定义的图标&#xff0c;可根据需要补充 组件代码 <script setup lang"ts"> import { onMounted, PropType, reactive, ref, watch } from v…

jupyter内核错误

1、在dos窗口输入以下命令激活环境&#xff1a;anaconda activate 【py环境名&#xff0c;比如py37】&#xff08;目的是新家你一个虚拟环境&#xff09; 2、在虚拟环境py37下安装jupyter notebook&#xff0c;命令&#xff1a;pip install jupyter notebook 3、安装ipykerne…

python24.1.8

嵌套/多条件判断 嵌套 多条件&#xff1a; 实践&#xff1a;

pybind11实现numpy和OpenCV Mat的数据交互

1、编译安装pybind11 下载源代码&#xff1a;https://github.com/pybind/pybind11&#xff0c; 文档&#xff1a;https://pybind11.readthedocs.io/en/stable/compiling.html 解压后进入到命令行&#xff0c;如果有conda环境&#xff0c;就先进入想要的conda环境&#xff0c…

【python入门】day22:机票订购界面、北京地铁1号线运行图

机票订购界面 print(✈国内\t✪国际&#xff0c;港澳台\t↘发现低价) print(----------------------------------) print(航班类型&#xff1a;⊙单程 ⊙往返 ⊙多程&#xff08;含缺口程&#xff09;) print(出发城市&#xff1a;北京) print(到达城市&#xff1a;长春) pri…

OpenHarmony - 基于ArkUI框架实现日历应用

前言 对于刚刚接触OpenHarmony应用开发的开发者&#xff0c;最快的入门方式就是开发一个简单的应用&#xff0c;下面记录了一个日历应用的开发过程&#xff0c;通过日历应用的开发&#xff0c;来熟悉基本图形的绘制&#xff0c;ArkUI的组件的使用&#xff0c;UI组件生命周期&a…

Java集合框架概念详解

目录 1. 什么是Java集合框架&#xff1f;2. 常用接口介绍3. 常用实现类介绍4. 集合框架的应用场景 前言&#xff1a; Java集合框架是Java编程中最重要的工具之一。它提供了一套强大而灵活的数据结构和算法&#xff0c;用于存储和操作数据。本文将详细介绍Java集合框架的概念、常…

前端算法总结

基础–时间复杂度&空间复杂度 什么是复杂度分析 &#xff1f;为什么要进行复杂度分析 &#xff1f;如何进行复杂度分析 &#xff1f; 双指针 最接近的三数之和通过删除字母匹配到字典里最长单词 滑动窗口 滑动窗口的最大值 二叉树 二叉树的最近公共祖先 堆 最小的k个数前 K…

Vant2组件库van-list+Toast下拉加载滚动条回顶问题

目录 List 列表 Toast 轻提示 解决方案 1、不使用 Toast 的 加载提示 2、修改调整 pointer-event 属性值 3、判断是否为第一次加载再使用 背景 &#xff1a; 移动端项目 开发时&#xff0c;有数据长列表展示的场景需求&#xff0c;此时就用到了 Vant2 组件库里面的 <v…

结构型设计模式——外观模式

外观模式 有句话说这个世界就是个草台班子&#xff0c;只不过排面做的好看而已&#xff0c;里面都是一包糠。这句话来形容外观模式非常准确&#xff0c;外观模式又叫门面模式&#xff0c;顾名思义一个系统我不管你里面有多复杂有多少屎山代码&#xff0c;我只要求你提供的接口…

使用JGit拉取代码提示未授权not authorized

原因&#xff1a;2021年8月13日后不支持密码登录&#xff0c;需要使用token验证 调用时候需要先去git仓库创建个人令牌 需要在安全中心创建个人token&#xff0c;使用token名称作为账号&#xff0c;使用token作为密码。 另&#xff1a; Github克隆仓库的三种方式对比&#xff…

Qt连接数据库(内含完整安装包)

遇到问题必须多思考 这里是最全的Qt连接数据库步骤 qt下载地址 链接&#xff1a;https://pan.baidu.com/s/1wdnTfyL9MQlNOCrSmIOxrQ?pwddgqi 提取码&#xff1a;dgqi --来自百度网盘超级会员V1的分享 数据库百度网盘地址 链接&#xff1a;https://pan.baidu.com/s/1orCczey…

Python+Flask+MySQL的图书馆管理系统【附源码,运行简单】

PythonFlaskMySQL的图书馆管理系统【附源码&#xff0c;运行简单】 总览 1、《的图书馆管理系统》1.1 方案设计说明书设计目标需求分析工具列表 2、详细设计2.1 登录2.2 注册2.3 程序主页面2.4 图书新增界面2.5 图书信息修改界面2.6 普通用户界面2.7 其他功能贴图 3、下载 总览…

c++学习:STL库(框架)+字符串模板类string+vector容器+list链表

目录 stl库 常用组件包括 字符串库 字符串模板类string 头文件 最常用的字符串模板类 字符串类型 模板原型 模板的成员数据类型 模板成员函数 有些函数会有重载&#xff0c;可以去下面网址查看std::basic_string - cppreference.comhttps://zh.cppreference.com/w/cp…

探索C语言中的水仙花数及其计算方法

在计算机科学与数学的交叉领域中&#xff0c;有一种特殊的整数被称为“水仙花数”&#xff0c;它是指一个三位数&#xff0c;其各位数字立方和等于该数本身。例如&#xff0c;153是一个典型的水仙花数&#xff0c;因为1 5 3 1 125 27 153。 下面&#xff0c;我们通过一段…

NODE笔记 0

一些简单的node学习笔记记录&#xff0c;是Vue等前端框架的基础 入门学习备忘录 文章目录 前言一、pandas是什么&#xff1f;二、使用步骤 1.引入库2.读入数据总结 前言 node.js 内置网络服务器&#xff0c;是前端框架学习的基础&#xff1a; 概念&#xff1a;…

Pytorch框架学习笔记

官网- PyTorch Tensor 构造随机初始化矩阵 xtorch.rand(5,3) 构造全0矩阵&#xff0c;数据类型为long xtorch.zeros&#xff08;5,3,dtypetorch.long&#xff09; 获取维度信息 x.size(&#xff09; tensor加法 torch.add&#xff08;x&#xff0c;y&#xff09; xy y…

linux常见操作,and一些练习题加线上练习网站,无须配置linux.持续更新中。。。。

文章目录 cd命令相对路径特殊的路径表达符和cd一起使用pwdmore 查看文件内容支持翻页小技巧clear用户&#xff0c;用户权限 and 用户的切换如何创建用户 ls和通配符的使用利用通配符 *grep 过滤管道符 |如何学习Linux在线练习网站 https://www.lanqiao.cn/courses/1 cd命令 cd…