back       next

sandip's blog

php with mysqlnd support

You can now get the latest PHP with mysqlnd (MySQL Native Driver) support via remis' yum repository as mentioned in PHP-5.3,-zts-and-mysqlnd. The blog mentions that this is enabld in php-zts. However, no php-pecl extension are available and neither are some of the extensions thread safe. So I went about rebuilding php package from source for mysqlnd support.

  1. Download the source php rpm from http://rpms.famillecollet.com/SRPMS/ . Note, I have used php-5.3.2 which is the latest as of this writing.
  2. Install and apply the below diff patch to the spec file via `patch -p0 < {new_patch_file}` where "new_patch_file" has the below contents:

    --- php-5.3.2-remi.spec.orig 2010-03-11 23:07:04.000000000 -0600
    +++ php-5.3.2-remi.spec 2010-03-11 23:36:03.000000000 -0600
    @@ -24,6 +24,7 @@
    %global phpversion 5.3.2

    # Optional components; pass "--with mssql" etc to rpmbuild.
    +%define with_mysqlnd %{?_with_mysqlnd:1}%{!?_with_mysqlnd:0}
    %define with_oci8 %{?_with_oci8:1}%{!?_with_oci8:0}
    %define with_ibase %{?_with_ibase:1}%{!?_with_ibase:0}
    %if %{?rhel}%{?fedora} > 4
    @@ -677,6 +678,11 @@
    %if %{?fedora}%{?rhel:99} >= 10
             --with-system-tzdata \
    %endif
    +%if %{with_mysqlnd}
    +        --with-mysql=shared,mysqlnd \
    +        --with-mysqli=shared,mysqlnd \
    +        --with-pdo-mysql=shared,mysqlnd \
    +%endif
    $*
    if test $? != 0; then
       tail -500 config.log
    @@ -704,8 +710,13 @@
           --enable-dba=shared --with-db4=%{_prefix} \
           --with-xmlrpc=shared \
           --with-ldap=shared --with-ldap-sasl \
    +%if %{with_mysqlnd}
    +      --with-mysql=shared,mysqlnd \
    +      --with-mysqli=shared,mysqlnd \
    +%else
           --with-mysql=shared,%{_prefix} \
           --with-mysqli=shared,%{_bindir}/mysql_config \
    +%endif
    %ifarch x86_64
           %{?_with_oci8:--with-oci8=shared,instantclient,%{_libdir}/oracle/%{oraclever}/client64/lib,%{oraclever}} \
    %else
    @@ -725,7 +736,11 @@
           --enable-fastcgi \
           --enable-pdo=shared \
           --with-pdo-odbc=shared,unixODBC,%{_prefix} \
    +%if %{with_mysqlnd}
    +      --with-pdo-mysql=shared,mysqlnd \
    +%else
           --with-pdo-mysql=shared,%{_prefix} \
    +%endif
           --with-pdo-pgsql=shared,%{_prefix} \
           --with-pdo-sqlite=shared,%{_prefix} \
           --with-pdo-dblib=shared,%{_prefix} \
    @@ -756,6 +771,16 @@
           --with-recode=shared,%{_prefix}
    popd

    +%if %{with_mysqlnd}
    +without_shared="--without-gd \
    +      --disable-dom --disable-dba --without-unixODBC \
    +      --disable-xmlreader --disable-xmlwriter \
    +      --without-sqlite \
    +      --disable-phar --disable-fileinfo \
    +      --disable-json --without-pspell --disable-wddx \
    +      --without-curl --disable-posix \
    +      --disable-sysvmsg --disable-sysvshm --disable-sysvsem"
    +%else
    without_shared="--without-mysql --without-gd \
           --disable-dom --disable-dba --without-unixODBC \
           --disable-pdo --disable-xmlreader --disable-xmlwriter \
    @@ -764,6 +789,7 @@
           --disable-json --without-pspell --disable-wddx \
           --without-curl --disable-posix \
           --disable-sysvmsg --disable-sysvshm --disable-sysvsem"
    +%endif

    # Build Apache module, and the CLI SAPI, /usr/bin/php
    pushd build-apache

  3. Package with:
    rpmbuild -bb --with mysqlnd --define "rhel 5" SPECS/php-5.3.2-remi.spec
    
  4. To install via yum, change to the directory where rpms are located and recreate the repodata via:
    createrepo .

  5. Note: you may need to install some of the missing dependent devel packages. I used a combination of base, epel and remi repository to install the dependencies.

