3

如何在Raspberry Pi安装Apache Web服务器

 1 year ago
source link: https://www.myfreax.com/how-to-install-apache-on-raspberry-pi/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何在Raspberry Pi安装Apache Web服务器

Apache HTTP服务器是世界上最受欢迎的Web服务器之一。它是一个开放源代码和跨平台的HTTP服务器

Updated At 17 Sep 2022

2 min read

By myfreax
如何在Raspberry Pi安装Apache Web服务器

Apache HTTP服务器是世界上最受欢迎的Web服务器之一。它是一个开放源代码和跨平台的HTTP服务器。

为Internet的很大一部分网站提供支持。Apache提供了许多强大的功能,可以通过其他模块进行扩展。

在本教程中,我们将说明如何在Raspberry Pi上安装Apache Web服务器。我们假设您在Raspberry Pi 安装Raspbian

Apache在默认的Raspbian存储库中可用,安装非常简单。首先运行命令sudo apt update更新软件包索引。

然后运行命令sudo apt install apache2来安装apache2软件包。至此您在Raspberry Pi上安装了Apache Web服务器。

要验证一切正常,请打开浏览器,键入Raspberry Pi IP地址http://PI_IP,您将看到默认的Apache欢迎页面。

欢迎页面包含有关Apache配置文件,帮助程序脚本和目录位置的一些基本信息。默认的Apache网页名为index.html,它存储在/var/www/html目录中。

如果要修改此页面,则需要以root或者具有sudo权限的用户的编辑文件。您也可以删除文件并添加自己的HTML文件。

Apache日志文件access.logerror.log位于/var/log/apache目录中。如果您遇到任何问题,日志文件可以帮助你排除故障。

sudo apt update 
sudo apt install apache2

如果您想在Raspberry Pi上提供动态PHP文件,则需要安装PHP和PHP Apache模块。当安装php软件包后,你需要重新启动Apache服务,启用PHP模块。

要测试是否已正确配置Apache Web服务器解释PHP代码,请使用以下代码在/var/www/html目录中创建一个名为info.php的新文件。

保存文件,打开您选择的浏览器,然后访问http://PI_IP/info.php。此页面将显示PHP配置的信息。

sudo apt install php libapache2-mod-php
sudo systemctl restart apache2

sudo vim /var/www/html/info.php
<?php

phpinfo();

您已成功在Raspberry Pi板上安装Apache和PHP。您现在可以开始将Apache用作Web或代理服务器。

如果您有任何疑问或反馈,请随时发表评论。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK