Current Location: Home> Latest Articles> Comprehensive Guide to Installing and Configuring PHP cURL on Linux

Comprehensive Guide to Installing and Configuring PHP cURL on Linux

gitbox 2025-08-08

Guide to Installing and Configuring PHP cURL on Linux

In a Linux environment, PHP's cURL extension is a crucial tool for interacting with other services and requesting data. cURL supports fetching data from web pages, sending POST requests, and uploading files, offering powerful and flexible functionality. This article explains how to install and configure the PHP cURL extension on Linux systems to ensure your development environment has complete HTTP request capabilities.

Preparation

Before starting, make sure PHP is installed on your system. You can check the PHP version using the following command:

php -v

If PHP is not installed, please follow the appropriate installation method for your Linux distribution. After confirming your PHP environment, proceed with installing the cURL extension.

Installing the cURL Extension

The cURL extension is typically installed through your system's package manager. Below are installation commands for popular Linux distributions:

Ubuntu/Debian Systems

sudo apt update
sudo apt install php-curl

CentOS Systems

sudo yum install php-curl

If you are using another distribution, please refer to its official documentation for installation instructions.

Enabling the cURL Extension

After installation, you need to enable the cURL extension in the php.ini configuration file. The php.ini file is typically located at a path such as /etc/php/7.4/cli/php.ini (version number may vary). Open this file and locate the following line:

;extension=curl

Change it to:

extension=curl

If this line is not present, add it manually. Save and close the configuration file afterward.

Restarting the Web Server

To apply changes, restart your web server. Run the appropriate command based on the server you use:

Apache Server

sudo systemctl restart apache2

Nginx Server

sudo systemctl restart nginx

Verifying cURL Extension Activation

Create a PHP test file (e.g., phpinfo.php) with the following content:

<?php
phpinfo();
?>

Access this file via a web browser and look for a “cURL” section on the page. If found, the cURL extension has been successfully enabled.

Conclusion

This article covered the full process of installing and configuring the PHP cURL extension on Linux. With simple commands to install and enable the extension, combined with restarting the web server and verification steps, you can quickly set up a PHP development environment capable of HTTP requests. We hope this guide helps you configure your environment efficiently and achieve effective network interactions.