在 Linux 上启动 PHP 的步骤包括:1. 安装 PHP;2. 启动 Apache 并启用 PHP 模块;3. 创建 PHP 文件;4. 访问 PHP 文件。

如何在 Linux 启动 PHP
PHP 是一种广泛使用的服务器端脚本语言,用于创建动态网站和应用程序。在 Linux 系统上启动 PHP 的步骤如下:
1. 安装 PHP
-
使用包管理器安装 PHP:
立即学习“PHP免费学习笔记(深入)”;
<code>sudo apt-get update sudo apt-get install php</code>
-
或者,从 PHP 官网下载源码并编译:
<code>wget https://www.php.net/distributions/php-7.4.11.tar.gz tar -xzvf php-7.4.11.tar.gz cd php-7.4.11 ./configure make && make install</code>
2. 启动 Apache 并启用 PHP 模块
-
确保 Apache 已安装:
<code>sudo apt-get install apache2</code>
-
启用 PHP 模块:
<code>sudo a2enmod php7.4 sudo service apache2 restart</code>
3. 创建 PHP 文件
-
创建一个名为
index.php的 PHP 文件,并添加以下代码:<code class="php"><?php echo "PHP 已成功启动!"; ?></code>
-
将文件保存到 Apache 的根目录(通常为
/var/www/html):<code>sudo cp index.php /var/www/html/</code>
4. 访问 PHP 文件
-
在浏览器中打开服务器 IP 地址或域名,后跟
/index.php:<code>http://localhost/index.php</code>
如果一切设置正确,你应该会看到 "PHP 已成功启动!" 消息。











