search
HomeComputer TutorialsComputer KnowledgeHow to quickly set up a LAMP environment on Debian 12

How to quickly set up a LAMP environment on Debian 12

Feb 20, 2024 pm 12:39 PM
serverdebianLinux operating systemlamp

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:每日运维. If there is any infringement, please contact admin@php.cn delete
Download Hidester VPN/Proxy to Access Your Favorite Content - MiniToolDownload Hidester VPN/Proxy to Access Your Favorite Content - MiniToolApr 22, 2025 am 12:50 AM

Learn about Hidester VPN and Hidester proxy and download Hidester VPN for Windows, Mac, Android, and iOS to use this VPN service to view websites with no limit. For more useful free computer tools and troubleshooting tips, you may visit php.cn Softwa

Windows Keyboard Opening Shortcuts Instead of Typing [Fixed]Windows Keyboard Opening Shortcuts Instead of Typing [Fixed]Apr 22, 2025 am 12:48 AM

Have you ever encountered the trouble of “Windows keyboard opening shortcuts instead of typing”? In this post from php.cn, you will learn how to fix this issue.

Easy Ways to Add the Control Panel Icon to Desktop on Win 10 / 11Easy Ways to Add the Control Panel Icon to Desktop on Win 10 / 11Apr 22, 2025 am 12:46 AM

In this post, php.cn Software will introduce what Control Panel is and how to add the Control Panel icon to desktop on your Windows 10 or Windows 11 computer. You can also learn some related information about desktop icon settings.

Granblue Fantasy Relink Save File Location & Backup Save DataGranblue Fantasy Relink Save File Location & Backup Save DataApr 22, 2025 am 12:45 AM

If you play Granblue Fantasy: Relink on your PC, you may wonder where you can find its save file. In this post, php.cn introduces everything you want to know - Granblue Fantasy Relink save file location and how to back up the savegame of this game.

How to Fix Event ID 1104: The Security Log Is Now Full? - MiniToolHow to Fix Event ID 1104: The Security Log Is Now Full? - MiniToolApr 22, 2025 am 12:44 AM

Event Viewer keeps track of activity for better management. However, if the upper limit of the security log is reached, no more events can be logged. In this post on php.cn Website, we will show you how to deal with Event ID 1104 the security log is

Watch: How to Enable Secure Boot on Gigabyte Motherboard?Watch: How to Enable Secure Boot on Gigabyte Motherboard?Apr 22, 2025 am 12:43 AM

Secure Boot is a security standard that can prevent your computer from booting with untrustworthy software. Enabling it will add an extra layer of security to your device. In this post from php.cn Website, we will show you how to enable Secure Boot o

Windows 11 23H2 Release Date: September 26, 2023 - MiniToolWindows 11 23H2 Release Date: September 26, 2023 - MiniToolApr 22, 2025 am 12:42 AM

Coming to a new year, what Windows 11 users are looking forward to are not only the patch updates but also the annual major update for Windows 11. This post will talk about the Windows 11 23H2 release date. In addition, if you want to recover deleted

How to Turn off Bixby on Samsung Phone? See a Guide! - MiniToolHow to Turn off Bixby on Samsung Phone? See a Guide! - MiniToolApr 22, 2025 am 12:41 AM

Can you completely disable Bixby? How to turn off Bixby on Samsung phones? It is not hard to disable this voice assistant. In this post from php.cn, we will go to any length to help you find the method. Besides, a way to turn off “Hi, Bixby” is also

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor