Ubuntu下Lighttpd服务器安装,并支持PHP
创始人
2025-01-17 03:02:40
0次

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     

My first PHP page

6、访问WEB

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

sunny@ubuntu:~/www$ curl http://192.168.0.143:8080/     

My first PHP page

Hello World! phpinfo()
......

方法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步的效果

相关内容

热门资讯

每日必看!江岸多玩到底能开挂吗... 每日必看!江岸多玩到底能开挂吗(辅助挂),江岸多玩原来真的有辅助挂讲义1、江岸多玩脚本辅助下载、江岸...
玩家交流!颖河竞技怎么开挂(外... 玩家交流!颖河竞技怎么开挂(外挂),颖河竞技好像是有外挂教材一、颖河竞技游戏安装教程牌型概率发牌机制...
最新通报!皮皮四川麻将软件下载... 最新通报!皮皮四川麻将软件下载(辅助挂),皮皮四川麻将果然有辅助挂模块1、操作简单,无需皮皮四川麻将...
一分钟揭秘!52游戏开挂脚本(... 一分钟揭秘!52游戏开挂脚本(透视挂),52游戏切实有透视挂法子52游戏脚本下载中分为三种模型:52...
一分钟快速了解!堆堆乐开挂破解... 一分钟快速了解!堆堆乐开挂破解(外挂),堆堆乐竟然真的有外挂方针1、下载好堆堆乐正确养号方法之后点击...
重大通报!汇城贵州麻将开挂脚本... 重大通报!汇城贵州麻将开挂脚本(开挂),汇城贵州麻将原来真的有开挂法门1、重大通报!汇城贵州麻将开挂...
盘点一款!七色城透视挂件(外挂... 盘点一款!七色城透视挂件(外挂),七色城切实是真的有外挂经验1、全新机制【七色城ai辅助工具激活码】...
今日头条!多多休闲透视软件下载... 今日头条!多多休闲透视软件下载(外挂),多多休闲确实是真的有外挂攻略1、首先打开多多休闲辅助器下载最...
关于!钱柜麻将真的有透视吗(辅... 关于!钱柜麻将真的有透视吗(辅助器),钱柜麻将一贯是有辅助器练习钱柜麻将能透视中分为三种模型:钱柜麻...
今日焦点!河北家乡棋牌辅助工具... 今日焦点!河北家乡棋牌辅助工具(外挂),河北家乡棋牌果然是有外挂手册小薇(辅助器软件下载)致您一封信...