Skip to content

Instantly share code, notes, and snippets.

@bangbuiduc
Created January 5, 2026 03:08
Show Gist options
  • Select an option

  • Save bangbuiduc/f085a73bdf1fd98cc059482dfe4f1a22 to your computer and use it in GitHub Desktop.

Select an option

Save bangbuiduc/f085a73bdf1fd98cc059482dfe4f1a22 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 1. Chặn các popup tương tác và cấu hình tự động restart dịch vụ
export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_MODE=a
# Kiểm tra quyền root
if [[ $EUID -ne 0 ]]; then
echo "Vui lòng chạy với quyền sudo."
exit 1
fi
# Hàm kiểm tra xem một gói đã cài đặt chưa
is_installed() {
dpkg -s "$1" >/dev/null 2>&1
}
echo "--- 1. Cập nhật hệ thống & Thêm các kho lưu trữ ---"
apt update && apt upgrade -y
# Các gói cơ bản
PACKAGES=(software-properties-common ca-certificates lsb-release apt-transport-https curl gnupg2)
for pkg in "${PACKAGES[@]}"; do
if ! is_installed "$pkg"; then
apt install -y "$pkg"
else
echo ">> $pkg đã được cài đặt, bỏ qua."
fi
done
# Thêm PPA PHP
if [ ! -f /etc/apt/sources.list.d/ondrej-ubuntu-php-*.list ]; then
add-apt-repository ppa:ondrej/php -y
apt update
fi
echo "--- 2. Cài đặt Nginx ---"
if ! is_installed "nginx"; then
apt install -y nginx
systemctl enable nginx
systemctl start nginx
else
echo ">> Nginx đã được cài đặt."
fi
echo "--- 3. Cài đặt nhiều phiên bản PHP (8.2) ---"
PHP_VERSIONS=("8.2")
EXTENSIONS=("fpm" "mysql" "dev" "zip" "gd" "mbstring" "curl" "xml" "bcmath" "redis" "mongodb" "intl" "cli")
for VER in "${PHP_VERSIONS[@]}"
do
if ! is_installed "php$VER-fpm"; then
echo "Đang cài đặt PHP $VER-FPM..."
apt install -y --no-install-recommends php$VER-fpm php$VER-cli
for EXT in "${EXTENSIONS[@]}"
do
apt install -y --no-install-recommends php$VER-$EXT
done
systemctl enable php$VER-fpm
systemctl start php$VER-fpm
else
echo ">> PHP $VER đã được cài đặt."
fi
done
echo "--- 4. Cài đặt Redis Server ---"
if ! is_installed "redis-server"; then
apt install -y redis-server
systemctl enable redis-server
systemctl start redis-server
else
echo ">> Redis đã được cài đặt."
fi
echo "--- 5. Cài đặt Supervisor ---"
if ! is_installed "supervisor"; then
apt install -y supervisor
systemctl enable supervisor
systemctl start supervisor
else
echo ">> Supervisor đã được cài đặt."
fi
echo "--- 6. Cài đặt Certbot (SSL) ---"
if ! is_installed "certbot"; then
apt install -y certbot python3-certbot-nginx
else
echo ">> Certbot đã được cài đặt."
fi
echo "--- 7. Cài đặt wkhtmltopdf ---"
if ! is_installed "wkhtmltopdf"; then
# Cài đặt wkhtmltopdf và các font chữ hỗ trợ tiếng Việt/Unicode
apt install -y wkhtmltopdf xfonts-75dpi xfonts-base fonts-viqr
echo ">> Cài đặt wkhtmltopdf thành công."
else
echo ">> wkhtmltopdf đã được cài đặt."
fi
echo "--- 8. Dọn dẹp Apache nếu bị cài nhầm ---"
if dpkg -l | grep -q apache2; then
echo "Phát hiện Apache2, đang gỡ bỏ..."
systemctl stop apache2
apt purge apache2* -y
apt autoremove -y
fi
echo "------------------------------------------------"
echo "TẤT CẢ ĐÃ CÀI ĐẶT XONG!"
echo "Nginx: Đang chạy"
echo "PHP-FPM: ${PHP_VERSIONS[*]} đang chạy"
echo "Redis & Supervisor: Đang chạy"
echo "Certbot: Sẵn sàng"
echo "wkhtmltopdf: Đã sẵn sàng"
echo "------------------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment