关于兰普
LAMP 堆栈是一组用于启动和运行 Web 服务器的开源软件。该缩写词代表 Linux、Apache、MySQL 和 PHP。 Arch Linux 使用功能强大的 Pacman 安装程序,只需一个命令即可下载每个程序所需的所有最新软件包。
Set Up
本教程中的步骤要求用户具有 root 权限。您可以查看如何设置here在步骤 3 和 4 中。
第一步——安装 Apache
Apache 是一款免费开源软件,运行着全球 50% 以上的 Web 服务器。
在安装任何 LAMP 程序之前,我们应该更新包管理器:
sudo pacman -Syu
更新完成后,我们就可以安装Apache了:
sudo pacman -S apache
安装 Apache 后,我们需要对配置进行一些更改。
打开apache配置文件:
sudo nano /etc/httpd/conf/httpd.conf
注释掉unique_id_module(可以使用ctrl w快速找到它):
#LoadModule unique_id_module modules/mod_unique_id.so
重新启动阿帕奇:
sudo systemctl restart httpd
在 apache 重新启动期间,您可能会收到一条通知,内容如下:
httpd: apr_sockaddr_info_get() failed for droplet1
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[DONE]
尽管此警报不会干扰 apache 启动,但如果您愿意,可以通过将主机名添加到配置中来轻松消除它。
打开主机文件:
sudo nano /etc/hosts
将您的主机名添加到以 127.0.0.1 开头的行末尾:
127.0.0.1 localhost.localdomain localhost droplet1
随后重新启动 Apache 将不再显示该消息。
这样,Apache 现已安装在您的服务器上。将浏览器定向到服务器的 IP 地址 (http://12.34.56.789) 将显示自动索引目录。
您可以通过将index.html文件添加到Arch的文档根目录(位于“srv/http”中)来快速尝试示例页面:
sudo nano /srv/http/index.html
<html>
<title>Welcome</title>
<body>
<h2>Hello, Welcome to Arch</h2>
</body>
</html>
您可以通过在浏览器中转到服务器的 IP 地址来访问占位符页面。
如何查找服务器的 IP 地址
您可以运行以下命令来显示服务器的 IP 地址。
curl -s icanhazip.com
第二步——安装MySQL
MySQL 是一个功能强大的数据库管理系统,用于组织和检索数据。
自2013年3月以来,MariaDB 已成为 Arch 存储库中 MySQL 的默认实现。安装“mysql”包将自动放入 MariaDB 作为替换。更多详情请参阅原始公告。
要安装 MySQL,请打开终端并输入以下命令:
sudo pacman -S mysql
如果它询问您任何问题,请按 Enter 键,除非您知道不需要默认值。
安装MySQL后,启动它运行
sudo systemctl start mysqld
通过运行 MySQL 设置脚本完成:
sudo mysql_secure_installation
该过程将询问您当前的 MySQL root 密码(不要与您的服务器密码混淆),并且由于尚未设置,因此只需按 Enter 键即可。
出现提示时,“设置 root 密码?”输入 Y,然后输入新的 MySQL root 密码。
之后,最简单的方法就是对所有选项都说“是”。最后,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...
安装完 MySQL 后,通过安装 PHP 来完成 LAMP 堆栈。
第三步——安装 PHP
PHP 是一种开源 Web 脚本语言,广泛用于构建动态网页。
要安装 PHP,请打开终端并输入此命令。
sudo pacman -S php php-apache
PHP 还应该添加到 apache 配置文件中:
sudo nano /etc/httpd/conf/httpd.conf
将此文本块粘贴到配置中。
# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
Include conf/extra/php5_module.conf
第四步 — 查看您的 PHP 配置并将程序添加到启动中
LAMP完全安装后,我们可以通过创建一个快速的php信息页面来查看PHP详细信息
要进行设置,首先创建一个新的空白文件:
sudo nano /srv/http/info.php
添加以下行:
<?php
phpinfo();
?>
然后保存并退出。
重新启动 apache 以使所有更改生效:
sudo systemctl restart httpd
访问您的 php 信息页面(确保将示例 IP 地址替换为正确的 IP 地址):http://12.34.56.789/info.php
您的屏幕应该如下所示:
要结束 LAMP 安装,请打开 Arch 的 initscripts 的配置文件,并将 apache 服务器和 MySQL 守护进程添加到服务器启动时运行的程序列表中:
sudo systemctl enable mysqld httpd
恭喜,您现在已经在 Arch Linux 上安装了 LAMP 服务器!
See More
安装 LAMP 后,您就有了构建站点的良好基础。
查看本教程以了解如何安装Arch 上的 WordPress
埃特尔·斯维尔德洛夫