云主机建站详细教程(以阿里云/腾讯云 + WordPress 为例)
1、购买云主机
- 推荐配置(新手):
- CPU:1核
- 内存:2GB
- 系统盘:40GB SSD
- 操作系统:Ubuntu 20.04 或CentOS 7.9
- 购买时注意开放端口:22(SSH)、80(HTTP)、443(HTTPS)
2、域名准备
- 购买域名(阿里云/腾讯云)
- 完成实名认证和备案(国内服务器必须备案)
1、SSH 登录(以 Ubuntu 为例)
ssh root@你的云主机IP # 输入购买时设置的密码
> LNMP = Linux + Nginx + MySQL + PHP
1. 更新系统
sudo apt update && sudo apt upgrade -y # Ubuntu 或 sudo yum update -y # CentOS
2. 安装 Nginx
sudo apt install nginx -y # Ubuntu sudo systemctl start nginx # 启动 sudo systemctl enable nginx # 开机自启
3. 安装 MySQL
sudo apt install mysql-server -y # Ubuntu sudo mysql_secure_installation # 安全设置(设置root密码)
4. 安装 PHP
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip -y sudo systemctl restart php-fpm
1. 创建网站目录
sudo mkdir -p /var/www/your_domain sudo chown -R www-data:www-data /var/www/your_domain # 赋权
2. 配置 Nginx 站点
sudo nano /etc/nginx/sites-available/your_domain.conf
粘贴以下内容(修改your_domain
为你的域名):
server { listen 80; server_name your_domain www.your_domain; root /var/www/your_domain; index index.php index.html; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # PHP版本根据实际修改 } }
启用配置:
sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/ sudo nginx -t # 测试配置 sudo systemctl reload nginx
1. 下载并解压
cd /tmp wget https://wordpress.org/latest.tar.gz tar -zxvf latest.tar.gz sudo mv wordpress/* /var/www/your_domain/
2. 创建数据库
mysql -u root -p
CREATE DATABASE wordpress; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY '你的密码'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
3. 配置 WordPress
cd /var/www/your_domain sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php
修改以下值:
define('DB_NAME', 'wordpress'); define('DB_USER', 'wpuser'); define('DB_PASSWORD', '你的密码'); define('DB_HOST', 'localhost');
1、域名解析
- 在域名控制台添加A记录,指向云主机IP。
2、免费HTTPS(Let's Encrypt)
sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx -d your_domain -d www.your_domain # 按提示操作,自动配置HTTPS
1、访问http://your_domain
或https://your_domain
2、根据WordPress向导完成设置(填写站点标题、管理员账号等)。
403 Forbidden:检查目录权限sudo chown -R www-data:www-data /var/www/your_domain
数据库连接失败:确认MySQL用户权限和配置文件密码。
Nginx 502错误:检查PHP-FPM是否运行sudo systemctl status php-fpm
> ✅ 大功告成!你的网站已上线,可通过域名访问,后续可通过WordPress后台管理内容和安装主题插件。
文章摘自:https://idc.huochengrm.cn/zj/13595.html
评论
昝俊慧
回复这是一份详细的云主机建站教程,包括购买云主机、配置环境、安装WordPress和配置HTTPS等步骤,适合新手学习和参考。