如何在 Manjaro 20 上安装 LAMP

[ad_1]

在本教程中,我们将向您展示如何在 Manjaro 20 上安装 LAMP。对于那些不知道的人, 代表Linux, Apache、MySQL/MariaDB 和 PHP 或 Perl 或 Python。 所有组件都是免费的开源软件,组合适合构建动态网页。 LAMP 堆栈是世界上最流行的服务器配置之一。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Manjaro 20 上逐步安装 LAMP Stack(尼比亚)。

在 Manjaro 20 Nibia 上安装 LAMP

步骤 1. 在运行以下教程之前,请确保我们的系统是最新的:

sudo pacman -Syu

步骤 2. 安装 Apache.

让我们安装 Apache 使用以下命令的网络服务器:

sudo pacman -S apache

安装完成后,打开 Apache 存在于的配置文件 /etc/httpd/conf/httpd.conf,搜索并评论以下行:
# LoadModule unique_id_module modules/mod_unique_id.so

我们现在可以使用以下命令启用和启动 apache 服务器:

sudo systemctl enable httpd
sudo systemctl restart httpd

步骤 3. 安装 MySQL。

运行以下命令在 Manjaro 上安装 MySQL 服务器:

sudo pacman -S mysql

完成后,首先使用以下命令初始化 MySQL 数据目录:

sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

接下来,使用以下命令启用并启动它:

sudo systemctl enable mysqld
sudo systemctl restart mysqld

默认情况下,MySQL 未加固。 您可以使用 mysql_secure_installation 脚本。 您应该仔细阅读下面的每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MySQL:

$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

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

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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, MariaDB 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...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

步骤 4. 安装 PHP。

安装 PHP 和 PHP Apache Manjaro 中的模块,只需使用 pacman 命令:

sudo pacman -S php php-apache

安装后,我们需要配置PHP。 编辑文件: /etc/httpd/conf/httpd.conf:

sudo nano /etc/httpd/conf/httpd.conf

找到以下行并对其进行评论:

#LoadModule mpm_event_module modules/mod_mpm_event.so

此外,取消注释或添加以下行:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

然后,在配置文件的底部添加以下行:

LoadModule php7_module modules/libphp7.so
AddHandler php7-script php
Include conf/extra/php7_module.conf

现在保存文件并退出。 重新启动 apache 服务器以确保正确加载所有配置:

sudo systemctl restart httpd

要测试 PHP 安装,请在以下位置创建一个文件 /srv/http/phpinfo.php 并编写以下 PHP 代码:

<?php
phpinfo();
?>

现在通过访问在浏览器中打开此文件 localhost/phptest.php 并检查 Apache 具有最新 PHP 版本的服务器已安装在您的 Manjaro Linux 上。

恭喜! 您已成功安装 LAMP 服务器。 感谢您使用本教程安装 LAMP (Apache, 玛丽亚数据库, 和 PHP) 在 Manjaro 20 系统中。 如需更多帮助或有用信息,我们建议您查看官方 Apache、MariaDB 和 PHP 网站。

[ad_2]

Related Posts