在 Linux 上安装 PHP 的步骤如下:更新系统:sudo apt-get update安装 PHP:sudo apt-get install php验证安装:php -v安装扩展(可选):sudo apt-get install php-mysql配置 PHP(可修改内存限制、上传文件大小等):编辑 "/etc/php/7.4/apache2/php.ini"重启 Apache:sudo systemctl restart apache2

如何在 Linux 安装 PHP
前言
PHP 是一种流行的开源服务器端脚本语言,广泛用于 Web 开发。在 Linux 系统上安装 PHP 非常简单,只需遵循以下步骤即可。
步骤 1:更新系统
<code class="shell">sudo apt-get update</code>
步骤 2:安装 PHP
立即学习“PHP免费学习笔记(深入)”;
<code class="shell">sudo apt-get install php</code>
步骤 3:验证安装
安装完成后,可以通过命令行检查 PHP 版本:
<code class="shell">php -v</code>
步骤 4:安装扩展
根据需要,可以安装其他 PHP 扩展,例如:
<code class="shell">sudo apt-get install php-mysql</code>
步骤 5:配置 PHP
PHP 配置文件通常位于 "/etc/php/7.4/apache2/php.ini"。可以根据需要对其进行编辑,例如更改以下设置:
-
memory_limit:控制 PHP 脚本消耗的内存量 -
upload_max_filesize:指定允许上传的文件的最大大小
步骤 6:重启 Apache
如果对 PHP 配置进行了更改,需要重启 Apache 以使其生效:
<code class="shell">sudo systemctl restart apache2</code>
验证安装
创建包含以下代码的 PHP 文件:
<code class="php"><?php phpinfo(); ?></code>
将此文件保存为例如 "info.php" 并将其移动到 Web 服务器的文档根目录。然后通过浏览器访问此文件(例如 http://localhost/info.php)来查看 PHP 信息。











