Sunday, January 28, 2007

In a deadirectory

After some apt-get update and apt-get install, I get this funny error message when I try to restart apache:

"shell-init: could not get current directory: getcwd: cannot access parent directories: No such file or directory"

But the command runs fine.

Something felt familiar ... oh right. This is a UNIX error message for "you are in a directory that no longer exists".

Monday, January 01, 2007

Mysql broken increment

Changing table names, I changed the name of the primary key as well, and forgot to set all the attributes.

If you don't, things start to break, because the attributes aren't "saved" for you in any way. For example, the auto-increment stops working, the table is no longer functional, and you get this error:

Duplicate entry '0' for key 1

To fix this, add the attributes to the primary key field. This won't hurt the values (at least, it didn't for me):

alter table X change column key_name key_name int(12) unsigned not null auto_increment

Friday, October 27, 2006

Upgrading to PHP 5 -- fix 3

And, of course, there's the famous "backslash" or "magic_quote" problem. The only way to sensibly develop a large PHP app is to turn magic_quote Off in the php.ini file. That way, you can get reliable behavior from addslashes & stripslashes. When you port to a new php implementation, however, you'll find that, by default, magic_quotes is On. Edit php.ini, turn magic quotes Off, issue a /etc/init.d/apache2 restart, and your text inserts & fetches shouls be fine.

Sunday, October 22, 2006

Upgrading to php5 -- fix 2

I get:

"Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' " ....

I notice that my old command line entrance into mysql isn't working, and I get:

"Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' "

Ah ... mysqld isn't running. So:

mysqld_safe &

... which finds the old config files fine. Errors disappear. Everything's up.

Upgrading to php5

After a major Linux distro upgrade

This message (from php):

Fatal error: Call to undefined function: mysql_connect() ...

Mysql wasn't bundled in. So I typed:

apt-get install php5-mysql

... which fixed the problem

Sunday, October 15, 2006

Odd characters in PHP server output

Switched from php4 to php5.

First problem: strange control characters that the browser renders as black diamonds with a question mark inside. Like this: ��

So I saved the html file.

Looked at it with vim -b.

The confused black diamonds were "a0" in hex.

I typed "a0" into Google.

Others had this problem, with perl. It was a matter of content-type character sets (charset): is0-8859-1 vs. UTF-8 ...

Looked at the HTML output of another server I had (with php4) for phpinfo(). Compared side-by-side with the php5 output. Very useful ... a bunch of sections with settings in tables. It was in a section entitled "HTTP Headers Information", subheading "HTTP Response Headers". The good server had the name/value pair:

Content-Type text/html; charset=iso-8859-1

... the bad, problem server had:

Content-Type text/html; charset=UTF-8

So, I looked at the /etc/php5/apache2/php.ini file.

there's a line that read:

;default_charset = "iso-8859-1"

I tried removing the leading semi-colon (uncommenting). Typed:

/etc/init.d/apache2/restart

And that fixed it. The diamonds disappeared.