Giter Club home page Giter Club logo

ubuntu-lemp-stack's Introduction

Auto Install & Optimize LEMP Stack on Ubuntu (18.04, 20.04)

Author: Sanvv - HOSTVN.NET Technical

Home Page: Hostvn Scripts Home page , Hostvn.net - Tên miền, Web Hosting, Email, VPS & Dịch vụ lưu trữ Website

Document: https://help.hostvn.vn/

Groups Support: https://www.facebook.com/groups/hostvn.vn

########################################################################################

Script được viết bằng shell dùng để cài đặt LEMP Stack (Nginx - MariaDB - PHP-FPM) trên Ubuntu (18.04, 20.04), Debian 10.

Vui lòng không sao chép, phát hành lại với mục đích thương mại, donate. Xin cảm ơn.

1. Chi tiết Script:

1.1. Cài đặt

  • Cập nhật liên tục, cung cấp Menu giúp dễ dàng thao tác, tự động cài đặt.
  • Cài đặt các phần mềm với phiên bản mới nhất từ chính trang chủ.
  • Mariadb: 10.5.
  • Phiên bản Nginx Stable.
  • Cho phép lựa chọn phiên bản PHP: 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0
  • phpMyAdmin 4.9.x nếu cài đặt PHP mặc định là 5.6, phpMyAdmin 5.0.x nếu cài đặt PHP mặc định là 7.x.
  • Cấu hình Nginx FastCGI cache
  • Cấu hình Nginx Pagespeed
  • Cài đặt PHPMemcachedAdmin, phpRedisAdmin, Opcache Dashboard.
  • Cài đặt memcached, redis cache. (Mặc định sẽ không bật).
  • Cài đặt Fail2ban.
  • Tích hợp Let's Encrypt SSL.
  • Tích hợp CloudFlare DNS API giúp xác thực SSL nhanh hơn.
  • Cung cấp Menu nâng cấp Nginx, MariaDB, PHP, Redis, Memcached, phpMyAdmin.
  • Cài đặt WP-CLI, Composer, supervisor, Rclone.
  • Cài đặt: ClamAV, ImunifyAV.
  • KHÔNG THU THẬP BẤT KỲ THÔNG TIN GÌ TRÊN VPS CỦA BẠN.

1.2. Tối ưu

  • Cấu hình tối ưu MySQL, Nginx, PHP, Opcache, Memcached, Redis phù hợp theo thông số của VPS.
  • Cấu hình Brotli Compress.
  • Cấu hình rewrite URL với một số mã nguồn phổ biến: WordPress, Laravel, Opencart, Magento, Drupal ...
  • Cho phép chạy song song hai phiên bản PHP.
  • Quản lý FTP dễ dàng trong trường hợp bạn thuê coder và chỉ muốn họ được phép access vào thư mục nhất định.
  • Cho phép lựa chọn Redis Cache hoặc Memcached giúp tăng tốc độ website.
  • Cho phép cấu hình tự động gia hạn Let's Encrypt.
  • Menu hỗ trợ cấu hình SSL trả phí.
  • Menu xem error log Nginx, Mysql, PHP và xem theo từng tên miền cụ thể.
  • Cronjob tự động cập nhật dải IP mới nhất của Cloudflare cho Nginx và CSF Firewall.
  • And More ...

1.3. Bảo mật

  • Cấu hình tăng cường bảo mật từ tầng webserver.
  • Cấu hình website chạy với user khác nhau hạn chế lây lan mã độc giữa các website.
  • Disable các hàm nguy hiểm, bật open_basedir và một số config khác nhằm tăng cường bảo mật.
  • Auto block bruteforce SSH, SFTP, Admin Tool .... với Fail2ban.
  • Block run shell trong thư mục uploads WordPress. Chặn truy cập các thư mục, file nhạy cảm trên WordPress.
  • Chống Bruteforce wp-admin.
  • BLock, Unblock IP dễ dàng với menu quản lý Firewall.
  • Disable User API - /wp-json/wp/v2/users - trên WordPress tránh lộ thông tin User.
  • Thay đổi Port SSH tránh scan SSH.
  • Cho phép thay đổi port Admin.
  • Cho phép thay đổi port SSH/SFTP.
  • Tự động tạo mật khẩu mạnh.
  • Scan Malware với Clamav, ImunifyAV.
  • And More ...

