2012年08月25日

The conf below doesn’t work

<Location /perl>

SetHandler perl-script

PerlHandler ModPerl::Registry

Options +ExecCGI

Allow from all

</Location>

If the client issues an HTTP HEAD request rather than the usual GET, to be compliant with the HTTP protocol we should not send the document body, but only the HTTP header. When Apache receives a HEAD request, header_only() returns true. If we see that this has happened, we return from the handler immediately with an OK status code.

Generally, you don’t need the explicit content type setting, since Apache does this for you, by looking up the MIME type of the request and by matching the extension of the URI in the MIME tables (from the mime.types file). So if the request URI is /welcome.html, the text/html content-type will be picked. However for CGI scripts or URIs that cannot be mapped by a known extension, you should set the appropriate type by using content_type() method.

The situation is a little bit different with Apache::Registry and similar handlers. If you take a basic CGI script like this:

  print "Content-type: text/plain\r\n\r\n";
  print "Hello world";

it wouldn’t work, because the HTTP header will not be sent out. By default, mod_perl does not send any headers itself. You may wish to change this by adding

  PerlSendHeader On

in the Apache::Registry <Location> section of your configuration

Mod-perl 2.0 use

PerlOptions +ParseHeaders

ParseHeaders

Scan output for HTTP headers, same functionality as mod_perl 1.0’s PerlSendHeader, but more robust. This option is usually needs to be enabled for registry scripts which send the HTTP header with:

  print "Content-type: text/html\n\n";

How to debug mod-perl

1) do the config
<IfDefine PERLDB>
    <Perl>
      use Apache::DB ();
      Apache::DB->init;
    </Perl>
    <Location />
      PerlFixupHandler Apache::DB
    </Location>
</IfDefine>
2) start a terminal and run
sudo apache2ctl -X -D PERLDB -k start
3) start another terminal and run
curl http://localhost/perl/test.pl
then you will see prompt from the first terminal
xxx@ubuntu:~$ sudo apache2ctl -X -D PERLDB -k start
[notice] Apache::DB initialized in child 4835
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Loading DB routines from perl5db.pl version 1.33
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::((eval 7):2): ;
DB<1> c
ModPerl::ROOT::ModPerl::Registry::var_www_perl_test_2epl::handler(/var/www/perl/test.pl:12):
12: print "Hello\n";
DB<1> c
xxx@ubuntu:~$ sudo apache2ctl -X -D PERLDB -k start[notice] Apache::DB initialized in child 4835apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName Loading DB routines from perl5db.pl version 1.33Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::((eval 7):2): ;  DB<1> cModPerl::ROOT::ModPerl::Registry::var_www_perl_test_2epl::handler(/var/www/perl/test.pl:12):12: print "Hello\n";  DB<1> c
2012年08月07日

Load data infile 出错,File ‘/tmp/tbl_mws_alexa_lexi’ not found (Errcode: 13)

需要改变file的权限和owner为mysql

sa@ubuntu:~$ sudo chown mysql:mysql /tmp/tbl_mws_alexa_lexi
mysql> load data infile ‘/tmp/tbl_mws_alexa_lexi’ into table tbl_mws_alexa_lexi;

ERROR 29 (HY000): File ‘/tmp/tbl_mws_alexa_lexi’ not found (Errcode: 13)
mysql> load data local infile ‘/tmp/tbl_mws_alexa_lexi’ into table tbl_mws_alexa_lexi;
ERROR 1148 (42000): The used command is not allowed with this MySQL version
mysql> load data local infile ‘/tmp/tbl_mws_alexa_lexi’ into table tbl_mws_alexa_lexi;
ERROR 1148 (42000): The used command is not allowed with this MySQL version
mysql> load data infile ‘/tmp/tbl_mws_alexa_lexi’ into table tbl_mws_alexa_lexi;
Query OK, 2747962 rows affected, 65535 warnings (42.79 sec)
Records: 2747962 Deleted: 0 Skipped: 0 Warnings: 5495924

mysql>

sa@ubuntu:~$ mysql -V
mysql Ver 14.14 Distrib 5.5.22, for debian-linux-gnu (x86_64) using readline 6.2
sa@ubuntu:~$

sa@ubuntu:~$ ls -al /tmp/
total 1165248
drwxrwxrwt 2 root root 4096 Aug 7 16:54 .
drwxr-xr-x 23 root root 4096 Jul 20 11:09 ..
-rwxrwxrwx 1 mysql mysql 329490142 Aug 7 16:42 tbl_mws_alexa_lexi
-rwxrwxrwx 1 mysql mysql 863709362 Jul 20 14:27 tbl_sec_mws