How to Install PHP GD Support to Apache on Ubuntu

How to Install PHP GD Support to Apache on Ubuntu

How to Install PHP GD Support for Apache on Ubuntu

Works with Ubuntu 18.04, 20.04, 22.04, 24.04+ and supports PHP 7.x / 8.x

Step 1: Update Your Package List

Start by updating your system's package index:

sudo apt update

Step 2: Install Apache (If Not Already Installed)

If you haven’t installed Apache yet:

sudo apt install apache2 -y

You can check if Apache is running:

sudo systemctl status apache2

Step 3: Install PHP (If Not Already Installed)

To install PHP (example with PHP 8.1, change if needed):

sudo apt install php libapache2-mod-php -y

Check PHP version:

php -v

Step 4: Install PHP GD Library

Install the PHP GD module:

sudo apt install php-gd -y

If you’re using a specific PHP version (like PHP 8.1), use:

sudo apt install php8.1-gd -y

Step 5: Restart Apache

After installing the GD module, restart Apache to apply changes:

sudo systemctl restart apache2

Step 6: Verify GD Installation

To confirm GD is enabled, create a phpinfo() file:

sudo nano /var/www/html/info.php

Add this content:

<?php phpinfo(); ?>

Then visit:
http://localhost/info.php
Look for "GD Support" in the browser page.

If you see it listed, GD is successfully installed!

(Optional) Step 7: Remove the Test File

For security, delete the info.php file after testing:

sudo rm /var/www/html/info.php

Done!

You’ve now installed PHP GD support on Apache in Ubuntu! You’re ready to process images using PHP functions like imagecreatefromjpeg(), imagepng(), imagecopyresampled(), etc.

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close