Well, I had the same problem, and I found a solution for my business. Post it here to help others.
My PHP script will fail, but I can easily FTP through the command line. I checked that my firewall did not block the script and I did not receive any PHP errors in my log ...
After searching, it turned out that my question was SELinux . I did not want to disconnect it, therefore I checked the status of httpd_can_network_connect .
Check your status by running:
getsebool httpd_can_network_connect
If you get:
httpd_can_network_connect --> off
This may be your problem.
Note:
If you already have this on :
httpd_can_network_connect --> on
or
SELinux is disabled
Then it will not solve your problem ... Good luck finding your solution.
Correction
Enable httpd_can_network_connect by doing:
setsebool httpd_can_network_connect=1
Check your script again and see if it works. This worked for me, so I decided to set a policy so that it was enabled.
setsebool -P httpd_can_network_connect=1
NOTE. -P sets the policy so that it persists upon reboot
source share