Xây dựng và triển khai ứng dụng PHP như thế nào?

AWS Elastic Beanstalk dành cho PHP giúp dễ dàng triển khai, quản lý và thay đổi quy mô các ứng dụng web PHP của bạn bằng Amazon Web Services. Beanstalk đàn hồi cho PHP có sẵn cho bất kỳ ai đang phát triển hoặc lưu trữ ứng dụng web bằng PHP. Phần này cung cấp các hướng dẫn để triển khai ứng dụng web PHP của bạn lên Elastic Beanstalk. Bạn có thể triển khai ứng dụng của mình chỉ trong vài phút bằng cách sử dụng Giao diện dòng lệnh đàn hồi Beanstalk [EB CLI] hoặc bằng cách sử dụng Bảng điều khiển quản lý đàn hồi Beanstalk. Nó cũng cung cấp hướng dẫn cho các framework phổ biến như CakePHP và Symfony

Các chủ đề trong chương này giả định rằng bạn có một số kiến ​​thức về môi trường Elastic Beanstalk. Nếu bạn chưa từng sử dụng Elastic Beanstalk trước đây, hãy thử hướng dẫn bắt đầu để tìm hiểu những điều cơ bản

Nếu bạn cần trợ giúp về phát triển ứng dụng PHP, có một số nơi bạn có thể đến

Hãy phát minh lại bánh xe cho mục đích giáo dục. Thật hữu ích khi biết cách e. g. Jenkins, v.v. làm việc dưới mui xe

Mục tiêu của chúng tôi là xây dựng và triển khai ứng dụng PHP bằng các công cụ đơn giản

Yêu cầu

  • Tạo bản dựng
  • Triển khai xây dựng
  • hai môi trường.
    # useradd -d /home/ubuntu -m -s/bin/bash ubuntu
    # mkdir /home/ubuntu/.ssh
    # cp .ssh/authorized_keys /home/ubuntu/.ssh/
    # chown ubuntu:ubuntu /home/ubuntu/.ssh /home/ubuntu/.ssh/authorized_keys
    8 và
    # useradd -d /home/ubuntu -m -s/bin/bash ubuntu
    # mkdir /home/ubuntu/.ssh
    # cp .ssh/authorized_keys /home/ubuntu/.ssh/
    # chown ubuntu:ubuntu /home/ubuntu/.ssh /home/ubuntu/.ssh/authorized_keys
    9
  • Tự động xây dựng và triển khai mỗi ngày một lần

máy chủ

Hãy bắt đầu từ một Ubuntu 18 mới. 04 giọt nước đại dương kỹ thuật số. Tên máy chủ của nó là

# apt install nginx php-fpm
0 và địa chỉ IP của nó là
# apt install nginx php-fpm
1

Thêm một mục vào

# apt install nginx php-fpm
2 để thuận tiện

Host ubuntu
    Hostname 104.248.169.147

Đừng bận tâm đến DNS, vì vậy hãy đặt cái này vào

# apt install nginx php-fpm
3

104.248.169.147 test.example.com
104.248.169.147 prod.example.com

Đăng nhập với quyền root.

# apt install nginx php-fpm
4

Tạo một tài khoản thông thường

# apt install nginx php-fpm
0

# useradd -d /home/ubuntu -m -s/bin/bash ubuntu
# mkdir /home/ubuntu/.ssh
# cp .ssh/authorized_keys /home/ubuntu/.ssh/
# chown ubuntu:ubuntu /home/ubuntu/.ssh /home/ubuntu/.ssh/authorized_keys

Cài đặt nginx và php-fpm [PHP 7. 2]

# apt install nginx php-fpm

Định cấu hình

# apt install nginx php-fpm
6

server {
    server_name test.example.com;
    listen 80;
    root /var/www/test;
    error_log /var/log/nginx/test.example.com.error.log;
    access_log /var/log/nginx/test.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

server {
    server_name prod.example.com;
    listen 80;
    root /var/www/prod;
    error_log /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

tải lại.

# apt install nginx php-fpm
7

Tạo tài liệu gốc để thử nghiệm và sản xuất

# mkdir /var/www/{test,prod}
# chown ubuntu:ubuntu /var/www/{test,prod}
  • # apt install nginx php-fpm
    8 môi trường thử nghiệm
  • # apt install nginx php-fpm
    9 môi trường sản xuất

Môi trường

# useradd -d /home/ubuntu -m -s/bin/bash ubuntu
# mkdir /home/ubuntu/.ssh
# cp .ssh/authorized_keys /home/ubuntu/.ssh/
# chown ubuntu:ubuntu /home/ubuntu/.ssh /home/ubuntu/.ssh/authorized_keys
8 và
# useradd -d /home/ubuntu -m -s/bin/bash ubuntu
# mkdir /home/ubuntu/.ssh
# cp .ssh/authorized_keys /home/ubuntu/.ssh/
# chown ubuntu:ubuntu /home/ubuntu/.ssh /home/ubuntu/.ssh/authorized_keys
9 hiện có thể truy cập tại

http. //kiểm tra. thí dụ. com/

http. // sản xuất. thí dụ. com/

Thoát và đăng nhập với tên

# apt install nginx php-fpm
0

$ ssh -lubuntu ubuntu

Tạo thư mục

$ mkdir ~/{app,bin}

server {
    server_name test.example.com;
    listen 80;
    root /var/www/test;
    error_log /var/log/nginx/test.example.com.error.log;
    access_log /var/log/nginx/test.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

server {
    server_name prod.example.com;
    listen 80;
    root /var/www/prod;
    error_log /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}
3 chứa mã nguồn ứng dụng và
server {
    server_name test.example.com;
    listen 80;
    root /var/www/test;
    error_log /var/log/nginx/test.example.com.error.log;
    access_log /var/log/nginx/test.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

server {
    server_name prod.example.com;
    listen 80;
    root /var/www/prod;
    error_log /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}
4 chứa các tập lệnh bash của chúng tôi

Cập nhật

server {
    server_name test.example.com;
    listen 80;
    root /var/www/test;
    error_log /var/log/nginx/test.example.com.error.log;
    access_log /var/log/nginx/test.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

server {
    server_name prod.example.com;
    listen 80;
    root /var/www/prod;
    error_log /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}
5 và nguồn
server {
    server_name test.example.com;
    listen 80;
    root /var/www/test;
    error_log /var/log/nginx/test.example.com.error.log;
    access_log /var/log/nginx/test.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

server {
    server_name prod.example.com;
    listen 80;
    root /var/www/prod;
    error_log /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}
6

$ echo "PATH=~/bin/:$PATH" >> .bashrc
$ . .bashrc

Ứng dụng này có một tệp duy nhất

server {
    server_name test.example.com;
    listen 80;
    root /var/www/test;
    error_log /var/log/nginx/test.example.com.error.log;
    access_log /var/log/nginx/test.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

server {
    server_name prod.example.com;
    listen 80;
    root /var/www/prod;
    error_log /var/log/nginx/prod.example.com.error.log;
    access_log /var/log/nginx/prod.example.com.access.log;

    index ua.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}
7 in ra ua của trình duyệt

Chủ Đề