Software & AppsOperating SystemLinux

How To Enable php-curl on Ubuntu 18.04 & PHP 7.2

Ubuntu 16

In this guide, we’ll walk you through the process of enabling php-curl on Ubuntu 18.04 with PHP 7.2. This is a common requirement for many PHP applications that need to make HTTP requests. The curl library provides a way to do this, but it is not enabled by default in PHP.

Quick Answer

To enable php-curl on Ubuntu 18.04 with PHP 7.2, you need to install the php-curl package using the command sudo apt-get install php7.2-curl. After installation, restart the Apache service with sudo service apache2 restart. Make sure the curl module is enabled in the php.ini file by removing the semicolon from the line extension=curl. Finally, verify that the curl module is enabled by creating a PHP file with the phpinfo() function and checking for "curl" in the output.

What is php-curl?

php-curl is a library that allows you to make HTTP requests in PHP. It is based on the libcurl library, which provides a powerful and flexible way to work with URLs. php-curl provides a simple interface to this library, making it easy to download and upload data over HTTP and FTP, handle cookies, and more.

Installing php-curl

To enable php-curl, we first need to install the php-curl package. This package contains the curl module for PHP.

Open a terminal and run the following command:

sudo apt-get install php7.2-curl

The sudo command allows you to run commands with administrative privileges. The apt-get install command installs a package. In this case, we’re installing the php7.2-curl package.

Restarting Apache

After installing the php-curl package, we need to restart the Apache service so it can load the new module. Run the following command:

sudo service apache2 restart

The service command allows you to control system services. In this case, we’re using it to restart the apache2 service.

Checking the php.ini file

Next, we need to make sure that the curl module is enabled in the php.ini file. This file contains configuration settings for PHP.

Open the php.ini file with a text editor by running the following command:

sudo nano /etc/php/7.2/apache2/php.ini

The nano command opens a text editor in the terminal. We’re using it to open the php.ini file.

Look for the line that starts with extension=curl. Make sure this line is not commented out (i.e., it should not have a semicolon at the beginning). If it is commented out, remove the semicolon and save the file.

Verifying the curl module is enabled

To verify that the curl module is enabled, we can create a PHP file that calls the phpinfo() function. This function outputs information about PHP’s configuration.

Create a new file named info.php in the web root directory (usually /var/www/html/) with the following content:

<?php
phpinfo();
?>

Then, open a web browser and visit http://localhost/info.php. This will display a page with information about PHP’s configuration. Search for “curl” on this page. If it is listed, then the curl module is enabled.

Troubleshooting

If you’re still having issues, here are a few things you can try:

  • Check the Apache error log. This log often contains useful information about any issues with PHP or Apache. You can view the log by running the following command:
    sudo tail /var/log/apache2/error.log
    The tail command displays the end of a file. In this case, we’re using it to view the most recent entries in the apache2 error log.
  • Make sure the curl.so file is in the correct directory. This file is the actual curl module that PHP loads. It should be located at /usr/lib/php/20170718/curl.so. If it’s not there, you may need to reinstall the php-curl package.
  • If the curl.so file is in a different directory, you can update the php.ini file to point to the correct directory. Look for the line that starts with extension_dir and update the path to the directory where the curl.so file is located.

By following these steps, you should be able to enable php-curl on Ubuntu 18.04 with PHP 7.2. This will allow your PHP applications to make HTTP requests using the powerful and flexible curl library.

What is the purpose of enabling php-curl on Ubuntu 18.04 with PHP 7.2?

Enabling php-curl allows PHP applications to make HTTP requests and interact with URLs, making it easier to download and upload data over HTTP and FTP, handle cookies, and more.

How do I install php-curl on Ubuntu 18.04 with PHP 7.2?

To install php-curl, open a terminal and run the command sudo apt-get install php7.2-curl. This will install the php-curl package.

How can I restart Apache after installing php-curl?

To restart Apache, run the command sudo service apache2 restart in the terminal. This will reload the Apache service and allow it to load the new php-curl module.

How do I check if the curl module is enabled in the php.ini file?

Open the php.ini file with a text editor by running the command sudo nano /etc/php/7.2/apache2/php.ini. Look for the line that starts with extension=curl. If it is not commented out (i.e., does not have a semicolon at the beginning), then the curl module is enabled.

How can I verify that the curl module is enabled?

Create a new PHP file named info.php in the web root directory (usually /var/www/html/) with the content <?php phpinfo(); ?>. Open a web browser and visit http://localhost/info.php. Search for "curl" on the page that appears. If it is listed, then the curl module is enabled.

What should I do if I’m still having issues enabling php-curl?

If you’re still having issues, you can try checking the Apache error log for any useful information by running the command sudo tail /var/log/apache2/error.log. Additionally, make sure the curl.so file is in the correct directory (/usr/lib/php/20170718/curl.so), and update the php.ini file if necessary to point to the correct directory.

Leave a Comment

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