Close Menu
Technoracle
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    TechnoracleTechnoracle
    • Home
    • AWS
      • EC2
      • Lightsail
      • RDS
      • S3
    • Ubuntu
      • Ubuntu 20.04
      • Ubuntu 22.04
    • AI Tools
    • Web Hosting
    • WordPress
    • Tech News
    Technoracle
    Home - Ubuntu 22.04 - How to Install PHP GD on Ubuntu 22.04 [Easy Guide]
    Ubuntu 22.04

    How to Install PHP GD on Ubuntu 22.04 [Easy Guide]

    Also Compatible with Ubuntu 18.04, Ubuntu 20.04
    Rajesh ShivamBy Rajesh ShivamMay 2, 2023Updated:June 10, 2023No Comments4 Mins Read
    install PHP GD on Ubuntu
    install PHP GD on Ubuntu

    PHP GD library is a graphics library used to create dynamic images in PHP. By default, GD library is not installed in Ubuntu. If you want to use it, you need to install it first. In this article, we will guide you on how to install PHP GD on Ubuntu. The commands we will used to install PHP GD is compatible with most of the Ubuntu versions. All the commands listed here, were tested by us.

    Page Contents

    Toggle
    • PHP GD Library [What is, Why it is Important]
    • Prerequisites
    • Step-by-Step Guide to Install PHP GD on Ubuntu
    • Step 1: Update the Package List
    • Step 2: Install GD Library
    • Step 3: Verify Installation
    • Step 4: Check PHP GD Version
    • Step 5: Restart the Web Server
    • Uninstall PHP GD library from Ubuntu
    • Conclusion

    PHP GD Library [What is, Why it is Important]

    Before dive into the installation, let’s understand what PHP GD library is and why it is important. The PHP GD library is a graphics library and it allows developers to create and manipulate images dynamically in PHP. It provides functions to create images from scratch, modify existing images, and output them in various formats like PNG, GIF, and JPEG. PHP GD is also used in many image resizing tools.

    Prerequisites

    Before, start with the installation process, make sure that you have the following prerequisites:

    • A Ubuntu 18.04 or 20.04 server with sudo access
    • Apache or Nginx web server installed
    • PHP installed on the server

    Step-by-Step Guide to Install PHP GD on Ubuntu

    Follow these steps to install PHP GD library on Ubuntu

    Step 1: Update the Package List

    Before installing any new package, it is always recommended to update the package list. Run the following command to update the package list

    sudo apt update

    Step 2: Install GD Library

    To install the PHP GD on Ubuntu, run the following command:

    sudo apt install php-gd

    This command will install the GD library and all its dependencies.

    If you are installing for particular version such as PHP 7.4 or PHP 8.2, use the command by adding version number to the tail of PHP, for e.g: php7.4 or php8.4

    This command will install the PHP GD library on Ubuntu and all its dependencies.

    Step 3: Verify Installation

    To verify installation, you can check PHP version or alternatively you can a create a sample PHP file to verify PHP GD extension installation. Let’s create a PHP file and we name it php_extension_check.php, in the website document root directory with below code snippet.

    <?php
    // Create a 100x100 image
    $image = imagecreatetruecolor(100, 100);
    
    // Set the background color to red
    $red = imagecolorallocate($image, 255, 0, 0);
    imagefill($image, 0, 0, $red);
    
    // Output the image in PNG format
    header('Content-Type: image/png');
    imagepng($image);
    imagedestroy($image);
    ?>

    Save the file and navigate to http://websitename.com/test-gd.php in your web browser. If everything is set up correctly, you should see a 100×100 red square.

    Step 4: Check PHP GD Version

    To check the version of PHP GD installed on your system, run the following command:

    php -i | grep GD

    This will display information about the GD library, including the version number.

    Step 5: Restart the Web Server

    After installing the PHP GD library, you need to restart your web server to ensure that it make changes. You can do this by running the following command:

    sudo service apache2 restart

    or

    sudo service nginx restart

    depending on which web server you are using.

    Uninstall PHP GD library from Ubuntu

    If you ever need to uninstall PHP GD from Ubuntu system, you can do so by running the following command:

    sudo apt remove php-gd

    This command will remove the library and all its dependencies.

    Conclusion

    In this article, you have learnt how to install PHP GD on Ubuntu. The installation is very simple process that can be completed in a few easy steps. Once installed, you can use this library to create and manipulate images in your PHP applications. We hope that this article has been helpful to you.

    php extensions
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit
    Previous ArticleHow to Install PHP on Ubuntu 22.04 [Simple Guide]
    Next Article How to Enable PHP BCMath Extension in cPanel (3 Easy Quick Steps)
    Rajesh Shivam
    • LinkedIn

    Rajesh Shivam is a seasoned professional with expertise in AWS and Linux System Administration. With over 10 years of freelancing experience, he brings a wealth of knowledge to the table. Rajesh has a strong passion for technology and stays connected with the latest happenings in the field. His dedication and expertise make him a trusted resource for all things tech-related.

    Related Posts

    Ubuntu 22.04

    How to Install OpenLDAP on Ubuntu 22.04 or later version.

    Read More
    install php 8.3 on Ubuntu 22.04
    Ubuntu

    How to Install PHP 8.3 on Ubuntu 22.04(Easy Steps)

    Read More
    Install Odoo 17 on Ubuntu 22.04
    Ubuntu 22.04

    How to Install Odoo 17 on Ubuntu 22.04 (Easy Guide)

    Read More
    Add A Comment
    Leave A Reply Cancel Reply

    linux commands every user should know in 2025

    25 Must-Know Linux Commands Every User Should Master in 2025

    April 10, 2025
    TeamViewer and Ubuntu logos on gradient background – banner for how to install TeamViewer on Ubuntu 24.04 tutorial

    How to Install TeamViewer on Ubuntu 24.04 [Fast & Easy Steps]

    April 10, 2025
    Troubleshooting ‘Permission Denied (publickey)’ SSH error on a Linux server using secure terminal access

    Fix ‘Permission Denied (publickey)’ SSH Error on Linux [Step-by-Step Guide]

    April 8, 2025
    Blog banner showing Ubuntu logo, coding laptop, and icons for VS Code, Docker, and Git with the title 'Perfect Dev Setup in Ubuntu 24.04 – Step-by-step guide for developers' on a dark tech-themed background.

    How to Set Up the Perfect Development Environment on Ubuntu 24.04

    April 8, 2025

    Subscribe to Blog

    Enter your email address to subscribe to
    this blog and receive notifications of new posts by email.

    Facebook X (Twitter) Instagram Pinterest
    • Sitemap
    • Privacy Policy
    • Disclaimer
    • Term of Services
    © 2025 Technoracle

    Type above and press Enter to search. Press Esc to cancel.

    Click to Copy