File_put_contents (): connect () failed: permission denied on AWS server

$username_ftp = "user";
$password_ftp = "password";
$file_name = "remote-transfer.txt";
$url = "example.biz/test/" . $file_name;
$hostname = "ftp://$username_ftp:$password_ftp@$url";
$content = file_get_contents('index.html');
$options = array('ftp' => array('overwrite' => true));
$stream = stream_context_create($options);
file_put_contents($hostname, $content, 0, $stream);

I try to put a file from my remote remote server to another remote server while I exixute this code from my localhost this is a working file, and I transfer the file from my ocal PC to the server. But when I try to output this code from my AWS server, it does not transfer any files. When I check my error log file, it gives

PHP Warning:  file_put_contents(): connect() failed: Permission denied 
PHP Warning:  file_put_contents(ftp://...@example.biz/remote-transfer.txt): failed to open stream: operation failed in

My test resolution for folder 777 is now what to do if there is any server configuration that is missing.

+4
source share
4 answers

, , . :

setsebool -P httpd_can_network_connect on

. : http://linux.die.net/man/8/setsebool

+2

, $hostname : ( ec2 .)

<?php 
/* set the FTP hostname */ 
$user = "test"; 
$pass = "myFTP"; 
$host = "example.com"; 
//path of file
$file = "test.txt"; 
$hostname = $user . ":" . $pass . "@" . $host . "/" . $file; 

/* the file content */ 
$content = "this is just a test."; 

/* create a stream context telling PHP to overwrite the file */ 
$options = array('ftp' => array('overwrite' => true)); 
$stream = stream_context_create($options); 

/* and finally, put the contents */ 
file_put_contents($hostname, $content, 0, $stream); 
?>

: PHP: file_put_contents -

0

:

AWS ( ) 777 ( , ), , , .

: AWS, , .

, ; ( ), .

, @chetanAmeta, .

.

0

, , , ( , ). , , apache (, "www-data" ), , , , .

Hope this helps someone else as it was very unpleasant for me in the beginning.

0
source

Source: https://habr.com/ru/post/1584416/


All Articles