Hướng dẫn enable php-curl extension ubuntu

Last updated on:  2021-12-02

Show

Authored by:  Alfonso Murillo


This article shows how to enable the PHP cURL extension for it to be used in a server that uses an Ubuntu LAMP stack.

Procedure

Check the version of php your server is running on:

It would look as follows:

root@ubuntu:~# php -v
PHP 7.4.3 (cli) (built: Aug 13 2021 05:39:12) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
root@ubuntu:~# 

Note: For this exercise, PHP 7.4 is being used, the package that you will install needs to match the version of PHP your server is running on.

The installation will be made through apt so an optional recommended command before starting with the installation to make sure you obtain the last updated packages is:

Search for the curl package, you can use apt-cache to search for package in your source lists and using grep to filter the results.

root@ubuntu:~# apt-cache search php | grep curl
php-curl - CURL module for PHP [default]
php7.4-curl - CURL module for PHP
root@ubuntu:~#

For PHP 7.4 version you will need to install the cURL Extension for PHP using the following command:

$ sudo apt install php7.4-curl

Once installed, review the syntax to ensure the Apache can be restarted without issues.

Note: In case Apache is unable to restart properly, this could lead to downtime.

After the installation is completed you will need to restart the Apache server.

$ sudo service apache2 restart

Conclusion

After following the instructions above, you will be able to user cURL on an Ubuntu LAMP stack.

  • Installing a LAMP stack on Ubuntu 18.04

©2020 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

Hướng dẫn enable php-curl extension ubuntu

See license specifics and DISCLAIMER

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    CURL stands for Client URL. It is a Linux Terminal command which is used to transferring data from one server to another server. It is a free and open-source data transfer tool that uses the following protocols: IMAP, IMAPS, POP, POP3, POP3S, DICT, FILE HTTP, HTTPS, SMB, SMBS, SMTP, SMTPS, FTP, FTPS, TELNET, RTSP, RMTP, and TFTP.

    It displays a meter-like progress bar while running and indicating various parameters like the amount of transferred data, speed of data transfer and estimated time left.

    Following are the steps for the installation of PHP-CURL on your Ubuntu system:

    • Step 1: Install PHP libraries for the server by running the following command:
      $ sudo add-apt-repository ppa:ondrej/php

      Hướng dẫn enable php-curl extension ubuntu

    • Step 2: Then, update the server:
      $ sudo apt update

      Hướng dẫn enable php-curl extension ubuntu

    • Step 3: Now, install CURL.
      $ sudo apt install curl

      Hướng dẫn enable php-curl extension ubuntu

    • Step 4: You can check the version of curl installed by the command:
      $ dpkg -l curl

      Hướng dẫn enable php-curl extension ubuntu

    • Step 5: Once you have installed CURL on Ubuntu 18.04 PHP server, you need to restart your webserver on which PHP is running:

      If you are using Apache server then use either of the following commands to restart the server:

      $ sudo service apache2 restart

      or

      $ sudo /etc/init.d/apache2 restart

      Similarly, if you are using Nginx server, then use either of the following commands:

      $ sudo systemctl restart nginx

      or

      $ sudo /etc/init.d/nginx restart

    PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.