[HOWTO] Get PDO and PDO_MYSQL working in PHP 5.2.5

GXX

Verified User
Joined
Mar 25, 2006
Messages
361
I just recently had to do this so I thought I might as well share. There are a few threads already with some info, but it's not entirely complete in my opinion.

Let's get started.

1) First off, issue this command to check your pear/pecl config:

Code:
pecl config-show
This will show you your config. Now if your /tmp is mounted noexec, skip the following and jump to step 2) now.

My /tmp is mounted noexec and instead of messing with it, I just changed the config to a local writable directory.

Your config-show should have:

Code:
PEAR Installer cache directory cache_dir        /tmp/pear/cache
PEAR Installer download        download_dir     /tmp/pear/cache
PEAR Installer temp directory  temp_dir         /tmp/pear/temp
Take note of the /tmp paths.

Type and execute:

Code:
pear config-set cache_dir /root/tmp/pear/cache
pear config-set download_dir /root/tmp/pear/cache
pear config-set temp_dir /root/tmp/pear/temp
Feel free to change the path to your own liking.

2) Now we will install pdo and pdo_mysql extensions.

Type and execute:

Code:
pecl install pdo
pecl install pdo_mysql
Now check your extensions directory to make sure they were installed. For my purposes they were in /usr/local/lib/php/extensions/no-debug-non-zts-20060613.

You should see pdo.so and pdo_mysql.so there.

3) Next you will need to re-compile PHP5. Before doing so, edit the configure file and add the following:

Code:
	--enable-pdo=shared \
	--with-pdo-mysql=shared \
	--with-sqlite=shared \
	--with-pdo-sqlite=shared \
Next recompile PHP with your method of choice.

4) Last step is to edit your /usr/local/lib/php.ini file.

Change your extension_dir to:

Code:
extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20060613
Change this path if yours is different.

Scroll down and add the following extensions:

Code:
extension=pdo.so
extension=pdo_mysql.so
Exit and save your php.ini.

5) Restart httpd and open up a phpinfo.php file. You should now see pdo/pdo_mysql entries.

TROUBLESHOOTING

A) If you are receiving the following warning/error:

Code:
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'pdo_mysql.so' in Unknown on line 0
Try restarting mysqld first.
 
Last edited:

ekaja

Verified User
Joined
Dec 9, 2007
Messages
46
Big Thank :)

Should....

