Hướng dẫn php with ssl - php với ssl

Trong bài viết này sẽ sử dụng tên miền ảo làm ví dụ là site.test

Nội dung chính

  • 1. Vào thư mục Apache trong XAMPP.
  • 2. Tạo một thư mục mới.
  • 3. Tải về và thêm 2 tập tin này vào thư mục vừa tạo
  • 4. Sửa cert.conf và chạy make-cert.bat
  • 5. Cài đặt chứng chỉ trong windows.
  • 6. Thêm trang web trong máy chủ Windows
  • 7. Thêm tên miền này vào file conf của XAMPP.
  • 8. Khởi động lại trình duyệt và thử lại!
  • Description
  • Return Values

1. Vào thư mục Apache trong XAMPP.

2. Tạo một thư mục mới.XAMPP đợc cài đặt trong thư mục C:\xampp\apache.

2. Tạo một thư mục mới.

3. Tải về và thêm 2 tập tin này vào thư mục vừa tạocrt ,Vì vậy, đường dẫn sẽ có dạng C:\xampp\apache\crt

3. Tải về và thêm 2 tập tin này vào thư mục vừa tạo

4. Sửa cert.conf và chạy make-cert.batcert.conf make-cert.bat về. 2 tập tin này sẽ dùng để tạo chứng chỉ SSL cho tên miền tùy thích.

4. Sửa cert.conf và chạy make-cert.bat

5. Cài đặt chứng chỉ trong windows.site.test và lưu lại.

6. Thêm trang web trong máy chủ Windowssite.test khi được nhắc. Và nhập trả lời cho các câu hỏi khác, thiết lập mặc định có sẵn trong cert.conf

Hướng dẫn php with ssl - php với ssl

5. Cài đặt chứng chỉ trong windows.

6. Thêm trang web trong máy chủ Windowsserver.crt and server.key. Đây là chứng chỉ SSL certificate.

7. Thêm tên miền này vào file conf của XAMPP.

8. Khởi động lại trình duyệt và thử lại!Local Machine trong Store Location.

DescriptionPlace all certificate in the following store” và click browse sau đó chọn Trusted Root Certification Authorities.

Return ValuesNext và Finish.

Mặc định XAMPP đợc cài đặt trong thư mục C:\xampp\apache.

6. Thêm trang web trong máy chủ Windows

  1. 7. Thêm tên miền này vào file conf của XAMPP.
  2. 8. Khởi động lại trình duyệt và thử lại!
  3. Description
 
127.0.0.1 site.test

Return Values

7. Thêm tên miền này vào file conf của XAMPP.

8. Khởi động lại trình duyệt và thử lại!C:\xampp\apache\conf\extra\httpd-xampp.conf

Description

## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 

Return Values

Mặc định XAMPP đợc cài đặt trong thư mục C:\xampp\apache.: Trong file conf XAMPP, bạn có thể thay đổi thư mục gốc cho từng tên miền nếu cần.

8. Khởi động lại trình duyệt và thử lại!

Description

Return Values

Mặc định XAMPP đợc cài đặt trong thư mục C:\xampp\apache.

Đây là nơi ta sẽ lưu trữ chứng chỉ SSL. Trong ví dụ này Ngôi Sao Số sẽ tạo thư mục crt ,Vì vậy, đường dẫn sẽ có dạng C:\xampp\apache\crtGenerates a CSR

Description

Return Values: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.

Mặc định XAMPP đợc cài đặt trong thư mục C:\xampp\apache.

Đây là nơi ta sẽ lưu trữ chứng chỉ SSL. Trong ví dụ này Ngôi Sao Số sẽ tạo thư mục crt ,Vì vậy, đường dẫn sẽ có dạng C:\xampp\apache\crt

Vào đường dẫn sau tải 2 tập tin cert.conf make-cert.bat về. 2 tập tin này sẽ dùng để tạo chứng chỉ SSL cho tên miền tùy thích.

Mở file cert.conf và thay đổi {{DOMAIN}} thành tên miền bạn muốn, trong trường hợp này site.test và lưu lại.

Nhấp đúp chuột vào make-cert.bat và nhập tên miền site.test khi được nhắc. Và nhập trả lời cho các câu hỏi khác, thiết lập mặc định có sẵn trong cert.confopenssl_pkey_new() (or otherwise obtained from the other openssl_pkey family of functions). The corresponding public portion of the key will be used to sign the CSR.

Sau đó, bạn sẽ thấy thư mục site.test được tạo. Trong thư mục đó ta sẽ có server.crt and server.key. Đây là chứng chỉ SSL certificate.

Nhấp đúp chuột vào server.crt để cài đặt nó trên Windows để Windows chấp nhận chứng chỉ này.

