Report this

What is the reason for this report?

How to install GD library extension on my deployed Laravel app

Posted on November 7, 2020

So i’m getting an error when i’m trying to upload an image.

Error: gd library extension not available with this php installation

How to install GD library extension on my Laravel app.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @SteveEGL,

If you are on an Ubuntu server you could do that by running the following command:

  1. sudo apt install php-gd

After that, you would need to restart your webserver:

  • In case that you are using Apache run:
  1. sudo systemctl restart apache2
  • In case that you are using Nginx run:
  1. sudo systemctl restart nginx

Regards, Bobby

The error you’re seeing indicates that the GD library, which is commonly used in PHP applications for handling image processing tasks, is not installed or enabled on your server. Installing the GD library on a server where you are running a Laravel application involves a few steps. Here’s how you can install the GD library extension on an Ubuntu server, which is common for Laravel applications:

Step 1: Install GD Library for PHP

First, you need to install the GD library. The command to do this will depend on the version of PHP you are running. You can check your PHP version by running:

php -v

Once you know your PHP version, install the GD library using the appropriate command. For example, if you are using PHP 7.4, you would use:

sudo apt update
sudo apt install php7.4-gd

Replace 7.4 with the version of PHP you are using. If you are using PHP 8.0, the command would be:

sudo apt install php8.0-gd

Step 2: Enable the GD Extension

After installing the GD library, you will need to ensure that it’s enabled. Usually, the installation process automatically enables the extension, but you can check if it’s enabled by looking for it in your php.ini file or by running:

php -m | grep gd

If it outputs gd, then the extension is enabled. If not, you might need to manually enable it by adding or uncommenting the following line in your php.ini file:

extension=gd

The php.ini file is typically located in /etc/php/8.1/apache2/php.ini or /etc/php/8.1/cli/php.ini, depending on whether PHP is running as an Apache module or CLI. Again, replace 8.1 with your PHP version.

Step 3: Restart Your Web Server

To make sure your PHP configuration is reloaded with the GD extension enabled, restart your web server. For Apache, you would use:

sudo systemctl restart apache2

For Nginx (if you’re using PHP-FPM):

sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx

Replace 7.4 with your version of PHP.

Step 4: Verify Installation

To verify that the GD library is properly installed and recognized by PHP, you can create a small PHP file (e.g., info.php) that calls the phpinfo() function. This function outputs information about your PHP installation, including enabled extensions. Access this file in a web browser and check if the GD library is listed under the extensions section.

<?php
phpinfo();

Step 5: Laravel Configuration

No additional Laravel-specific configuration should be needed after installing the GD library. However, ensure your Laravel application has the necessary permissions to work with files and directories if it processes images.

By following these steps, you should be able to resolve the error related to the GD library in your Laravel application and continue with your image uploading features.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.