GD Library extension not available with this PHP installation Ubuntu Nginx
When you encounter the error GD library extension not available with this PHP installation while running a Laravel application on Ubuntu, the root cause is almost never a file system permission issue, despite what the initial symptoms might suggest. You mentioned setting your upload directory to 777 permissions; while that grants read/write/execute access to everyone, it does not install the GD library itself. PHP and its extensions operate in memory, separate from the static files sitting on your disk.
The error message explicitly states that the PHP interpreter cannot find the GD module loaded during runtime. This is a configuration or installation problem at the system level, not an application-level bug. If you attempt to use image manipulation featuresâsuch as Image::make($path)->fit() in Laravel's Blade directives or storage controllersâthe server will throw a Class 'Gd' not found exception because the underlying C extension is missing from the PHP build.
Diagnosing the Environment
Before attempting to fix the issue, verify exactly which PHP installation your Nginx worker processes are using. On Ubuntu 14.04, multiple PHP versions often coexist (e.g., php5.6, php7.0, or php-fpm pools). The binary executing your code might be different from the one you installed extensions for.
Run the following command to confirm your current PHP path and version:
php -i | grep "Loaded Extensions"
If this output is empty or lists standard modules like Core, but lacks gd or exif, the extension is indeed missing. You can also check specifically for GD:
php -m | grep gd
If this returns nothing, you have confirmed that the extension is not loaded. Note that simply installing the package on Ubuntu does not automatically enable the module in your specific PHP installation if multiple versions are present.
Installing the Missing Extension
On a standard Ubuntu 14.04 (Trusty Tahr) setup using the official repositories, you can install the GD library by updating your package lists and installing the specific PHP GD package that matches your version:
sudo apt-get update
sudo apt-get install php5-gd php5-curl php5-mbstring
If you are using a specific PHP-FPM setup (common in production Laravel environments), ensure you also install the corresponding FPM packages:
sudo apt-get install php5-fpm php5-gd
After installation, do not restart the Nginx server immediately. You must restart the PHP-FPM service or reload the configuration to pick up the new extensions. The exact command depends on your init system, but usually:
sudo service php5-fpm restart
Or, if you are using systemd (less common on 14.04 but possible):
sudo systemctl restart php5-fpm
Verifying the Fix
Once the service has restarted, re-run your Laravel application and attempt the file upload or image manipulation action again. If the error persists, check your php.ini configuration to ensure the module is not being explicitly disabled:
grep -i "extension=gd" /etc/php5/mods-available/*
On Ubuntu with separate pool configurations, you might need to create a symbolic link to enable the extension in your specific PHP-FPM pool. Create the necessary symlink:
sudo ln -s /etc/php5/mods-available/gd.ini dist/
Replace dist/ with the path defined in your php-fpm.conf or the specific pool file (e.g., /etc/php5/fpm/pool.d/www.conf). The exact location depends on whether you are using PHP 5.4, 5.6, or another variant. Verify that Nginx is passing requests to the correct FastCGI socket and that the PHP process has access to the updated configuration.
Security Considerations
Finally, address the 777 permissions you mentioned for the public/uploads folder. While this resolved nothing regarding the GD error, it presents a significant security vulnerability. Allowing any user on the system (including www-data, other services, or compromised users) full read/write/execute access to your uploads directory violates the principle of least privilege.
Instead of setting permissions globally:
- Create the directory with restricted ownership:
sudo chown -R www-data:www-data public/uploads. - Set the base permission to
755for security:chmod 755 public/uploads. - If your application requires group write access (e.g., for multiple web workers), set the group bit:
chmod 775 public/uploadsand ensure the group matcheswww-data.
This ensures that even if the GD extension works, attackers cannot upload malicious scripts to arbitrary locations within that directory.
