I had recently purchased a small computer to act as my development server but I also wanted it to act as second desktop machines. I have plenty of experience using Debian as a server, but I decided to try the new distribution from Ubuntu.
The install was pretty easy including getting PHP 5.1.2, Apache 2, and MySQL 5 installed using the familiar apt-get command. (I wish they had included php 5.1.4, but this wasn’t a deal breaker)
I was dismayed to find that they didn’t have a package for PDO extension (PHP Database Objects). So I installed the PDO via the pecl command:
bhiv@devserver:~# pecl install pdo
It downloaded, phpized, configured, compiled and installed just fine. The only thing I had to do was add the line:
extension=pdo.so
to the files:
/etc/php/apache2/php.ini
/etc/php/cli/php.ini
(and restart apache)
But what good was the PDO without a driver for a database, in my case MySQL. So I tried:
bhiv@devserver:~# pecl install pdo_mysql
It downloaded, phpized, then failed on the configure command with the error:
configure: error:
You’ve configured extension pdo_mysql, which depends on extension pdo,
but you’ve either not enabled pdo, or have disabled it.
After trying a number of ways to force it to install, trying to foce the dotdeb distribution to install I found the simplest solution was to manually download the package with the following commands:
bhiv@devserver:~# wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
bhiv@devserver:~# tar zxvf PDO_MYSQL-1.0.2.tgz
bhiv@devserver:~# cd PDO_MYSQL-1.0.2
bhiv@devserver:~# phpize
bhiv@devserver:~# vi configure
comment out lines 4163-4173
bhiv@devserver:~# ./configure
bhiv@devserver:~# make
bhiv@devserver:~# sudo make install
add the lines:
extension=pdo.so
extension=pdo_mysql.so
to the very bottom of the file.
bhiv@devserver:~# sudo vi /etc/php/apache2/php.ini
bhiv@devserver:~# sudo vi /etc/php/cli/php.ini
bhiv@devserver:~# sudo apache2ctl restart
Hopefully there will be a php-pdo package soon. But until then, this was the simplest way to get PDO installed on your new Ubuntu system.
The intro paragraph sets this post up for an entirely different story.
What did you think it would be about?
I was about to try out how this worked, but apparently phpize didn’t install by default. I did a quick search for phpize in the dapper release at packages.ubuntu.com, but didn’t get any results. What package needs to be installed for phpize?
Justin,
php5-dev provides phpize.
you might also need the mysql packages:
libmysqlclient15-dev
libmysqlclient15off
Cheers, worked a treat and saved me a bit of time. The best way to get phpize is to use the php5-dev package. Also I think sudo is needed on phpize in this case.
one additional package to install was “make” everything else looks to have worked just as documented above. Thanks.
Cheers mate, I had the same problem.
Hope a package is available soon!
when i do ./configure
error:
./configure: line 4144: syntax error near unexpected token `
Swegn,
Very strange. that line doesn’t have anything on it in my version. Make sure you are modifing PDO_MYSQL 1.0.2’s configure sript.
Thanks a lot Brent! Works as described.
Cheers,
Mark
See: http://pecl.php.net/bugs/bug.php?id=6117
Simple answer without going manual:
PHP_PDO_SHARED=1 pecl install PDO_MYSQL
Pingback: PHP with PDO_MySQL and error “SQLSTATE[HY000]: General error: 2036″: fixed at Joel’s Corner
Same trick worked for PDO_SQLite . I think pecl on ubuntu dapper have some sort of problem.
that was very useful, thanks 🙂
I was getting the error that mysql header files couldn’t be found.
I installed the mysql-server and dev packages for mysql and it worked just fine.
# apt-get install mysql-server
# apt-get install libmysqlclient14-dev
Hope this might be helpful for other too…
Adios,
Me
Surely there has to be a package somewhere for pdo ? I am not a ubuntu user but forced to use it at work and ubuntu being the number one distro around, I was hoping the end user should not go through compiling and installing stuff.
Its not that I don’t know how to compile stuff its just I did everything I “had to do” and it was failing with “You’ve configured extension pdo_mysql, which depends on extension pdo,
but you’ve either not enabled pdo, or have disabled it.”
I was actually trying to set it up on my colleagues box and it was a bit embarrassing when things don’t work.
Thanks for pointing out the lines to comment off but I still hope to find a repository which holds the package as it helps in automating stuff when you are “mass installing” applications on your servers.
cheers,
Jeffery
after pecl install pdo
i get message:
root@Luger:/etc/php5# 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
sh: phpize: command not found
ERROR: `phpize’ failed
can anyone help me???
Bob,
the php5-dev package provides phpize (or phpize5)
Thanks a lot. You saved my ass lol
I have recently wrote a article on my website regarding how to setup a php dev machine using ubuntu 7.04,
You can view this here http://www.theatons.com/blog/2007/07/01/ubuntu-install-php5-mysql-apache2-ssl-pdo-pdo_mysql/
I hope this helps other ubuntu’ers.
Pingback: Because I Learn » Blog Archive » Compile PDO drivers from source
Pingback: Not So Wise
Pingback: Being Linux admin - setting up virtual servers and Samba | ProDevTips - dev notes and tutorials
Thx. This helped me a lot. Now I have PDO and don’t need to adjust my scripts.
Regards
Pingback: A problem with instalation of pdo_mysql « e-notebook