Home  >  Article  >  Computer Tutorials  >  How to quickly set up a LAMP environment on Debian 12

How to quickly set up a LAMP environment on Debian 12

王林
王林forward
2024-02-20 12:39:27458browse

LAMP refers to the abbreviation consisting of the first letters of the names of four open source components, often used to support web programs developed using PHP. When purchasing a VPS server, whether it is Alibaba Cloud ECS or VULTR VPS server, if you plan to install a Debian system and configure a LAMP environment, this article will provide you with some help.

Let’s introduce the specific meaning of LAMP in detail:

  • L – Linux operating system
  • A – Apache is the world’s most popular HTTP web server
  • M – MySQL or MariaDB relational database management system
  • P – PHP Programming Language

before the start

Before starting this tutorial, you may need a server with Debian 12 installed:

  • At least 1GB of RAM
  • Non-root users with sudo permissions (of course root users can also be used, but security considerations are not recommended)

Students who do not have a server can buy it here in China, and VPS servers abroad can buy it here.

Step 1. Install Apache

Apache is available in the default Debian 12 repositories. Installation is very simple, run the following command:

sudo apt update

sudo apt install apache2

After the installation is completed, the apache2 service runs automatically by default and can be viewed through the following command:

sudo systemctl status apache2

After the command is executed, you will see something similar to the following:

如何快速在 Debian 12 上搭建 LAMP 环境

Browser inputhttp://localhost displays the apache information page by default.

如何快速在 Debian 12 上搭建 LAMP 环境

Apache service start and stop commands:

sudo systemctl start apache2 //Start

sudo systemctl stop apache2 //Stop

Please refer to "How to install Apache on Debian 12".

Step 2. Install MariaDB / MySQL

The Debian 12 software source does not include the MySQL software package, which has been replaced by MariaDB. MariaDB is fully compatible with MySQL.

If you want to install MySql, you can check "How to install MySQL on Debian 12"

The following commands take the installation of MariaDB as an example:

sudo apt update

sudo apt install mariadb-server

After the installation is completed, the MariaDB service will automatically start and can be viewed through the following command.

sudo systemctl status mariadb

If it runs normally, you will see output similar to the following:

如何快速在 Debian 12 上搭建 LAMP 环境

Execute the following command to strengthen MariaDB database security according to the prompts.

sudo mysql_secure_installation

After the

command is executed, you will get a prompt in the terminal. Basically, you can enter y all the way.

For improved security, it is recommended to keep the default authentication plugin and allow the root user to authenticate only through Unix sockets.

If you want to change root authentication to classic authentication, you can do the following on the server:

sudo mysql

Then execute the following SQL.

ALTER USER ‘root’@’localhost’ IDENTIFIED VIA mysql_native_password;

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘your_root_passwd’;

Hereyour_root_passwd is the root account password you set. After the above settings are completed, you can log in in the terminal through the following command.

mysql -u root -p

For more information, please refer to "How to install MariaDB on Debian 12"

Step 3. Install and configure PHP

The default installed php in Debian 12 environment is 8.2.

sudo apt update

sudo apt install php libapache2-mod-php php-mysql php-fpm

Note: By default, php is installed with the latest version php8.2 in the Debian 12 software repository. If you need to install a specific version of PHP, you can do the following:

sudo apt install php[version]

For example, if you install version 7.3 of php, the command is as follows:

sudo apt install php7.3

Of course, the corresponding module also needs to specify the version, such as php7.3-mysql. Generally, the following modules are commonly used:

php7.3-cli

php7.3-common

php7.3-curl

php7.3-gd

php7.3-json

php7.3-mbstring

php7.3-mysql

php7.3-xml

php7.3-fpm

For more information, please refer to "How to install PHP on Debian 12"

Step 4. Visit LAMP

After the above three steps, we have installed Apache, MariaDB/MySQL, and PHP. Now we can add site content to access static files or php files.

First, enter the apache default site directory through the cd command.

cd /var/www/html

Secondly, create the info.php file through the touch command and edit the file using vi/vim.

sudo touch info.php

sudo vi info.php

Press the i key to enter editing mode and enter the following content

Press Esc, enter :wq, press Enter to save the file and return.

Finally, enter http://localhost/info.php in your local browser, you will see the following content:

如何快速在 Debian 12 上搭建 LAMP 环境

Write at the end

This tutorial has shown you how to set up a LAMP environment on Debian 12. If possible, I recommend you try it on your own Debian server.

The above is the detailed content of How to quickly set up a LAMP environment on Debian 12. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete