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:
Before starting this tutorial, you may need a server with Debian 12 installed:
Students who do not have a server can buy it here in China, and VPS servers abroad can buy it here.
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:
Browser inputhttp://localhost
displays the apache information page by default.
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".
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:
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"
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"
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:
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!