LNMP是指Linux、Nginx、MySQL和PHP的组合,常用于搭建网站服务器。在Debian系统上集成LNMP环境通常涉及以下步骤:
sudo apt update && sudo apt upgrade
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
curl -sL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
echo "deb [signed-by=/usr/share/keyrings/nginx-keys.gpg] http://nginx.org/packages/debian ${lsb_release}-backports main" | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt update
sudo apt install nginx
安装完成后,启动Nginx服务并设置开机自启动:
sudo systemctl start nginx
sudo systemctl enable nginx
sudo apt install mariadb-server
sudo apt-get remove mysql-server
sudo apt-get autoremove
sudo apt-get install mysql-server
安装完成后,启动MySQL/MariaDB并设置开机自启动:
sudo systemctl start mariadb
sudo systemctl enable mariadb
为了安全起见,建议进行数据库的安全加固:
sudo mysql_secure_installation
sudo apt install php-fpm libapache2-mod-php php-mysqlnd php-gd php-curl php-mbstring
注意:根据最新的Debian版本,PHP包名可能会有所不同,例如php7.4-fpm
。
/etc/nginx/sites-available/default
或/etc/nginx/sites-available/example.com.conf
),添加指向PHP的FastCGI代理规则。例如:server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
保存文件后,重启Nginx服务:
sudo systemctl restart nginx
info.php
),放在/var/www/html
目录下:<?php
phpinfo();
?>
保存文件后,在浏览器中访问http://your_server_ip/info.php
,如果看到PHP信息页面,则表示配置成功。
以上步骤概述了在Debian系统上配置LNMP环境的基本流程。根据具体需求,可能还需要进行更多的优化和安全设置。