How to Install CURL on an Ubuntu Server and Verify PHP cURL is Running
CURL is a powerful command-line tool for transferring data using various network protocols. It's widely used in server environments, particularly when working with APIs. If you're running PHP applications, it's also important to ensure the PHP cURL extension is enabled. This guide will walk you through installing CURL on an Ubuntu server and checking that PHP cURL is properly configured.
🛠️ Installing CURL on Ubuntu
To install CURL on your Ubuntu server, follow these steps:
1. Update Package Index
sudo apt update
2. Install CURL
sudo apt install curl -y
3. Verify Installation
curl --version
If installed correctly, this will output the CURL version and supported protocols.
⚙️ Installing PHP cURL Extension
If you're using PHP, you'll also need to install the PHP cURL module.
1. Install PHP cURL
Replace php
with your PHP version, e.g., php8.2-curl
.
sudo apt install php-curl
Or, if using a specific version:
sudo apt install php8.2-curl
2. Restart the Web Server
Apache:
sudo systemctl restart apache2
Nginx (with PHP-FPM):
sudo systemctl restart php8.2-fpm
✅ Verifying PHP cURL is Running
1. Use Command Line
php -m | grep curl
You should see:
curl
2. Check with phpinfo()
Create a test PHP file:
sudo nano /var/www/html/info.php
Add the following content:
<?php
phpinfo();
?>
Access in browser:
Visit:
http://your-server-ip/info.php
Search for curl in the output. You'll find a section confirming cURL support.
🧹 Clean Up (Optional)
After checking, remove the test file:
sudo rm /var/www/html/info.php
📝 Summary
Task | Command | |
---|---|---|
Install CURL | sudo apt install curl -y | |
Install PHP cURL | sudo apt install php-curl | |
Check PHP cURL (CLI) | `php -m \ | grep curl` |
Check PHP cURL (phpinfo ) | Visit info.php in the browser | |
Restart Web Server (Apache) | sudo systemctl restart apache2 | |
Restart Web Server (Nginx) | sudo systemctl restart php8.2-fpm |
By following these steps, you'll have CURL and PHP cURL up and running on your Ubuntu server, ready to handle web requests from your PHP applications.