如何配置现有的 Apache 2 服务器以使用 PHP?

How to configure existing Apache 2 server to use PHP?

互联网上有很多帖子解释如何配置 LAMP 环境,但很少有文章描述如何配置现有 Apache 服务器以使用 PHP,考虑到 Apache已经安装在另一个位置,然后是默认位置。

我在安装了 Apache 但未配置 PHP 模块的 AWS Lightsail Node.js 堆栈中遇到的这种情况。

有谁知道如何配置现有的 Apache 安装以使用 PHP?

经过一些研究,我发现了进行配置的必要步骤(Ubuntu):

  1. 运行 sudo apt-get update 获取最新的可用软件包列表
  2. 通过运行安装 PHP:
sudo apt-get install php libapache2-mod-php
  1. 运行 sudo find / -name libphp* 获取 libphpX.X.so 文件的位置
  2. libphpX.X.so 文件复制到 Apache modules 文件夹中
  3. 打开 Apache httpd.conf 文件并在末尾添加以下行:
<FilesMatch \.php$>
    ​SetHandler application/x-httpd-php
​</FilesMatch>
  1. 重新启动 apache 服务器