1.4. Quản lý WordPress

  • Kiểm tra phiên bản WordPress đang sử dụng.
  • Cập nhật WordPress.
  • Cập nhật plugins.
  • Tối ưu Database.
  • Repair Database.
  • Sao lưu dữ liệu (Local/GG Drive).
  • Khôi phục dữ liệu (Local/GG Drive).
  • Thay đổi tên miền.
  • Đổi mật khẩu admin (wp-admin).
  • Cài đặt WordPress tự động.
  • Bật/tắt Yoast Seo config.
  • Bật/Tắt Rank Math Seo config.
  • Cấu hình Nginx với một số plugins cache phổ biến: WP-Rocket, w3 total cache, wp supercache, Cache Enabler, Swift Performance, Fast cache.
  • Thêm cache key tránh trùng lặp nội dung giữa các site khi dùng memcached hoặc redis.
  • Bật/tắt Debug.
  • Bật/tắt chế độ bảo trì.
  • Bật/Tắt disable xmlrpc (Mặc định sẽ disable xmlrpc để tránh bị khai thác DDOS).
  • Huỷ kích hoạt toàn bộ plugins.
  • Random database prefix khi sử dụng chức năng cài đặt tự động.
  • And more ...

1.5. Sao lưu/Khôi phục dữ liệu

  • Backup và restore dữ liệu từ Google Drive với Rclone.
  • Backup, restore tại Local.
  • Thiết lập số bản backup lưu trữ.
  • Quản lý các bản sao lưu.
  • Cho phép kết nối nhiều tài khoản Google Drive.

2. Yêu cầu

  • VPS tối thiểu 512MB ram và chưa cài đặt bất kỳ dịch vụ nào.
  • Ubuntu 18.04, 20.04, Debian 10.

3. Cách cài đặt

curl -sO https://scripts.hostvn.net/install && chmod +x install && ./install

4. Các tính năng sẽ phát triển

  • Các tính năng theo request của người dùng

5. Cách sử dụng

6. Nguồn download các phần mềm

7. Contact

8. Feedback

  • Do chưa có nhiều kinh nghiệm nên Scripts khó tránh khỏi thiếu sót, rất mong nhận được ý kiến đóng góp của các bạn để Scripts ngày càng hoàn thiện hơn.
  • Mọi ý kiến đóng góp các bạn vui lòng gửi về [email protected], Groups Facebook: https://www.facebook.com/groups/hostvn.vn hoặc tạo Github Issues.

9. Contributors & Credits

Developers / Maintainers

  • Sanvv

Contributors

ubuntu-lemp-stack's People

Contributors

sanvu88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ubuntu-lemp-stack's Issues

Không thể backup google drive

Hell, mình thử backup google drive thì bị lỗi không backup đc

