Thursday, May 19, 2011

PHP exec() and system() tied to /bin/sh on debian squeeze

In the past I relied on the exec() and system() functions to run some commands in PHP.
It came to a surprise when I updated my distro from etch to squeeze that the /bin/sh symlink was not pointing to bash anymore, but to dash which is a POSIX compliant shell and who knows what else (technical blah-blah).

Some commands I ran through exec() and system() failed and the reason is that bash doesn't share the same syntax and builtins as dash.

I was told on some IRC channels that reverting to bash should not break anything, just make slower the execution of startup scripts and the like (anyway I'll not die by waiting 2 seconds more for the box to be ready).

Just do a:

dpkg-reconfigure dash

and follow instructions, afterwards your /bin/sh symlink will point again to bash and your PHP exec() and system() calls will behave as before.

1 comment:

Ping said...

After migrating the website to Debian 6, all php exec calls stopped working.

Selected "No" while reconfiguring dash, and all went back to normal.

Thanks! You saved my day.

Followers

About me

Santa Fe, Argentina
Programador Web, PHP, MySQL, JQuery, Administrador Linux. LAMP, Lighttpd, Nginx.