In place variable substitution with AWK

The content of the input file becomes stdin for rm and awk. rm ignores the input and removes the file, but its file descriptor remains open until both commands, rm and awk is complete. AWK process this "nameless" file and creates a new file:

  { rm $CSV_FILE && awk -F',' -v stid="$ST_ID" '$1 ~ stid {gsub(/&/,"",$7)}1' > $CSV_FILE; } < $CSV_FILE

  • "-v" sets the awk variable that is passed in via shell script variable.
  • "gsub" replaces with "" all occurrence of & in the 7th field. Use "sub" for single/first occurrence substitution or GNU Awk's gensub for more articulated substitutions.
  • "1" is a shortcut which means print the current record:

pecl runkit with php-5.2.x

As of writing, the current pecl runkit-0.9 package does not compile with PHP 5.2+ . Below is how I got the latest installed from svn trunk on CentOS-5.4 with php-5.2.9.

  • Install runkit:
          svn co http://svn.php.net/repository/pecl/runkit/trunk/
          cd trunk
          phpize
          ./configure
          make
          make install

  • Create "/etc/php.d/runkit.ini":
          extension=runkit.so

  • Restart apache and validate with phpinfo.

Note: you would need php-pear and php-devel installed already.

y2k10 bug in SpamAssassin

If running 3.2.x version of SpamAssassin... (check with `spamassassin -V`) there is a y2k10 bug in the FH_DATE_PAST_20XX rule, causing all mails getting an extra 3.4 points:

Reference: SA Bugzilla – Bug 6269

The fix mentioned is to update the rules using `sa-update` and restart spamd. The rules in the update directory at /var/lib/spamasassin will get updated.

With the fix applied you should no longer see FH_DATE_PAST_20XX in the logs.

For a manual fix, update /usr/share/spamassassin/72_active.cf and change:

header   FH_DATE_PAST_20XX      Date =~ /20[1-9][0-9]/ [if-unset: 2006]

to:

header   FH_DATE_PAST_20XX      Date =~ /20[2-9][0-9]/ [if-unset: 2006]

Related reading on sa-update: SpamAssassin RuleUpdates

Resolving df and du reporting different output

If df and du give different output of disk usage. Then, most probably it is due to "open file descriptors".

Run `ls +L1` to get a listing of open files that have been unlinked or removed. Note the file size and kill or restart the respective service.

Reference: walkernews.net

HP Deskjet F2430 printing in Ubuntu-9.10

Although the printer HP Deskjet F2430 was automatically detected upon usb connection to my ubuntu-9.10 desktop, the 3.9.8 version of hplip that came via apt repository did not quite get printing to work.

I headed off to hplipopensource.com, downloaded and installed the latest driver (version 3.9.12 as of this writing) and got the all-in-one printer to work just following the install wizard.

I have yet to test the scanner... but that's going to be another update.

Extending ext3 partition

*** Make sure you have a back up prior to proceeding. ***

  1. Boot into rescue mode.
  2. Unmount partition if mounted and check disk:
    umount /dev/sda1
    e2fsck -vn /dev/sda1

  3. Delete /dev/sda1 partition and create a bigger one with fdisk:
    fdisk /dev/sda

  4. Recreate the partition /dev/sda1 with the starting point at the default location and the ending point at highest possible cylinder. (Note: if you are extending by merging two partitions, the data in the second partition is lost so make sure to backup data you need.)
  5. Run partprobe and resize2fs utility with no size arguments:
    partprobe /dev/sda
    resize2fs /dev/sda1

  6. Reboot and check everything in file-system is intact.

