Today went to use GD within PHP and a simple check of phpinfo() showed it wasn't installed, but running php -m show that both (pdo_mysql and gd) where installed.

Does anyone know how to sort this?

- PHP Modules 
ctype
curl
date
dom
exif
filter
ftp
gd <--
hash
iconv
json
ldap
libxml
mbstring
mysql
mysqli
odbc
openssl
pcre
PDO
pdo_mysql <--
pdo_sqlite
posix
Reflection
session
SimpleXML
sockets
SPL
SQLite
standard
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zlib

I am running a Mac OSX 10.5.8 on the inbuild/bundled Apache/PHP setup that came with leopard php versions is 5.8.11 and its Apache 2.2 (i think)

Dani AI

Generated

Short answer: the output from php -m is coming from the CLI PHP binary, while phpinfo() shows the PHP instance Apache is running. Those are often different SAPIs with different php.ini files and loaded-extension lists, so seeing GD and pdo_mysql in the terminal but not in phpinfo() is a classic CLI-vs-Apache mismatch. (stackoverflow.com)

Do these checks (they’ll point exactly at which php and which php.ini Apache is using):

which -a php
php -v
php --ini
php -m

# create a web-visible test page (remove it afterwards)
# info.php contents:
<?php phpinfo(); ?>

Open that info.php in a browser and look for “Server API”, “Loaded Configuration File”, and “Additional .ini files parsed”. php --ini / php -i show the CLI config; phpinfo() shows the web config. (php.net)

If Apache’s PHP is missing GD/PDO, enable them in the php.ini that phpinfo() lists (or put small .ini files in the “scan” directory). Typical fixes: ensure extension_dir points to the directory containing the .so files (or add extension=gd.so / extension=pdo_mysql.so lines), save, then restart Apache:

sudo apachectl restart
# then check Apache error log for startup/load errors:
sudo tail -n 200 /var/log/apache2/error_log

If an extension won’t load you’ll often see a dependency or binary-mismatch error in the logs. After a successful restart the extensions should appear in phpinfo(). (php.net)

Extra tips: use which -a php and apachectl -V to find multiple installs and the ServerRoot; make a backup copy of any php.ini before editing; delete the temporary phpinfo page when finished because it exposes server details. (developer.wordpress.org)

(Direct testing of GD as suggested — a tiny PHP script that creates and outputs an image — is a good final verification once the extension is enabled.)

Recommended Answers

All 4 Replies

Well, let me ask the simple question: Does GD work? Can you make a simple image with it or does it fail to initialize?

Well, let me ask the simple question: Does GD work? Can you make a simple image with it or does it fail to initialize?

No, classes aren't recognised and images don't appear, so i'm presuming i have more than 1 installation of php on my laptop - how can i tell if thats the case? i've tried installing installing but it fails post install.

Hmm, well I'm no Mac expert, so bear with me here. Look in the Mac's equivalent to Program Files and see if there are multiple installations of PHP. Maybe the folders have different names? If that doesn't work, you can always check the Mac's list of processes to see if there are multiple PHP's running. You'd have to ask a Mac expert to be sure, because all I can give you is Windows equivalents!

Hmm, well I'm no Mac expert, so bear with me here. Look in the Mac's equivalent to Program Files and see if there are multiple installations of PHP. Maybe the folders have different names? If that doesn't work, you can always check the Mac's list of processes to see if there are multiple PHP's running. You'd have to ask a Mac expert to be sure, because all I can give you is Windows equivalents!

I've had a root around and found only one php.ini file - so i'm assuming that means i only have 1 installation of php.

this is really annoying - all i wanted was to add GD to apple's pre-installed PHP (which i had been in the pass but its forgotten) as i see no point in installing a MAMP if i have them all there already.

I think Steve Jobs hates me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.