如何在 Debian 上安装 Linux、Apache、MySQL、PHP (LAMP)如何在 Debian 上安装 Linux、Apache、MySQL、PHP (LAMP)如何在 Debian 上安装 Linux、Apache、MySQL、PHP (LAMP)如何在 Debian 上安装 Linux、Apache、MySQL、PHP (LAMP)
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Debian 上安装 Linux、Apache、MySQL、PHP (LAMP)

关于灯

LAMP 堆栈是一组用于启动和运行 Web 服务器的开源软件。首字母缩写词代表 Linux、Apache、MySQL 和 PHP。由于虚拟专用服务器已经在运行 Debian,因此 linux 部分已得到处理。这是安装其余部分的方法。

设置

在执行本教程的步骤之前,请确保您的所有存储库都是最新的:

apt-get update

完成后,继续并开始安装 LAMP 服务器。

第一步——安装 Apache

Apache 是一种免费的开源软件,运行着全球 50% 以上的 Web 服务器。

要安装 apache,请打开终端并输入以下命令:

apt-get install apache2

就是这样。要检查您的 VPS 上是否安装了 Apache,请将浏览器指向服务器的 IP 地址(例如 http://12.34.56.789)。该页面应该像这样显示“It works!”字样。

如何查找服务器的 IP 地址

您可以运行以下命令来显示您的 VPS 的 IP 地址。

ifconfig eth0 | grep inet | awk '{ print $2 }'

第二步——安装 MySQL

MySQL 是一种广泛部署的数据库管理系统,用于组织和检索数据。

要安装 MySQL,请打开终端并输入以下命令:

apt-get install mysql-server

在安装过程中,MySQL 会要求您设置 root 密码。如果您错过了在安装程序时设置密码的机会,稍后可以很容易地从 MySQL shell 中设置密码。

通过运行 MySQL 设置脚本完成:

 mysql_secure_installation

提示将询问您当前的 root 密码。

输入它。

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

然后提示会问你是否要更改root密码。继续并选择 N 并继续执行下一步。

对所有选项都说“是”是最简单的。最后,MySQL 将重新加载并实施新的更改。

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                                            
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

完成后,您可以通过在虚拟服务器上安装 PHP 来完成。

第三步——安装 PHP

PHP 是一种开源网络脚本语言,广泛用于构建动态网页。

要安装 PHP,请打开终端并输入此命令。注意:如果您使用的是 Debian 7 之前的版本,请同时包含 php5-suhosin。

 apt-get install php5 php-pear php5-mysql

在您两次对提示回答“是”后,PHP 将自行安装。

通过重新启动 apache 完成:

service apache2 restart

恭喜!现在你的 Droplet 上有了 LAMP 堆栈!

第四步——结果:查看服务器上的 PHP

虽然安装了 LAMP,但我们仍然可以通过创建一个快速的 php 信息页面来在线查看组件

要设置它,首先创建一个新文件:

 nano /var/www/info.php

添加以下行:

<?php
phpinfo();
?>

然后保存退出。

最后访问您的 php 信息页面(确保将示例 IP 地址替换为正确的 IP 地址):http://12.34.56.789/info.php

它应该看起来像这样:

©2015-2025 艾丽卡 support@alaica.com