🧰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及必要模块
安装PHP及与Nginx配合所需的模块:
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服务器,并按提示完成数据库配置。
安装完成后,创建符号链接让phpMyAdmin与Nginx兼容:
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配置信息。