在Debian上配置LNMP(Linux, Nginx, MySQL/MariaDB, PHP)虛擬主機的步驟如下:
sudo apt update
sudo apt install nginx
sudo apt update
sudo apt install mysql-server
或者安裝MariaDB:
sudo apt update
sudo apt install mariadb-server
sudo apt update
sudo apt install php-fpm php-mysql
運行以下命令以安全地配置數據庫:
sudo mysql_secure_installation
按照提示設置root密碼,刪除匿名用戶,禁止遠程root登錄等。
登錄到MySQL/MariaDB:
sudo mysql -u root -p
創建數據庫和用戶,并授權:
CREATE DATABASE your_database_name;
CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
創建一個新的Nginx配置文件:
sudo nano /etc/nginx/sites-available/your_domain.conf
添加以下內容,根據需要進行修改:
server {
listen 80;
server_name your_domain.com www.your_domain.com;
root /var/www/your_domain;
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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
保存并退出。
sudo mkdir -p /var/www/your_domain
sudo chown -R www-data:www-data /var/www/your_domain
創建一個符號鏈接以啟用配置:
sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
編輯PHP-FPM配置文件:
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
找到listen行,將其更改為:
listen = /var/run/php/php7.4-fpm.sock
保存并退出。
sudo systemctl restart php7.4-fpm
現在,您已經在Debian上配置了LNMP虛擬主機。請確保您的域名已解析到服務器IP地址,并在DNS提供商處更新DNS設置。