在 Debian 上建站一般指配置 Web 服务器 + 网站程序 + 数据库,最常用的是 LNMP / LAMP。下面给你一个从零到可用的完整流程(适合新手,也适用于生产环境)。
sudo apt update && sudo apt upgrade -y
sudo hostnamectl set-hostname webserver
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
浏览器访问:
http://服务器IP
看到 Nginx 欢迎页说明成功 ✅
sudo apt install mariadb-server -y
sudo mysql_secure_installation
sudo mysql -u root -p
CREATE DATABASE webdb;
CREATE USER 'webuser'@'localhost' IDENTIFIED BY '密码';
GRANT ALL PRIVILEGES ON webdb.* TO 'webuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
sudo apt install php php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip -y
php -v
ls /var/run/php/
sudo mkdir -p /var/www/html
sudo nano /etc/nginx/sites-available/web.conf
示例:
server {
listen 80;
server_name 你的域名或IP;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
}
sudo ln -s /etc/nginx/sites-available/web.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
浏览器访问:
http://IP/info.php
✅ 看到 PHP 信息页说明成功
cd /var/www/html
sudo wget https://cn.wordpress.org/latest-zh_CN.tar.gz
sudo tar -xzvf latest-zh_CN.tar.gz
sudo chown -R www-data:www-data wordpress
然后访问:
http://IP/wordpress
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx
sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
| 用途 | 推荐 |
|---|---|
| 静态网站 | Nginx |
| PHP 网站 | LNMP |
| 博客 | WordPress |
| 企业站 | Nginx + PHP |
| 高并发 | Nginx + PHP-FPM |
/var/www 和数据库如果你愿意,我可以:
✅ 给你 宝塔面板一键建站方案
✅ 帮你 部署 WordPress / Typecho / 静态站
✅ 给你 Docker 版 LNMP
✅ 手把手教你 域名 + HTTPS
你现在是 新手 / 生产环境 / 学习用?