Cài WordPress trên VPS: Hướng Dẫn LEMP Stack
WordPress chạy trên VPS riêng với LEMP stack mang lại hiệu suất vượt trội so với shared hosting. Bạn kiểm soát toàn bộ môi trường, không bị giới hạn tài nguyên, và có thể tùy chỉnh sâu. Hướng dẫn này giúp bạn cài đặt WordPress trên VPS offshore AnubizHost với Nginx, MySQL và PHP-FPM.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
Cài Đặt LEMP Stack
LEMP stack gồm Linux (Ubuntu), Nginx, MySQL và PHP. Cài đặt từng thành phần:
apt update && apt upgrade -y
# Nginx
apt install -y nginx
# MySQL
apt install -y mysql-server
mysql_secure_installation
# PHP và extensions cần cho WordPress
apt install -y php8.2-fpm php8.2-mysql php8.2-xml php8.2-mbstring php8.2-curl php8.2-zip php8.2-gd php8.2-intl php8.2-bcmathKiểm tra PHP:
php -vTạo Database và User MySQL
Tạo database riêng cho WordPress:
mysql -u root -pTrong MySQL shell:
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;Tải và Cài Đặt WordPress
Tải WordPress và đặt vào thư mục web:
cd /var/www
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress yourdomain.com
chown -R www-data:www-data yourdomain.com
chmod -R 755 yourdomain.comCấu hình wp-config.php:
cd /var/www/yourdomain.com
cp wp-config-sample.php wp-config.php
nano wp-config.phpĐiền thông tin database:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'StrongPassword123!');
define('DB_HOST', 'localhost');Cấu Hình Nginx cho WordPress
Tạo server block Nginx tối ưu cho WordPress:
nano /etc/nginx/sites-available/yourdomain.comserver {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
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/php8.2-fpm.sock;
}
location ~ /.ht {
deny all;
}
location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginxRelated Services
Why Anubiz Host
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.