在不使用宝塔面板的情况下,手动部署WordPress网站需要一定的技术基础,但能提供更高的灵活性和控制权。以下是详细步骤:
1. 准备服务器环境
- 操作系统:推荐使用Ubuntu 20.04/22.04或CentOS 7/8。
- SSH登录:通过终端连接服务器(如
ssh root@your_server_ip)。
2. 安装必要软件
A. 安装Web服务器(Nginx/Apache)
-
Nginx(高性能,推荐):
# Ubuntu/Debian sudo apt update sudo apt install nginx -y # CentOS sudo yum install epel-release -y sudo yum install nginx -y sudo systemctl start nginx sudo systemctl enable nginx -
Apache(传统选择):
# Ubuntu/Debian sudo apt install apache2 -y # CentOS sudo yum install httpd -y sudo systemctl start httpd sudo systemctl enable httpd
B. 安装数据库(MySQL/MariaDB)
# Ubuntu/Debian
sudo apt install mariadb-server mariadb-client -y
# CentOS
sudo yum install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
- 安全配置:
sudo mysql_secure_installation按提示设置root密码并移除匿名用户、测试数据库等。
C. 安装PHP
WordPress需要PHP 7.4或更高版本:
# Ubuntu/Debian
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip php-opcache -y
# CentOS
sudo yum install epel-release -y
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum-config-manager --enable remi-php74
sudo yum install php php-mysqlnd php-fpm php-gd php-mbstring -y
3. 配置数据库
- 登录MySQL:
sudo mysql -u root -p - 创建WordPress数据库和用户:
CREATE DATABASE wordpress; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_strong_password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
4. 下载并配置WordPress
- 下载最新版WordPress:
cd /tmp wget https://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gz sudo mv wordpress /var/www/html/ - 设置权限:
sudo chown -R www-data:www-data /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress
5. 配置Web服务器
Nginx配置
- 创建虚拟主机配置文件:
sudo nano /etc/nginx/conf.d/wordpress.conf -
粘贴以下内容(替换
your_domain.com):server { listen 80; server_name your_domain.com www.your_domain.com; root /var/www/html/wordpress; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } - 测试并重启Nginx:
sudo nginx -t sudo systemctl restart nginx
Apache配置
- 启用必要模块:
sudo a2enmod rewrite - 编辑虚拟主机文件:
sudo nano /etc/apache2/sites-available/wordpress.conf - 粘贴以下内容:
<VirtualHost *:80> ServerName your_domain.com DocumentRoot /var/www/html/wordpress <Directory /var/www/html/wordpress> AllowOverride All </Directory> </VirtualHost> - 启用配置并重启Apache:
sudo a2ensite wordpress.conf sudo systemctl restart apache2
6. 完成WordPress安装
- 访问
http://your_server_ip或域名。 - 按提示填写数据库信息(数据库名、用户名、密码等)。
- 设置网站标题、管理员账号和密码。
7. 其他优化(可选)
- SSL证书:使用Let’s Encrypt免费证书:
sudo apt install certbot python3-certbot-nginx -y # Nginx sudo certbot --nginx -d your_domain.com - 防火墙:开放HTTP/HTTPS端口:
sudo ufw allow 80/tcp sudo ufw allow 443/tcp
常见问题排查
- 403 Forbidden:检查目录权限和所有者(应为
www-data或apache)。 - 数据库连接错误:确认数据库名、用户名、密码是否正确,以及MySQL是否允许本地连接。
- PHP不解析:确保PHP-FPM已启动且Web服务器配置正确。
通过以上步骤,你可以完全手动部署WordPress,无需依赖宝塔面板。这种方式适合学习服务器管理或需要深度定制的用户。
云服务器