/var/hostvn/menu/cronjob/gg_drive_one: line 2: $'\r': command not found
/var/hostvn/menu/cronjob/gg_drive_one: line 12: $'\r': command not found
/var/hostvn/menu/cronjob/gg_drive_one: line 13: /var/hostvn/ipaddress
: No such file or directory
/var/hostvn/menu/cronjob/gg_drive_one: line 14: /var/hostvn/.hostvn.conf
: No such file or directory
/var/hostvn/menu/cronjob/gg_drive_one: line 15: /var/hostvn/menu/helpers/variable_common
: No such file or directory
/var/hostvn/menu/cronjob/gg_drive_one: line 16: $'\r': command not found
/var/hostvn/menu/cronjob/gg_drive_one: line 17: syntax error near unexpected token `$'do\r''
/var/hostvn/menu/cronjob/gg_drive_one: line 17: `for domains in "${BASH_DIR}"/ggdrive/*; do

source /var/hostvn/ipaddress
source /var/hostvn/.hostvn.conf
source /var/hostvn/menu/helpers/variable_common

for domains in "${BASH_DIR}"/ggdrive/*; do
    domain=$(echo "$domains" | cut -f5 -d'/')
    if [[ -f "${USER_DIR}/.${domain}.conf" ]]; then
        user=$(grep -w "username" "${USER_DIR}/.${domain}.conf" | cut -f2 -d'=')
        db_name=$(grep -w "db_name" "${USER_DIR}/.${domain}.conf" | cut -f2 -d'=')
        if [[ ! -d "/home/backup/${CURRENT_DATE}/${domain}" ]]; then
            mkdir -p /home/backup/"${CURRENT_DATE}"/"${domain}"
        fi
        rm -rf /home/backup/"${CURRENT_DATE}"/"${domain}"/*
        cd /home/backup/"${CURRENT_DATE}"/"${domain}" || exit
        mysqldump -uadmin -p"${mysql_pwd}" "${db_name}" | gzip > "${db_name}".sql.gz

        cd /home/"${user}"/"${domain}" || exit
        if [[ ! -f "/home/${user}/${domain}/public_html/wp-config.php" && -f "/home/${user}/${domain}/wp-config.php" ]]; then
            cp /home/"${user}"/"${domain}"/wp-config.php /home/"${user}"/"${domain}"/public_html/wp-config.php
        fi
        if [ -d "/home/${user}/${domain}/public_html/storage" ]; then
            tar -cpzvf /home/backup/"${CURRENT_DATE}"/"${domain}"/"${domain}".tar.gz \
                --exclude "public_html/storage/framework/cache" --exclude "public_html/storage/framework/views" public_html
        else
            tar -cpzvf /home/backup/"${CURRENT_DATE}"/"${domain}"/"${domain}".tar.gz \
                --exclude "public_html/wp-content/cache" public_html
        fi
        rclone copy /home/backup/"${CURRENT_DATE}"/"${domain}" "${remote}":/WEBSITE/BACKUP/"${domain}"/"${CURRENT_DATE}" --bwlimit 30M >> /var/log/rclone.log 2>&1
        rm -rf /home/backup/"${CURRENT_DATE}"/"${domain}"
        if [[ -f "/home/${user}/${domain}/public_html/wp-config.php" && -f "/home/${user}/${domain}/wp-config.php" ]]; then
            rm -rf /home/"${user}"/"${domain}"/public_html/wp-config.php
        fi
    fi
done

rclone -q --min-age "${backup_num}"d delete "${remote}":/WEBSITE/BACKUP/"${domain}" >> /var/log/rclone.log 2>&1
rclone -q --min-age "${backup_num}"d rmdirs "${remote}":/WEBSITE/BACKUP/"${domain}" >> /var/log/rclone.log 2>&1

file cron

0 3 * * * bash /var/hostvn/menu/cronjob/updateCloudflareRangeIP >/dev/null 2>&1
12 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
@midnight bash /var/hostvn/menu/cronjob/gg_drive_one > /root/rclone.log 2>&1

Đổi phương thức khác để backup mysql hiệu quả hơn

việc dùng mysqldump không hiệu quả trong trường hợp người dùng không dùng mysql trên server đó, nếu người dùng remote sql tới chỗ khác thì quá trình backup bị lỗi

_backup_database() {
db_name=$(grep -w "db_name" "${USER_DIR}/.${domain}.conf" | cut -f2 -d'=')
_cd_dir /home/backup/"${CURRENT_DATE}"/"${domain}"
if [ -f "/home/backup/${CURRENT_DATE}/${domain}/${db_name}.sql.gz" ]; then
rm -rf /home/backup/"${CURRENT_DATE}"/"${domain}"/"${db_name}".sql.gz
fi
mysqldump -uadmin -p"${mysql_pwd}" "${db_name}" | gzip > "${db_name}".sql.gz
}

Chuyển thành code như sau

_backup_database() {
   user=$(grep -w "username" "${USER_DIR}/.${domain}.conf" | cut -f2 -d'=')
   _cd_dir /home/backup/"${CURRENT_DATE}"/"${domain}"
   wp db export "${domain}".sql --allow-root --path=/home/"${user}"/"${domain}"/public_html

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.