Éditorial

admin — 14/09/2009 (23:22)

sitecopy started to give me grief, so as a temporary solution, I just used wput to mirror the site:

hourly:

nice -n 19 find /home/ ! -type d ! -type l grep -v '.*.tar.gz' grep -v 'backup.*.sql' grep -v /public_html/cache grep -v /public_html/save grep -v /public_html/thumb nice -n 19 wput -i - -o wput-hourly.log --timestamping --reupload --dont-continue ftp://user:passwd@backup.server.fr/

daily:

dpkg -l > /etc/local/pkg.ls cp /root/backup*.sh /etc/local cp /usr/share/shorewall/modules /etc/local/shorewall.modules

cd / nice -n 19 tar cjf /root/tmp/etc.tar.bz2 etc/ chmod 400 /root/tmp/etc.tar.bz2

cd /root/tmp/ wput -a wput-daily.log --timestamping --reupload --dont-continue etc.tar.bz2 ftp://user:passwd@backup.server.fr/ rm etc.tar.bz2

admin — 09/04/2009 (21:59)

ipw3945 is working great with Debian Etch, but to upgrade to Lenny the wifi driver needs was upgrating manually.

  • Make sure iwlwifi module is installed
  • go the the driver page and download iwlwifi-3945-ucode-15.28.1.8.tgz on http://www.intellinuxwireless.org/index.php?n=downloads&f=ucodes_3945
  • create the following file /etc/hotplug/firmware.agent with:
    FIRMWARE_DIR=/lib/firmware
  • then copy iwlwifi-3945-1.ucode in /lib/firmware
  • you need to modify /etc/network/interfaces as the interface name changed (on my computer from eth1 to wlan0_rename)
  • To properly name the interface to wlan0, uninstall ipw3945d (apt-get remove ipw3945), then edit the following file : /etc/udev/rules.d/70-persistent-net.rules, and comment the following line :
       # PCI device 0x8086:0x4222 (ipw3945)
       #SUBSYSTEM=="net", DRIVERS=="?*", ATTRSaddress=="00:18:de:32:fd:7c", NAME="eth1"

Normally, at the next reboot you'll get another line being added automatically in this file:

       # PCI device 0x8086:0x4222 (iwl3945)
       SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTRaddress=="00:18:de:32:fd:7c", ATTRtype=="1", KERNEL=="wlan*", NAME="wlan0"

admin — 12/07/2008 (12:54)

/etc/apache2/mods-available/fcgid.conf

<IfModule mod_fcgid.c>

 AddHandler fcgid-script .fcgi
 SocketPath /var/lib/apache2/fcgid/sock
 IPCConnectTimeout 20
 IPCCommTimeout 60

</IfModule>

admin — 12/07/2008 (12:37)

Config Apache:

 #redirect server.org to www.server.org
<VirtualHost *:80>
       ServerName server.org
       DocumentRoot /home/server.org/public_html
       RedirectMatch permanent ^(.*)$ http://www.server.org$1
</VirtualHost>
<VirtualHost *:80>
      ServerName www.server.org
      #Alias for CDN
      ServerAlias img0.server.org img1.server.org img2.server.org
      DocumentRoot /home/server.org/public_html
      <Directory /home/server.org/public_html>
               #Default charset
               AddDefaultCharset utf-8
               #If using Templeet
               ErrorDocument 403 /templeet.php
               ErrorDocument 404 /templeet.php
               DirectoryIndex index.html
               #PHP goes through FCGI
               AddHandler fcgid-script .php
               FCGIWrapper /var/www/php/server.org/phpwrapper .php
               Options -Indexes FollowSymLinks ExecCGI
               #MultiViews
               <FilesMatch ".(flvgifjpgjpegpngico)$">
                       Header append Cache-Control "public"
               </FilesMatch>
               FileETag All
               ExpiresActive On
               ExpiresByType image/gif "access plus 1 month 1 week"
               ExpiresByType image/png "access plus 1 month 1 week"
               ExpiresByType image/jpg "access plus 1 month 1 week"
               ExpiresByType image/jpeg "access plus 1 month 1 week"
               ExpiresByType image/x-icon "access plus 1 month 1 week"
               Allow from all
     </Directory>
      ErrorLog /var/log/apache2/server.org-error.log
      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn
      CustomLog /var/log/apache2/server.org-access.log combined
      ServerSignature On
      SuexecUserGroup server.org server.org
</VirtualHost>

