Cannot enable php-curl on Ubuntu 18.04 & PHP 7.2

Found the issue.

What was happening was I had both php7.1 and php7.2 enabled within apache2. had to run sudo a2dismod php7.1, restart apache, and afterwards I was able to load my inc.redirect.php page without errors.


Thanks MathewH, I was strugging for last 2 days but was not able to locate the error, as curl module was installed, php-curl extension was also installed, I was able to run the curl for a url in terminal, but when I run the curl_init() function in a PHP code, it would always show 500 internal server error,

Though I have installed the curl module by following commands:

sudo apt-get install php7.0-curl
sudo /etc/init.d/apache2 restart

as I have php 7.4.6 installed in my system

Then I checked the Apache2 error logs in /var/log/apache2/error_log and I found that curl_init() shows error

Call to undefined function curl_init()

Then searching on google I find the link: PHP: Check if cURL is enabled. which mentioned these 3 codes to check whether curl is loaded or not:

  1. if(function_exists('curl_init') === false)
    {
    
     //curl_init is not defined
        //cURL not enabled
    
    }
    
  2. //Check if "curl" can be found in the array of loaded extensions.
    
    if(in_array('curl', get_loaded_extensions()))
    {
        //cURL module has been loaded
    } 
    else
    {
        //It has not been loaded. Use a fallback.
    }
    
  3. if(extension_loaded('curl'))
    {
        //the extension has been loaded
    }
    

I have added these 3 code in index.php and named the project folder as curl-load-check. After running I found and got confirmed that the curl extension is not loaded.

Then finally I found this link: Cannot enable php-curl on Ubuntu 18.04 & PHP 7.2 and from the answer of MathewH, I found that php 7.2 and php 7.4 were both enabled in apache2. so I disabled php 7.2 by the following commands:

sudo a2dismod php7.2
sudo systemctl restart apache2 

and then finally I checked the php code for checking whether the curl extension is loaded as mentioned above in php codes, it showed finally the curl extension is loaded successfully. I checked now the curl_init() function used in php code is working now without any error. Thanks MathewH, after a lot of struggle, finally you saved my day