See all PHP related FAQ
I setup a LEMP (Linux, Nginx,MySQL, PHP ) stack. But, getting the following error in /var/log/nginx/error.log file:
    PHP Fatal error: Call to undefined function curl_init() in /home/httpd/a/includes/functions.php(1)
How do I solve this problem on Linux server?

You need to install the CURL module or extenshion for PHP 5 or 7/8 version. cURL is a library that lets you make HTTP requests in PHP. In order to use PHP’s cURL functions you need to install the libcurl package. To solve this problem install php-curl as per your Linux / Unix distro and restart the web-server or php-fpm service.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements PHP on Linux/Unix
Est. reading time 3 minutes
Advertisement

How to fix “Fatal error: Call to undefined function curl_init()”

Let us install curl extension on Linux or Unix.

Installing CURL module for PHP on Ubuntu / Debian Linux

Type the following apt-get command or apt command to install CURL module for PHP 5.x/7.x/8.x:
$ sudo apt-get install php-curl
Type the following apt-get command or apt command to install CURL module for PHP 7.x only:
$ sudo apt-get install php7.0-curl # php v7
$ sudo apt install php7.4-curl # php v7.4 for Ubuntu 20.04

PHP Fatal error: Call to undefined function curl_init()

RHEL/CentOS/ScientificAlmaLinux/Rocky Linux install CURL module for PHP

Run the following yum command or dnf command on Fedora box:
$ sudo yum install php-curl
$ sudo dnf install php-curl

You also try the following command:
$ sudo yum install php-common
The above should install php-common to enable curl support.

OpenSUSE or SUSE Enterprise Linux

Use the zypper command as follows:
sudo zypper in php7-curl

Alpine Linux fixing Fatal error: Call to undefined function curl_init()

Execute the following apk command to install extension:
# apk add php5-curl
OR
# apk add php7-curl
OR
# apk add php8-curl

FreeBSD Unix install CURL module for PHP

To install the port for PHP 5.x:
# cd /usr/ports/ftp/php56-curl/ && make install clean
Or To add the package for PHP 5.x use the pkg command:
# pkg install php56-curl
To install the port for PHP 7.x:
# cd /usr/ports/ftp/php70-curl/ && make install clean
Or To add the package for PHP 7.x:
# pkg install php70-curl
For PHP 8.x, run:
sudo pkg install php80-curl

Restart Apache/Nginx or PHP-FPM service

Type the following command to restart nginx service:
$ sudo service nginx restart
OR
$ sudo /etc/init.d/nginx restart
OR
$ sudo systemctl restart nginx
OR
# rc-service nginx restart
If you are using php-fpm, enter the following commands to restart php services:
# rc-service php-fpm restart
OR
# /etc/init.d/php7.0-fpm restart
OR
# /etc/init.d/php5.0-fpm restart
OR
$ sudo systemctl restart php7.0-fpm.service
To restart Apache 2 Web Server:
sudo systemctl restart apache2.service # Debian/Ubuntu
sudo systemctl restart httpd.service # RHEL/CentOS/Fedora

Summing up

You learned how to fix the error “Fatal error: Call to undefined function curl_init()” when using PHP with popular web servers such as Nginx, Apache, and others.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.