Now, using mod_deflate to gzip the output, in apache2.conf:

 # MOD_GZIP
 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
 #SetOutputFilter DEFLATE
 #SetEnvIfNoCase Request_URI .(?:gifjpe?gpng)$ no-gzip dont-vary
 #SetEnvIfNoCase Request_URI .(?:exet?gzzipbz2sitrar)$ no-gzip dont-vary
 #SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
 BrowserMatch ^Mozilla/4 gzip-only-text/html
 BrowserMatch ^Mozilla/4.0[678] no-gzip
 BrowserMatch bMSIE !no-gzip !gzip-only-text/html
 Header append Vary User-Agent env=!dont-vary

Apache2 has some memory leaks, so set a limit to the number of request per childs:

 # worker MPM
 # StartServers: initial number of server processes to start
 # MaxClients: maximum number of simultaneous client connections
 # MinSpareThreads: minimum number of worker threads which are kept spare
 # MaxSpareThreads: maximum number of worker threads which are kept spare
 # ThreadsPerChild: constant number of worker threads in each server process
 # MaxRequestsPerChild: maximum number of requests a server process serves
 
   StartServers          2
   MaxClients          150
   MinSpareThreads      25
   MaxSpareThreads      75
   ThreadsPerChild      25
   MaxRequestsPerChild   5000
 
 #MaxRequestsPerChild was 0

admin — 09/07/2008 (19:35)

Read the cheatsheet: php-unicode

1. Move your database to utf8 as default: See MySQL-charsethttp://dev.mysql.com/doc/refman/5.0/en/charset.html:

  ALTER DATABASE dabase
       CHARACTER SET utf8
       DEFAULT CHARACTER SET utf8
       COLLATE utf8_general_ci
       DEFAULT COLLATE utf8_general_ci;

2. Then convert all your tables:

  ALTER TABLE articles CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
  SHOW WARNINGS;
  ALTER TABLE articles CHARACTER SET utf8 COLLATE utf8_general_ci;
  OPTIMIZE TABLE articles;

You might need to correct any warnings, due to colliding key if your data was in latin1 charset before. Recreating the index is important, otherwise ordering will be wrong under the new collation. MySQL will only convert text column, so if any field if a blob it's time to convert!

ALTER TABLE messages CHANGE body body text;

3. Configure you MySQL server, in my.ini:

[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
default-character-set = utf8
[mysql]
default-character-set = utf8

This should set all connection to utf8 as the default charset. All except certain version of the php-mysql... for which you need to do as the first query of you website:

SET NAMES 'utf8'

4. Configure PHP See http://www.php.net/mbstring

mbstring.language = Neutral
mbstring.internal_encoding = UTF-8
;mbstring.http_output = UTF-8
;mbstring.func_overload = 7
default_charset = UTF-8

You need to test the mb function overload, as it might not suit your PHP apps. My own code use directly mb_ function directly, also bear in mind that there is no mb_strtr function so you will have to provide your own like this:

~defunc('unhtmlentities',~utf8_encode(~strtr(~utf8_decode(~sparam(1)),~array_flip( ~get_html_translation_table( ~constant('HTML_ENTITIES') )))))

5. You could also add a default charset in Apache:

AddDefaultCharset utf-8

7. Last but not least, update your templates/scripts to unicode:

#!/bin/bash
for i in `find $1  grep -v .svn`; do
ftype=`file $i  grep "ISO-8859"`
if [ "$ftype" != "" ]; then
echo $i
iconv -f ISO-8859-1 -t UTF-8 $i > $i2
mv $i2 $i
fi
ftype=""
done

Above script might not work for all filetype (like .rss).

8. PCRE

Be careful of Preg as they are not within the scope of the mbstring, add the modifier u. Unfortunately by doing so you kiss goodbye to PCRE extention, so use it wisely.

 preg_replace( '/[éêëèÊËÉÈ]/u', 'e' , $topic)

9. Characters conversion :

http://www.microsoft.com/typography/unicode/1252.htm http://openweb.eu.org/articles/caracteres_illegaux

function unicode2utf8($c)
$output="";

if($c < 0x80)
{
return chr($c);
else if($c < 0x800)
return chr( 0xc0 | ($c >> 6) ).chr( 0x80 | ($c & 0x3f) );
else if($c < 0x10000)
return chr( 0xe0 | ($c >> 12) ).chr( 0x80 | (($c >> 6) & 0x3f) ).chr( 0x80 | ($c & 0x3f) );
else if($c < 0x200000)
return chr(0xf0 | ($c >> 18)).chr(0x80 | (($c >> 12) & 0x3f)).chr(0x80 | (($c >> 6) & 0x3f)).chr(0x80 | ($c & 0x3f));
return false;

}