Curl install in cent os but not working


I have install CURL in cent OS.

I can see in my PHPINFO.

I also install LARAVEL.

But when i call curl return 0.

i have also setup firewall and allowed 80 and 443 port

 $html_brand = "";
                $ch = curl_init();

                $options = array(
                    CURLOPT_URL            => $html_brand,
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_HEADER         => true,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_ENCODING       => "",
                    CURLOPT_AUTOREFERER    => true,
                    CURLOPT_CONNECTTIMEOUT => 120,
                    CURLOPT_TIMEOUT        => 120,
                    CURLOPT_MAXREDIRS      => 10,
                curl_setopt_array( $ch, $options );
                $response = curl_exec($ch); 
                $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

                if ( $httpCode != 200 ){
                    echo "Return code is {$httpCode} \n"
                } else {
                    echo "<pre>".htmlspecialchars($response)."</pre>";

It’s “Return code is 0”;

how i resolved this issue.

I am sure issue from server.

any comments guys ?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I am able to solve this error by executing below command. Most of the time we face if SELinux is enabled on our server. The curl request is blocked by SELinux.

setsebool -P httpd_can_network_connect on

after that restart your server.

sudo systemctl restart httpd

I am also facing this issue, please let us know if there is any solution. Server - Getting this issue on Cetos server with php version 8.0. If anyone find the resolution for this than please be kind to share info.

Hi @sharmahemal811,

I tested your script and I can confirm I got a HttpCode 200.

Now, you were wondering why was executing


From the command line working but when you put it in a script it didn’t work. The curl you are using from the command line is actually very different than the one you are using in php scripts.

Basically, in your command line, you are using curl and in your php scripts, you are using an extension for php called php-curl. While the command-line curl comes installed by default, that is not the case for php-curl. As such all you need to do is install php-curl.

Depending on the php version installed (7, 7.2, 7.3, 7.4), you need to run the following command:

yum install php-curl


yum install php7.2-curl

Now, if you are using another php version just change the number 7.2 as you like.

Regards, KFSys