Skip to content

Blog Công Nghệ

MENUMENU
  • Trang chủ
  • Giới Thiệu
  • Lập Trình
    • Lập Trình Website
      • Laravel
        • Phân Tích Dự Án
      • PHP
      • SQL
      • HTML
      • CSS
      • Javascipt
      • My Project
      • Wordpress
    • Luyện Skill
    • Lập trình winform
    • CSDL
    • Lập Trình Android
    • Trí tuệ nhân tạo
    • Khai Khoáng Dữ Liệu
    • Arduino
    • Khác
    • Đồ án
  • Phần Mềm
    • Powerpoint
    • Tool
  • Cuộc sống và Giải trí
    • Hợp âm
    • web5ngay - youtube
    • Công Giáo
    • Kỹ Năng Sống
    • Street Workout
  • Danh sách bài viết
  • Guide line
    • Guild line phỏng vấn
    • Guide lines Laravel
    • Guide line Module Frontend
  • Tóm tắt sách
  • Fanpage

Blog Công Nghệ

Nơi chia sẻ kiến thức

Build Server Ubuntu A-Z

1 Tháng Bảy, 2024 by admin
Lượt xem: 21

Contents

  • 1. Cài Nginx
  • 2. Cài PHP 8.1
  • 3. Cài Composer
  • 4. Cài Git
  • 5. Change nginx
  • 6. Cài MySQL
  • 7. Cài PHPMyadmin
  • 8. Check log

1. Cài Nginx

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04

sudo apt update
sudo apt install nginx
=>Nhấn Y
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
sudo ufw status
sudo ufw allow ssh

Chạy lên thử sẽ thấy trang welcome nginx
http://your_server_ip

sudo mkdir -p /var/www/your_domain
sudo chown -R www-data:www-data /var/www/your_domain/
sudo chmod -R 755 /var/www/your_domain

sudo vi /var/www/your_domain/index.html

add nội dung bên dưới

<html>
    <head>
        <title>Welcome to your_domain!</title>
    </head>
    <body>
        <h1>Success!  The your_domain server block is working!</h1>
    </body>
</html>
sudo vi /etc/nginx/sites-available/your_domain

Change root and server_name

server {
        listen 80;
        listen [::]:80;

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

        location / {
                try_files $uri $uri/ =404;
        }
}
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

sudo vi /etc/nginx/nginx.conf

Find the server_names_hash_bucket_size directive and remove the # symbol

sudo nginx -t

sudo systemctl restart nginx

2. Cài PHP 8.1

https://www.digitalocean.com/community/tutorials/how-to-install-php-8-1-and-set-up-a-local-development-environment-on-ubuntu-22-04

sudo apt update
sudo apt install --no-install-recommends php8.1
=> Chọn Y

php -v

sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath

php -m

sudo apt install php8.1-fpm

3. Cài Composer

curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
echo $HASH
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

composer

4. Cài Git

https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-22-04

Install git:
sudo apt update
sudo apt install git
git --version

5. Change nginx

sudo vi /etc/nginx/sites-available/your_domain
server {
    listen 80;
    server_name your_domain;
    root /var/www/;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;


    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
sudo nginx -t
sudo systemctl restart nginx

6. Cài MySQL

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04

sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql.service

sudo mysql_secure_installation
=> Chọn 2

sudo MySQL
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456aA@';
exit
mysql -u root -p

7. Cài PHPMyadmin

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-20-04

sudo apt update
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
=> Chọn Apache
mysql -u root -p
UNINSTALL COMPONENT "file://component_validate_password";
exit
sudo apt install phpmyadmin

add thêm vào config:

sudo vi /etc/nginx/sites-available/your_domain
server {
    listen 8080;
    server_name  34.64.145.16;

    root /usr/share/phpmyadmin;
    index index.php index.html index.htm;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # Other phpMyAdmin configurations...
}

8. Check log

tail /var/log/nginx/error.log

Related posts:

  1. Kinh nghiệm VPS Linux
  2. Dev với server nginx
  3. Kinh Nghiệm Docker
  4. Django – build core

Post navigation

Previous Post:

Cài nextjs version cũ

Next Post:

Các bài học từ Resonance Tech

Trả lời Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Ẩn sidebar

Tìm kiếm

Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages

Blog Công Nghệ

Bài viết mới

  • Master typescript
  • Sendmail trong Laravel sử dụng dịch vụ SES, SQS của Amazon
  • Install SSL in Nginx Ubuntu
  • Docker study
  • Bảo vệ: Hướng dẫn code bot Telegram easy game

Lượng truy cập

0074628
Visit Today : 224
Visit Yesterday : 178
This Month : 899
Who's Online : 2
© 2025 Blog Công Nghệ | WordPress Theme by Superbthemes