I'm changing shared hosting providers for my websites and the sites I manage for clients as Salt City Tech. Most of the sites are basic websites powered by PHP, share a common code base, and store data in MySQL databases. But I've also been taking advantage of the situation to transition the sites from MySQL to SQLite. There are a lot of things that annoy me about SQLite (such as allowing NULLs in primary-key columns, ignoring foreign key constrains, and incomplete ALTER TABLE support) and a few things that I think are pretty awesome (such as user-defined functions in PHP). Pragmatically speaking, SQLite will be more convenient for deployment to and backup from the shared hosting environment and the sites' simple storage requirements fall exactly in SQLite's sweet-spot.
The transition hasn't been terribly difficult... the biggest obstacle has been configuring a development environment that adequately mirrored the shared hosting deployment environment. I happened to have a cloned virtual CentOS 5.3 image at my disposal so I started with that, but the hosting provider supports SQLite v2 (ancient!), which's storage format is incompatible with the newer version 3 in CentOS. The search engines didn't offer me much help in finding a packaged SQLite2 solution on CentOS that would meet my needs, so I figured I'd post a few notes in case someone else may find them helpful.
Obtain the sqlite-2 RPM for CentOS from RPMForge repository (in case you want to work with the database files directly):
The transition hasn't been terribly difficult... the biggest obstacle has been configuring a development environment that adequately mirrored the shared hosting deployment environment. I happened to have a cloned virtual CentOS 5.3 image at my disposal so I started with that, but the hosting provider supports SQLite v2 (ancient!), which's storage format is incompatible with the newer version 3 in CentOS. The search engines didn't offer me much help in finding a packaged SQLite2 solution on CentOS that would meet my needs, so I figured I'd post a few notes in case someone else may find them helpful.
Obtain the sqlite-2 RPM for CentOS from RPMForge repository (in case you want to work with the database files directly):
wget http://dag.wieers.com/rpm/packages/sqlite/Install sqlite using the -i and --force options (do not use -U so you do not replace sqlite3):
sqlite-2.8.17-1.el5.rf.i386.rpm
rpm -i --force sqlite-2.8.17-1.el5.rf.i386.rpmInstall the php-devel package so phpize and phpconfig are available:
yum install php-develObtain the source RPM for PHP (CentOS installs 5.1.6--yuck! Now I remember why I hate using packages for important software):
wget ftp://mirror.switch.ch/pool/3/mirror/centos/5.3/os/SRPMS/Extract PHP from the SRPM:
php-5.1.6-23.el5.src.rpm
rpm2cpio php-5.1.6-23.el5.src.rpm | cpio -id php-5.1.6.tar.gzUncompress the archive:
tar zxvf php-5.1.6.tar.gzBuild the sqlite extension using the standard phpize, ./configure, make routine:
cd php-5.1.6/ext/sqliteInstall the extension:
phpize
./configure
make
cp modules/sqlite.so /usr/lib/php/modules/Even though it's been obsoleted by version 3 for almost 6 years now, version 2 of SQLite works fine for my needs here. And God forbid I have to migrate the sites again or the provider upgrades, upgrading my code base is as simple as this:
echo extension=sqlite.so > /etc/php.d/sqlite2.ini
sqlite site.db.old .dump | sqlite3 site.db
for f in $(ls *php); do
sed -i 's/new SQLiteDatabase/new SQLite3/g' $f
sed -i 's/fetch\(SQLITE_ASSOC\)/fetchArray\(SQLITE3_ASSOC\)/g' $f
done
Helpful, thanks!
ReplyDeleteVery helpful. Thank you.
ReplyDeleteI'm using PHP 5.2.10 from the CentOS-5 Testing
repositories at http://dev.centos.org/centos/5/testing/ and your procedure worked perfectly to add sqlite2 to my CenOS-5.5 box. The one hiccup was that the php distro in the 5.2.10 SRPM is a .bz2 rather than a .gz file, and I had to run cpio -t to find it when the tarball didn't extract.
There is a great tutorial on installing sqlite, sqlite3 and mcrypt on Centos here: http://www.exteon.ro/en/articles/php/compile-extensions
ReplyDeleterunning rpm -qpl php-5.1.6-23.el5.src.rpm can show you all the files inside the SRPM. Once you identify what file you want you can provide it to cpio -id.
ReplyDeleteThat was really interesting to know about.It was really helpful.Thank you !
ReplyDeleteSide note -> extra information to help others:
ReplyDelete1. This post assumes you have a compatible compiler like gcc (many production systems do not to prevent people from compiling malicious code), so you may need to install a compiler before you run your configure or make commands.
2. If after following this blog this you get this error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/sqlite.so' - /usr/lib/php/modules/sqlite.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
when you start PHP. All that you need to do is install php-pdo (yum install php-pdo) and this will fix the problem. (After you restart apache /etc/init.d/httpd restart)
Hope this helps others out... or even me if I need to do it again. Cheeers.
Thank you very much! I was able to loosely follow your directions on Ubuntu Server 12.04. You saved me from having to redo my old SQLite2 PHP code. Once again, thank you very much!
ReplyDelete