LendKey

Monday, November 16, 2009

PHP cannot connect to mysql when run inside Apache

I ran into a very strange issue when Apache/PHP/MySQL.
What happend was my php code suddenly cannot connect to mysql on another machine any more. The error message is:
mysqli_connect() [function.mysqli-connect]: (HY000/2003): Can't connect to MySQL server on '218.241.156.222' (13)
The strange thing was that if I connect mySQL from command line, even run the same code by php directly from command line, it worked just fine.

After searched around, I finally found the answer. Looks like it has something to do with SELinux settings.

To fix the issue, I only need to run:
setsebool httpd_can_network_connect_db 1

Before I ran the script, the file content of /selinux/booleans/httpd_can_network_connect_db was:
0 0

After I ran the script, content changed to:
1 1

Saturday, November 7, 2009

Trick to let iTune handle Chinese song names and tags correctly in Mac OS X

When play Chinese songs in iTune, it always tends to show the song information, such as name, artist, album, etc. as garbage text.

When I was running Mac OSX Tiger and Leopard, the trick I used was to open iTune application information by right-click and choose Get Info.
In the information windows, remove all languages except Chinese. So next time, when iTune is started, it starts in Chinese mode. And it handles all Chinese songs correctly.

In Snow Leopard, the language selection is missing in Get Info dialog. It took me a few weeks to find the new trick.
cd /Applications/iTunes.app/Contents/Resources
mkdir lang_bak
mv *.lproj lang_bak
cp -r lang_bak/zh_CN.lproj .

Then start iTune, you will get it in Chinese mode again and just as the trick before, all Chinese songs are handled correctly.

Hope these tricks can be helpful to Chinese Mac users.

Enjoy!

BTW: If you speak other language and suffers the sames kind of problem, I guess you can try to delete all other languages other than your preference. Hopefully that will work for you too.