Installing Postgres PDO driver on cPanel

cPanel offers two options for installing PDO – using EasyApache which can enable PDO and MySQL’s PDO driver or installing everything via PECL. Unfortunately, under PHP 5.3, the PECL installers don’t work, so if you need any other PDO drivers, you’re in a hole.

Luckily, you can install it manually.

Download the PDO driver from the PECL website. Extract the archive and CD into the directory.

wget http://pecl.php.net/get/PDO_PGSQL
tar -xzf PDO-PGSQL-1.0.2.tgz
cd PDO-PSQL-1.0.2/

Once this is done, run the standard commands for building a PHP extension.

phpize
./configure
make
make install

Once this is done, you can add the extension to php.ini.

cd /usr/local/lib/
vim php.ini
extension=pdo_pgsql.so

Finally, restart Apache and the Postgres driver should show up in your phpinfo() output.

Installing Mongo PHP driver on CentOS 6 cPanel

Once again, the PECL installer. In order to get the Mongo driver for PHP working, you need to install it manually.

mkdir mongo
cd mongo
wget https://github.com/mongodb/mongo-php-driver/zipball/master
unzip master
cd mongodb-mongo-php-driver-df8b217
phpize
./configure
make install

Add the extension to your php.ini file.

extension=mongo.so

Restart Apache, and Mongo should appear inf your phpinfo() output.

Install Memcache on CentOS 6 cPanel

Here is how to install Memcache for PHP on a CentOS 6 cPanel / WHM box. Some of the guides suggest that you need libevent (well, you do need libevent), though when I tried it, I already had it installed. But if you need it, yum will sort you out.

yum install libevent

Next, install memcache itself. Note that the package is called memcached.

yum install memcached

Of course, just installing it doesn’t mean that the daemon is running. So don’t forget to start it too!

/etc/init.d/memcached start

Finally, we need to add the PHP extension. Beware that the PECL installer on WHM won’t work! So you need to compile it manually from source. That isn’t too difficult though.

wget http://pecl.php.net/get/memcache
tar zxvf memcache
cd memcache-3.0.6
phpize
./configure
make
make install

And add the extension to your php.ini.

extension=memcache.so

Now restart Apache and a memcache section should appear in your PHP info.

Converting CVS to Git, with branches

There are quite a number of tools to convert a CVS repository to a Git repository out there. However, most of them don’t seem to be able to copy over the branches properly. A work around is to convert it to Mercurial first, then convert it to Git.

In this example I’m using a repository called RedDog.

First, we need to get Mercurial on the system.

yum install mercurial

Next we need to add the convert extension to the .hrc file. This might be a global file, or might be in your home directory, can’t quite remember.

[extensions]
hgext.convert=

Check out from CVS and convert to Mercurial.

cvs checkout RedDog
hg convert RedDog

This will create a Mercurial repository called RedDog-hg. Now we need to get hold of Fast Export.

git clone git://repo.or.cz/fast-export.git

Once we have the software we can initialise a new Git repository that we’re going to use and then CD into the folder.

git init RedDog-git
cd RedDog-git

Run the Fast Export tool, specifying the location of the Mercurial repository.

../fast-export/hg-fast-export.sh -r ../RedDog-hg

This will migrate everything into your new Git repository. If you run an ls -a you should see the .git folder, which you may want to rename to RedDog.git (something.git locations are actually just .git directories).

You may optionally also want to do a check out into that folder.

git checkout HEAD

However, you don’t have to – you can begin using it remotely without doing a local checkout.

ActiveRecord::ConnectionNotEstablished in Rails

I ran into this error while trying to get Ruby on Rails 3.1.1 which I installed from the Rails Installer to talk to MySQL. My stack is built from WAMP, so it might not have been as easily as it would be on a standlone MySQL installation.

Here is are the steps I took to fix it.

Edit Gemfile in project and add the following line.

gem 'mysql2', '< 0.3'

Rebuild the MySQL adapter with your version of MySQL.

gem uninstall mysql2
gem install mysql2 -- --with-mysql-config="C:/wamp/bin/mysql/mysql5.5.16/bin/mysql_config.pl"

Download the MySQL connector from the MySQL website.

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

Once you have the zip file, uncompress it and copy lib/libmysql.dll to the Ruby bin directory. Finally, go back to your Rails project and run the following command.

bundle install

I was finally then able to run a command such as the following.

rails generate model Something name:string

Without it throwing any errors up.

Install APD on CentOS 5

Here is how to install APD (Advanced PHP Debugger) on CentOS 5. Lets start by creating a directory for it to log files to.

cd /tmp
mkdir apd
chown apache:apache apd

We need to remove ioncube, or it will cause errors.

rpm -e php-ioncube-loader

Now we can install APD, via PECL.

pecl install apd

Add the following to php.ini.

[apd]
zend_extension=/usr/lib64/php/modules/apd.so
apd.dumpdir=/tmp/apd
apd.statement_tracing=0

My PHP binary was in a different location, so I had to alter the script too.

cd /usr/bin/
vim pprofp

Change /usr/local/bin to /usr/bin and save the file.

You also need to ensure PEAR is in your include path (/usr/share/pear) for the script to work.