How to install LAMP server on Debian 10

"LAMP" stack is a collection of open source software, usually installed together to allow the system to deploy dynamic applications. This term describes the Linux operating system, the first letter of the Apache Web server, MariaDB database and PHP programming abbreviations.

Although the "LAMP" stack typically involves a MySQL database management system, but some Linux distributions (such as Debian) using MariaDB MySQL as a substitute.

In this article, we'll show you how to use MariaDB database management system as a LAMP stack installed on Debian 10 servers.

Installed on Debian 10 Apache Web Server

Apache Web server is an open source, powerful, reliable, secure, highly scalable and widely used HTTP server software for hosting Web site.

To install the Apache, use of Debian apt package manager, as shown in FIG.

# apt install apache2

Apache After installation is complete, the installer will immediately trigger systemd system and service manager to start Apache2 service and have it start automatically when the system boots.

To check whether the Apache service is up and running, run the following command systemctl.

# systemctl status apache2

You can also start by using the following command systemctl, stop, restart and acquires the status of the Apache Web server.

# systemctl start apache2.service
# systemctl restart apache2.service
# systemctl stop apache2.service
# systemctl reload apache2.service
# systemctl status apache2.service

If you are already running a firewall, you need to open port 80 (www) and 443 (https) to allow incoming traffic on Apache.

# ufw allow www
# ufw allow https
# ufw status

Now you need to test whether Apache is installed properly and can provide Web pages. Open a Web browser and use the following URL to access Apache Debian default page.

http://SERVER_IP/
或者
http://localhost/

Debian 10 mounted on MariaDB

After the Apache Web server is up and running, you need to install the database system to retain and manage your site's data.

To install MariaDB, please use Debian apt package manager, as shown in FIG.

# apt install mariadb-server

After installing MariaDB, run the following recommended safety script that would delete some unsafe default settings and disable access to the database system.

# mysql_secure_installation

Safety above script will guide you through a series of questions, you can make some changes to MariaDB disposed therein, as shown.

If you want to create a database named "tecmint_wpdb" and called "tecmint_wpuser" and has a database user full privileges, run the following command.

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE tecmint_wpdb;
MariaDB [(none)]> GRANT ALL ON tecmint_wpdb.* TO 'tecmint_wpuser'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;

您可以通过使用用户凭据登录MariaDB来确认新用户是否具有数据库的完全权限,如下所示。

# mysql -u tecmint_wpuser -p
MariaDB [(none)]> SHOW DATABASES;

在Debian 10上安装PHP 7.3

PHP(超文本预处理器)是一种流行的脚本语言,用于构建用于显示Web内容和用户与数据库交互的逻辑。

要安装PHP包,请运行以下命令。

# apt install php libapache2-mod-php php-mysql

如果要安装其他PHP模块,可以使用apt-cache命令和grep命令的组合进行搜索和安装,如图所示。

# apt-cache search php | egrep 'module' | grep default

现在重新加载Apache的配置并使用以下命令检查状态。

# systemctl reload apache2
# systemctl status apache2

在Apache上测试PHP处理

我们将创建一个简单的PHP脚本来验证Apache是否可以处理PHP文件的请求。

# nano /var/www/html/info.php

在文件中添加以下PHP代码。

<?php phpinfo(); ?>

完成后,保存并关闭文件。

现在打开浏览器并键入以下地址,以查看您的Web服务器是否可以显示由此PHP脚本创建的内容。

http://SERVER_IP/info.php
或者
http://localhost/info.php

如果您在Web浏览器中看到上面的页面,那么您的PHP安装正在按预期工作。 此外,此页面显示了有关PHP安装的一些基本详细信息,它对于调试非常有用,但同时它还会显示有关PHP的一些敏感信息。

因此,强烈建议从服务器中删除此文件。

# rm /var/www/html/info.php

结论

在本文中,我们已经解释了如何在Debian 10服务器上安装Linux,Apache,MariaDB和PHP(LAMP)堆栈。 如果您对本文有疑问,请随时在评论部分询问。

via:https://www.tecmint.com/install-lamp-on-debian-10-server/

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159818.htm