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

2024-01-09 09:44

本文主要是介绍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/Linuxsunny@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:25sunny@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 Technologieswith 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                 = 8080index-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 8080root@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 lighttpdroot@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/wwwsunny@ubuntu:~/www$ mkdir lighttpd
sunny@ubuntu:~/www$ touch lighttpd/error.logsunny@ubuntu:~/www$ chmod  777  lighttpd
sunny@ubuntu:~/www$ chmod  777  lighttpd/error.logsunny@ubuntu:~/www$ tree ./
./
├── index.php
└── lighttpd├── error.log└── uploads2 directories, 2 filessunny@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=1sudo 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 php4、使能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 changes5、重启lighttpd
sudo /etc/init.d/lighttpd stop
sudo /etc/init.d/lighttpd start6、便能看到第6步的效果

这篇关于Ubuntu下Lighttpd服务器安装,并支持PHP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/586696

相关文章

如何解决mmcv无法安装或安装之后报错问题

《如何解决mmcv无法安装或安装之后报错问题》:本文主要介绍如何解决mmcv无法安装或安装之后报错问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mmcv无法安装或安装之后报错问题1.当我们运行YOwww.chinasem.cnLO时遇到2.找到下图所示这里3.

Python 安装和配置flask, flask_cors的图文教程

《Python安装和配置flask,flask_cors的图文教程》:本文主要介绍Python安装和配置flask,flask_cors的图文教程,本文通过图文并茂的形式给大家介绍的非常详细,... 目录一.python安装:二,配置环境变量,三:检查Python安装和环境变量,四:安装flask和flas

基于Python打造一个可视化FTP服务器

《基于Python打造一个可视化FTP服务器》在日常办公和团队协作中,文件共享是一个不可或缺的需求,所以本文将使用Python+Tkinter+pyftpdlib开发一款可视化FTP服务器,有需要的小... 目录1. 概述2. 功能介绍3. 如何使用4. 代码解析5. 运行效果6.相关源码7. 总结与展望1

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.

Win11安装PostgreSQL数据库的两种方式详细步骤

《Win11安装PostgreSQL数据库的两种方式详细步骤》PostgreSQL是备受业界青睐的关系型数据库,尤其是在地理空间和移动领域,:本文主要介绍Win11安装PostgreSQL数据库的... 目录一、exe文件安装 (推荐)下载安装包1. 选择操作系统2. 跳转到EDB(PostgreSQL 的

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

SpringKafka消息发布之KafkaTemplate与事务支持功能

《SpringKafka消息发布之KafkaTemplate与事务支持功能》通过本文介绍的基本用法、序列化选项、事务支持、错误处理和性能优化技术,开发者可以构建高效可靠的Kafka消息发布系统,事务支... 目录引言一、KafkaTemplate基础二、消息序列化三、事务支持机制四、错误处理与重试五、性能优