By SteveEGL
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!
Hi there @SteveEGL,
If you are on an Ubuntu server you could do that by running the following command:
- sudo apt install php-gd
After that, you would need to restart your webserver:
- sudo systemctl restart apache2
- 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:
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
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.
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.
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();
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.