阅读量:124
在Debian系统上部署LNMP(Linux, Nginx, MySQL/MariaDB, PHP)环境并运行网站应用,可以按照以下步骤进行:
1. 更新系统
首先,确保你的系统是最新的:
sudo apt update
sudo apt upgrade -y
2. 安装Nginx
sudo apt install nginx -y
安装完成后,启动Nginx并设置开机自启:
sudo systemctl start nginx
sudo systemctl enable nginx
3. 安装MySQL/MariaDB
你可以选择安装MySQL或MariaDB,这里以MariaDB为例:
sudo apt install mariadb-server -y
安装完成后,启动MariaDB并设置开机自启:
sudo systemctl start mariadb
sudo systemctl enable mariadb
运行安全脚本以提高安全性:
sudo mysql_secure_installation
4. 安装PHP
安装PHP及其常用扩展:
sudo apt install php-fpm php-mysql -y
配置PHP-FPM以使用Nginx:
sudo systemctl restart php7.4-fpm
编辑Nginx配置文件以处理PHP请求。打开默认站点配置文件:
sudo nano /etc/nginx/sites-available/default
修改配置文件,添加以下内容:
server {
listen 80;
server_name your_domain_or_ip;
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:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
保存并退出编辑器,然后测试Nginx配置:
sudo nginx -t
如果没有错误,重新加载Nginx:
sudo systemctl reload nginx
5. 配置防火墙