Code:
cp /usr/local/lib/php/extensions/no-debug-non-zts-20060613/* /usr/local/lib/
and edit php.ini (/usr/local/lib/php.ini) to (for future :D )
Code:
extension_dir = "/usr/local/lib/"

:cool:
 

GXX

Verified User
Joined
Mar 25, 2006
Messages
361
That works too. That's why I said "Change this path if yours is different." :)
 

jazzy

Verified User
Joined
Feb 28, 2008
Messages
6
Location
Oslo, Norway
pdo_mysql.so: undefined symbol: php_pdo_declare_long_constant

After painstakingly trying to follow this (I'm a newbie so it took some time to find configure.php and learn how to edit it in vi), it seems like I've just messed it up. :confused:

Apache error log gives me this:
Code:
/usr/sbin/httpd: symbol lookup error: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so: undefined symbol: php_pdo_declare_long_constant
And when rebuilding php (./build php d) I get:
Code:
*** There was an error while trying to configure php. Check the configure.php file
My configure.php says:
Code:
#!/bin/sh
./configure \
        --with-apxs \
        --with-curl \
        --with-curl-dir=/usr/local/lib \
        --with-gd \
        --with-gd-dir=/usr/local \
        --with-gettext \
        --with-jpeg-dir=/usr/local/lib \
        --with-kerberos \
        --with-mcrypt \
        --with-mhash \
        --with-mysql=/usr \
        --with-pear \
        --with-png-dir=/usr/local/lib \
        --with-xml \
        --with-zlib \
        --with-zlib-dir=/usr/local/lib \
        --with-zip \
        --with-openssl \
        --enable-bcmath \
        --enable-calendar \
        --enable-ftp \
        --enable-pdo=shared \
        --with-pdo-mysql=shared \
        --with-sqlite=shared \
        --with-pdo-sqlite=shared \
        --enable-magic-quotes \
        --enable-sockets \
        --enable-track-vars \
        --enable-mbstring \
        --enable-memory-limit \
Any help at all would be highly appreciated, I'd love to work with PDO/MySQL.

Erik
 

GXX

Verified User
Joined
Mar 25, 2006
Messages
361
What version of PHP?

Are you using customapache or custombuild?
 

GXX

Verified User
Joined
Mar 25, 2006
Messages
361
Missed his mention of configure.php specifically, thanks for picking that up.

Jazzy - did pdo and pdo-mysql install correctly to begin with?
 

jazzy

Verified User
Joined
Feb 28, 2008
Messages
6
Location
Oslo, Norway
GXX - yes, pdo and pdo-mysql did install correctly the first time.
I must admit that the first time I tried to get things working with just adding this to php.ini (after installing pdo-mysql, but hadn't found configure.php by the time...):
Code:
extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20060613
and
Code:
extension=pdo.so
extension=pdo_mysql.so
Then I had to acknowledge that the *nix world (I've only set up apache/mysql/php on win before) really demanded that you know what you're doing, so google and this forum is your best friend. I found configure.php, managed to put in
Code:
--enable-pdo=shared
--with-pdo-mysql=shared,/usr/local/mysql
--with-sqlite=shared
--with-pdo-sqlite=shared
then rebuilt php, got error messages mentioned before, removed the ,/usr/local/mysql from this sentence: --with-pdo-mysql=shared,/usr/local/mysql
tried again to rebuild php, but alas, to no avail.

I read the bug report mentioned by smtalk, but can't find anything there that I haven't tried. :(
Ideas, anyone?
 

GXX

Verified User
Joined
Mar 25, 2006
Messages
361
Here's my configure.php_ap2:

Code:
#!/bin/sh
./configure \
        --with-apxs2 \
        --with-curl \
        --with-curl-dir=/usr/local/lib \
        --with-gd \
        --with-gd-dir=/usr/local/lib \
        --with-gettext \
        --with-jpeg-dir=/usr/local/lib \
        --with-kerberos \
        --with-openssl \
        --with-mcrypt \
        --with-mhash \
        --with-mysql=/usr \
        --with-pear \
        --with-png-dir=/usr/local/lib \
        --with-xml \
        --with-zlib \
        --with-zlib-dir=/usr/local/lib \
        --with-zip \
        --enable-bcmath \
        --enable-calendar \
        --enable-ftp \
        --enable-magic-quotes \
        --enable-sockets \
        --enable-track-vars \
        --enable-mbstring \
        --enable-memory-limit \
        --enable-pdo=shared \
        --with-pdo-mysql=shared \
        --with-sqlite=shared \
        --with-pdo-sqlite=shared
I'm running apache 2.0.63 with php 5.2.5 using customapache. I assume you are using apache 1.3.x? What version of PHP are you compiling as well?
 

jazzy

Verified User
Joined
Feb 28, 2008
Messages
6
Location
Oslo, Norway
Eureka!

Solution found!
But, for those of you finding yourself in the same situation:

I got completely lost, whatever I did. I got this message via DA's Service Monitor when I tried to restart apache:
/sbin/service httpd start 2>&1
Then I tried restarting via SSH, getting this error:
Starting httpd:
Syntax error on line 17 of /etc/httpd/conf/httpd.conf
Cannot load /usr/lib/apache/libphp5.so into server
Tried to rebuild everything, but finally gave up and followed this advice to get everything up and running again:
http://www.directadmin.com/forum/showpost.php?p=117790&postcount=2

So, I'm now using custombuild in stead of customapache. I found my php conf (configure.php5) file here:
/usr/local/directadmin/custombuild/configure/ap2
and in order to get pdo working I filled in with the necessary lines:
--enable-pdo=shared \
--with-pdo-mysql=shared \
--with-sqlite=shared \
--with-pdo-sqlite=shared \
Then changed my php.ini file according to the guidelines in this How-To, and Voilà! I'm happy, and so are my clients (mostly for getting their sites up and running again...). Dunno what initially went wrong, but if you go the same road as I did, don't take any shortcuts. Good luck! :)

BTW: thx for replying, GXX and smtalk!
 

bjfield

New member
Joined
Mar 31, 2008
Messages
1
Invalid library when restarting Apache

All the .so libraries installed fine. I moved them to /usr/local/lib for testing and didn't move them back, so don't be thrown by the path in the error messages below. I also updated the extension_dir to match. PHP5 recompiled and runs fine as long as I comment out the extension=pdo.so and extension=pdo_mysql.so lines in PHP.ini.

Starting httpd: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'pdo.so' in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/pdo_mysql.so' - /usr/local/lib/pdo_mysql.so: undefined symbol: php_pdo_get_dbh_ce in Unknown on line 0

Thanks for any help!

UPDATE: I had to restart mysqld.
 
Last edited:

klemens

Verified User
Joined
Aug 15, 2007
Messages
22
i have do everything that is in this howto, but i get this error when restarting/starting apache.

PHP Warning: Module 'PDO' already loaded in Unknown on line 0
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'pdo_mysql.so' in Unknown on line 0
 

webguy

Verified User
Joined
Apr 13, 2005
Messages
41
Location
Best, Netherlands
Error at first step

When I do the first step, I get the following:

pecl install pdo
downloading PDO-1.0.3.tgz ...
Starting to download PDO-1.0.3.tgz (52,613 bytes)
.............done: 52,613 bytes
12 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
/usr/local/bin/phpize: /tmp/pear/cache/PDO-1.0.3/build/shtool: /bin/sh: bad interpreter: Permission denied
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.

ERROR: `phpize' failed

Do you have any suggestion what to do now?
 

GXX

Verified User
Joined
Mar 25, 2006
Messages
361
It sounds like your /tmp is mounted as noexec.

Use the commands in step 1) to change your /tmp path and then re-run the install.
 

FAF

Verified User
Joined
Apr 1, 2006
Messages
87
Location
CPH, Denmark
Just Solved my problem, while writing this..

Hi

I cannot load PDO_MYSQL.SO??

Running CentOS 4
Apache 1.3.34
DirectAdmin 1.31.5
MySQL 4.1.11
PHP 5.2.5

Installed like this:
- installed: PHP_PDO_SHARED=1 pecl install PDO
- installed: PHP_PDO_SHARED=1 pecl install PDO_MYSQL
- build php
-- had to install autoconf, freetype and iconv, then PHP5.2.5 compiled fine.

Changed extensions dir path in php.ini, added the extensions.

extension=pdo.so loads fine.
extension=pdo_mysql.so cannot load, actually crashes apache.

Tried to put the pdo extensions in /usr/local/lib that didn't change a thing.

Then I ran:
1. pecl uninstall PDO_MYSQL
2. PHP_PDO_SHARED=1 pecl install PDO_MYSQL

...and following result came up, at the end of the log:
-----------------------------------------------------------------------
running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2" install
Installing shared extensions: /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local/lib/php/extensions/no-debug-non-zts-20060613/
running: find "/var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2" -ls
573852 4 drwxr-xr-x 3 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2
623789 4 drwxr-xr-x 3 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr
623818 4 drwxr-xr-x 3 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local
623819 4 drwxr-xr-x 3 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local/lib
623820 4 drwxr-xr-x 3 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local/lib/php
623821 4 drwxr-xr-x 3 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local/lib/php/extensions
623822 4 drwxr-xr-x 2 root root 4096 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local/lib/php/extensions/no-debug-non-zts-20060613
623823 1152 -rwxr-xr-x 1 root root 1175295 Apr 16 16:27 /var/tmp/pear-build-root/install-PDO_MYSQL-1.0.2/usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so'
install ok: channel://pecl.php.net/PDO_MYSQL-1.0.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=pdo_mysql.so" to php.ini
-----------------------------------------------------------------------
I then activate the dam* extension=pdo_mysql.so again, hoping....

I restart MySQL.... and Apache, and you know what........ it actually works.

From phpinfo: PDO drivers: sqlite2, sqlite, mysql running.

So it was just, in my case, to reinstall PDO_MYSQL

Just took me 4 hours *grin*

/FAF
 

sky

Verified User
Joined
Nov 12, 2004
Messages
338
Hello

Thanks for this little HOWTO, works fine for me on a fedora core 6 with PHP 5.2.6 and MySQL 5

Sky
 

indirectadmin

New member
Joined
May 6, 2008
Messages
3
.......

Let's get started.

1) First off, issue this command to check your pear/pecl config:

Code:
pecl config-show
I'm a newby: where or how should I enter this code ????

And....

I host some sites with dvwebhost.nl. I wrote them that I get an PDO error message (with trying to install Magenta) but they answer that it is loaded. What should I write them to get them acknowledge the problem?
 
Last edited:

sky

Verified User
Joined
Nov 12, 2004
Messages
338
Hello

To check if PDO is loaded, create a php file and do a echo phpinfo(); and check if PDO is there.

Sky
 

Emk

New member
Joined
May 8, 2008
Messages
1
I'm getting a few errors when I try to install pdo and pdo_mysql

Code:
dedi07# pecl install pdo
pecl/PDO requires PHP (version >= 5.0.3), installed version is 4.4.8
No valid packages found
install failed
dedi07# pecl install pdo_mysql
pecl/PDO_MYSQL requires PHP (version >= 5.0.3), installed version is 4.4.8
pecl/PDO requires PHP (version >= 5.0.3), installed version is 4.4.8
No valid packages found
install failed
System information:
FreeBSD 6
Apache 2.0.63
PHP4 and PHP5

When I look at my info.php5 I see that pdo_sqlite and pdo_sqlite2 are installed, but it seems that pecl only sees PHP4 installed and therefore I can't install the modules.

Does any of you know a solution for this?
 
Top