LEMP套件介绍

🧰LEMP介绍

LEMP代表:

Linux:基础操作系统。
Nginx:高性能Web服务器。
MariaDB:数据管理系统(替代MySQL)。
PHP:服务脚本语言。

LEMP安装步骤
步骤1:通过SSH登录服务

使用root权限通过SSH访问服务VPS:

bash
ssh root@your_server_ip

步骤2:更新系统

安装之前,更新系统确保所有软件最新的:

bash
apt update && apt upgrade –y

步骤3:安装Nginx

安装Nginx Web服务器:

bash
apt install nginx –y

启动检查Nginx状态:

bash
systemctl start nginx
systemctl enable nginx
systemctl status nginx

打开浏览访问 http://your_server_ip,即可查看默认Nginx面。

步骤4:安装MariaDB

安装MariaDB数据系统:

bash
apt install mariadb-server mariadb-client –y

启动检查MariaDB状态:

bash
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb

执行MariaDB安全设置:

bash
mysql_secure_installation

根据提示设置root密码进行安全配置。

步骤5:安装PHP必要

安装PHPNginx配合所需块:

bash
apt install php8.1 php8.1-fpm php8.1-mysql php8.1-cli php8.1-curl php8.1-mbstring php8.1-xml php8.1-zip –y

启动检查PHP-FPM状态:

bash
systemctl start php8.1-fpm
systemctl enable php8.1-fpm
systemctl status php8.1-fpm

步骤6:配置Nginx处理PHP

创建编辑Nginx配置文件处理PHP文件,例如:

bash
nano /etc/nginx/sites-available/default

添加编辑以下内容:

nginx
server {
listen 80;
server_name your_domain.com;
root /var/www/wordpress;

index index.php index.html;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}

location ~* .(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}

location ~ /.ht {
deny all;
}
}

保存退出后,测试并重Nginx:

bash
nginx –t
systemctl restart nginx

步骤7:安装phpMyAdmin(选)

如果你想使用图形界面管理数据库,可以安装phpMyAdmin:

bash
apt install phpmyadmin –y

安装过程选择Nginx作为Web服务器,提示完成数据配置。

安装完成后,创建符号phpMyAdminNginx兼容:

bash
ln –s /usr/share/phpmyadmin /var/www/html/phpmyadmin

现在可以通过 http://your_server_ip/phpmyadmin 访问phpMyAdmin。

测试PHP是否正常工作

创建info.php文件测试PHP功能:

bash
echo “<?php phpinfo(); ?>” > /var/www/html/info.php

访问 http://your_server_ip/info.php 查看PHP配置信息。