Và chọn Local Machine trong Store Location.
Tiếp tục chọn “Place all certificate in the following store” và click browse sau đó chọn Trusted Root Certification Authorities.Chọn Next và Finish.Và bây giờ chứng chỉ này đã được cài đặt là tin cậy (trusted) trong Windows. Tiếp theo là làm thế nào để sử dụng chứng chỉ này trong XAMPP.Mở notepad với quyền administrator.
Sửa C:\Windows\System32\drivers\etc\hostsThêm một dòng mới: Điều này sẽ giúp XAMPP khi truy cập http://site.test sẽ trỏ tên miền này về IP localhostGiờ bạn cần kích hoạt SSL cho tên miền này và cho XAMPP biết nơi lưu trữ Chứng chỉ SSL. Vì vậy, bạn cần chỉnh sửa C:\xampp\apache\conf\extra\httpd-xampp.confopenssl_get_md_methods()
Và thêm dòng mới này dưới cùng:Thêm một dòng mới: Và thêm dòng mới này dưới cùng:Sau đó, bạn sẽ cần khởi động lại Apache trong XAMPP. Đơn giản, chỉ cần mở Bảng điều khiển XAMPP và bấm stop và start tại mục Apache.
Mẹo: Trong file conf XAMPP, bạn có thể thay đổi thư mục gốc cho từng tên miền nếu cần.Thêm một dòng mới: Mẹo: Trong file conf XAMPP, bạn có thể thay đổi thư mục gốc cho từng tên miền nếu cần.Cần khởi động lại trình duyệt để hệ thống tải chứng chỉ. Và truy cập tên miền trên trình duyệt của bạn, và bạn sẽ thấy khóa màu xanh lá như hình bên dưới!
Ngôi Sao Số hy vọng hướng dẫn này hữu ích!int (PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)openssl_csr_new — Generates a CSR
Note: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information. int Parameters distinguished_names
127.0.0.1 site.test
5
,
127.0.0.1 site.test
6
,
127.0.0.1 site.test
7
or
127.0.0.1 site.test
8
. The default value is
127.0.0.1 site.test
7
.
The Distinguished Name or subject fields to be used in the certificate. private_key The Distinguished Name or subject fields to be used in the certificate. private_key
Encrypt_key_codesint không ai Một trong những hằng số mật mã.
đường cong_namesợi dây không ai Một trong những hằng số mật mã.openssl_get_curve_names().
đường cong_namesợi dây Một trong các openSSL_GET_CURVE_NAME ().Cấu hình
N/a

Đường dẫn đến tệp OpenSSL.conf thay thế của riêng bạn.

## site.test DocumentRoot "C:/xampp/htdocs" ServerName site.test ServerAlias *.site.test DocumentRoot "C:/xampp/htdocs" ServerName site.test ServerAlias *.site.test SSLEngine on SSLCertificateFile "crt/site.test/server.crt" SSLCertificateKeyFile "crt/site.test/server.key" 0

## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
0 được sử dụng để chỉ định các tùy chọn cấu hình bổ sung cho CSR. Cả distinguished_names
## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
0 đều là các mảng kết hợp có các khóa được chuyển đổi thành OID và áp dụng cho phần liên quan của yêu cầu.
## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
4
on failure.

Trả về giá trị

Trả về CSR hoặc
## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
4 khi thất bại.
Thay đổi
8.0.0 Phiên bảnOpenSSLCertificateSigningRequest instance now; previously, a resource of type
## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
5 was returned.
8.0.0 Sự mô tảOpenSSLAsymmetricKey instance now; previously, a resource of type
## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
7 was accepted.
7.1.0 Về thành công, chức năng này trả về một thể hiện openSslCerTyerIgningRequest ngay bây giờ; Trước đây, một tài nguyên loại
## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
5 đã được trả lại.

private_key chấp nhận một phiên bản openSsmmetrickey ngay bây giờ; Trước đây, một tài nguyên loại ## site.test DocumentRoot "C:/xampp/htdocs" ServerName site.test ServerAlias *.site.test DocumentRoot "C:/xampp/htdocs" ServerName site.test ServerAlias *.site.test SSLEngine on SSLCertificateFile "crt/site.test/server.crt" SSLCertificateKeyFile "crt/site.test/server.key" 7 đã được chấp nhận.

options bây giờ cũng hỗ trợ

## site.test
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 
 
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 
9.

distinguished_names0

Ví dụ

distinguished_names1

Ví dụ #1 Tạo chứng chỉ tự ký

  • Ví dụ #2 Tạo chứng chỉ ECC tự ký (kể từ Php 7.1.0)

Xem thêm

OpenSSL_CSR_Sign () - Ký CSR bằng chứng chỉ khác (hoặc chính nó) và tạo chứng chỉ

distinguished_names2

Ẩn danh ¶

7 năm trước

distinguished_names3

distinguished_names4

distinguished_names5

Người mất tích ¶

OpenSSL_CSR_Sign () - Ký CSR bằng chứng chỉ khác (hoặc chính nó) và tạo chứng chỉ

distinguished_names6

distinguished_names7

distinguished_names8

distinguished_names9

private_key0

private_key1

private_key2

private_key3

private_key4

private_key5

private_key6

private_key7

distinguished_names5

Ẩn danh ¶

7 năm trước

private_key9

private_key0

private_key1

private_key2

private_key3

Người mất tích ¶

private_key5

distinguished_names5

12 năm trước

OpenSSL_CSR_Sign () - Ký CSR bằng chứng chỉ khác (hoặc chính nó) và tạo chứng chỉ

private_key7

Ẩn danh ¶

7 năm trước

private_key8

private_key9

options0

options1

distinguished_names5

Người mất tích ¶

12 năm trước

options3

options4

options5

options6

options7

distinguished_names5

James tại Kirk Dot Com ¶

12 năm trước

options9

James tại Kirk Dot Com ¶

12 năm trước

openssl.conf0

openssl.conf1

distinguished_names5

James tại Kirk Dot Com ¶

Main Att Jokester Dott fr ¶

openssl.conf3

openssl.conf4

distinguished_names5