PHP에서 fopen 또는 cURL에서 SSL 관련 오류가 발생하여 문제가 있습니다.
소개
PHP (NGINX + PHP-FPM)에서 외부 서버로 HTTPS 통신을 할 때 오류가 발생합니다.
라는 상황이었습니다.
사례 1
WordPress의 Jetpack에서 Twitter로 자동 게시하면 오류가 발생했습니다.
 
 사례 2
여기도 Jetpack이지만 HTTPS 통신에서 오류가 발생했습니다.
 
 사례 3
PHP cURL 시스템 (이 경우 SimpleXML)에서 오류.
Warning: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp/wp-content/themes/example/functions.php on line 506
Warning: simplexml_load_file(): Failed to enable crypto in /mnt/example.com/wp/DocumentRoot/wp-content/themes/example/functions.php on line 506
 사례 4
file_get_contents (fopen)로 외부를 열 때 에러.
2018/05/09 15:41:47 [error] 9268#0: *1641694 FastCGI sent in stderr: "PHP message: PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp-content/themes/example/functions.php on line 468
test.phpvar_dump('hoge');
ini_set('display_errors', true);
echo file_get_contents('https://example.com/hoge.jpg');
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/test.php on line 4
Warning: file_get_contents(): Failed to enable crypto in /mnt/example.com/test.php on line 4
Warning: file_get_contents(https://example.com/test.jpg): failed to open stream: operation failed in /mnt/example/test.php on line 4
 경과
같은 테스트 코드를 사용해 PHP7.2계에서 발생하고 있어, PHP7.0이라고 발생하지 않습니다.
버전에 의한 디폴트의 설정이 원인일지도….
PHP7.0 계열의 OpenSSL
 
PHP7.2.5의 OpenSSL
  
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(PHP에서 fopen 또는 cURL에서 SSL 관련 오류가 발생하여 문제가 있습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/yousan/items/4c98cbee20b2d89e91a3
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
여기도 Jetpack이지만 HTTPS 통신에서 오류가 발생했습니다.

사례 3
PHP cURL 시스템 (이 경우 SimpleXML)에서 오류.
Warning: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp/wp-content/themes/example/functions.php on line 506
Warning: simplexml_load_file(): Failed to enable crypto in /mnt/example.com/wp/DocumentRoot/wp-content/themes/example/functions.php on line 506
 사례 4
file_get_contents (fopen)로 외부를 열 때 에러.
2018/05/09 15:41:47 [error] 9268#0: *1641694 FastCGI sent in stderr: "PHP message: PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp-content/themes/example/functions.php on line 468
test.phpvar_dump('hoge');
ini_set('display_errors', true);
echo file_get_contents('https://example.com/hoge.jpg');
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/test.php on line 4
Warning: file_get_contents(): Failed to enable crypto in /mnt/example.com/test.php on line 4
Warning: file_get_contents(https://example.com/test.jpg): failed to open stream: operation failed in /mnt/example/test.php on line 4
 경과
같은 테스트 코드를 사용해 PHP7.2계에서 발생하고 있어, PHP7.0이라고 발생하지 않습니다.
버전에 의한 디폴트의 설정이 원인일지도….
PHP7.0 계열의 OpenSSL
 
PHP7.2.5의 OpenSSL
  
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(PHP에서 fopen 또는 cURL에서 SSL 관련 오류가 발생하여 문제가 있습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/yousan/items/4c98cbee20b2d89e91a3
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Warning: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp/wp-content/themes/example/functions.php on line 506
Warning: simplexml_load_file(): Failed to enable crypto in /mnt/example.com/wp/DocumentRoot/wp-content/themes/example/functions.php on line 506
file_get_contents (fopen)로 외부를 열 때 에러.
2018/05/09 15:41:47 [error] 9268#0: *1641694 FastCGI sent in stderr: "PHP message: PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp-content/themes/example/functions.php on line 468
test.php
var_dump('hoge');
ini_set('display_errors', true);
echo file_get_contents('https://example.com/hoge.jpg');
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/test.php on line 4
Warning: file_get_contents(): Failed to enable crypto in /mnt/example.com/test.php on line 4
Warning: file_get_contents(https://example.com/test.jpg): failed to open stream: operation failed in /mnt/example/test.php on line 4
경과
같은 테스트 코드를 사용해 PHP7.2계에서 발생하고 있어, PHP7.0이라고 발생하지 않습니다.
버전에 의한 디폴트의 설정이 원인일지도….
PHP7.0 계열의 OpenSSL
 
PHP7.2.5의 OpenSSL
  
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(PHP에서 fopen 또는 cURL에서 SSL 관련 오류가 발생하여 문제가 있습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/yousan/items/4c98cbee20b2d89e91a3
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Reference
이 문제에 관하여(PHP에서 fopen 또는 cURL에서 SSL 관련 오류가 발생하여 문제가 있습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yousan/items/4c98cbee20b2d89e91a3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)