Shrinking ext3 partition

*** Make sure you have a back up prior to proceeding. ***

  1. Boot into rescue mode.
  2. Unmount partition if mounted and check disk:
    umount /dev/sda1
    e2fsck -vn /dev/sda1

  3. Remove journaling from ext3 partition and revert to ext2, as resize2fs does not work on ext3 partition. (Note: This step should not be necessary in recent kernels.)
    tune2fs -O ^has_journal /dev/sda1

  4. Force check the partition:
    e2fsck -vf /dev/sda1

  5. Resize the partition making sure that you don't shrink it lesser than the disk space currently used else you may lose data.
    resize2fs /dev/sda1 6000M

  6. Make a note of the blocks and block size. You can also run:
    dumpe2fs /dev/sda1

  7. Delete /dev/sda1 partition and create a smaller one with fdisk:
    fdisk /dev/sda

  8. Recreate the partition /dev/sda1 with the starting point at the default location and the ending point at number of blocks from the resize2fs output (1536000) multiplied by the size of a block (4K). So, the end point would be 1536000 * 4 = 6144000K.
  9. Run partprobe and resize2fs utility with no size arguments:
    partprobe /dev/sda
    resize2fs /dev/sda1

    Note: If resize2fs errors out, you may need to further increase the block size by a small percentage (3 to 5%).

  10. Run a disk check for the final time before restoring the journal.
    e2fsck -vn /dev/sda1
    tune2fs -j /dev/sda1

  11. Reboot and check everything in file-system is intact.

Exclamations in the body of phplist emails resolved

PHPlist using phpmailer, by default sets to send email with Content-Transfer-Encoding set to 8-bit. However, mail transport standards forbid lines longer than 998 characters and has to handle such non-compliant lines by breaking/folding them, or the next hop MTA (Mail Transfer Agent) might reject the message or truncate the lines.

The fix for the problem is to use "base64" or "quoted-printable" encoding, which will fold the lines in a way that can be undone by the recipient MUA (Mail User Agent).

If using phplist with phpmailer, the file to edit would be "admin/phpmailer/class.phpmailer.php", as below:

var $Encoding = "base64";

PostgreSQL role based password authentication

To manage/setup role based password authentication for postgresql database.

Modify "/var/lib/pgsql/data/pg_hba.conf" and include:

host    samerole         all         127.0.0.1/32         md5

Save the below script and run:

./db_setup.sh <DBNAME> <DBMAINUSER> <DBMAINUSERPASS> create

#!/bin/bash
# db_setup.sh

USAGE="Usage: $0 <DBNAME> <DBMAINUSER> <DBMAINUSERPASS> <create|drop>"
DBNAME=${1?"$USAGE"}
DBMAINUSER=${2?"$USAGE"}
DBMAINUSERPASS=${3?"$USAGE"}

# Create new database + main user
#
create_db_and_mainuser() {
psql -U postgres template1 -f - <<EOT

CREATE ROLE ${DBNAME} NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;
CREATE ROLE ${DBMAINUSER} NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${DBMAINUSERPASS}';
GRANT ${DBNAME} TO ${DBMAINUSER};
CREATE DATABASE ${DBNAME} WITH OWNER=${DBMAINUSER};

EOT
}

# Remove database + main user
#
drop_db_and_mainuser() {
psql -U postgres template1 -f - <<EOT

-- TERMINATE CONNECTIONS OF ALL USERS CONNECTED TO <DBNAME>
DROP DATABASE ${DBNAME};
DROP ROLE ${DBMAINUSER};
DROP ROLE ${DBNAME};

EOT
}

# Main
case "$4" in
  create)
    create_db_and_mainuser
    ;;
  drop)
    drop_db_and_mainuser
    ;;
  *)
    echo $USAGE
    exit 1
    ;;
esac

exit 0

You should now be able to connect using:

psql -U <DBMAINUSER> -d <DBNAME>  -h 127.0.0.1

Syndicate content