Archive for April, 2006
Setup virtual users and domains on Courier (Debian package)
by Greg on Apr.02, 2006, under Linux
Courier Virtual Email Hosting – No SQL Servers
Using USERDB
-
Add the domain(s)
Add your domain name to esmtpacceptmailfor.dir/default
Add your domain name to hosteddomains/default
Then create the courier system files, run:makeacceptmailfor
makehosteddomains -
Add the users
You run 2 commands to add a user. (same user/pw for smtp also)
userdb and userdbpwLet’s say we want to add a user account for misc@1stbyte.com.
1st create the virtual account home dirs. I save mine in /home/virtual. You will create a sub dir for each domain, then user. And you must create the Maildir folders in this home folder. So it will look like this:
/home/virtual/domain.com/user
Run:
mkdir /home/virtual/1stbyte.com/misc
maildirmake /home/virtual/1stbyte.com/misc/Maildir
chown -Rv 999.999 /home/virtual/1stbyte.com/misc
userdb misc@1stbyte.com set uid=999 gid=999 home=/homevirtual/1stbyte.com/misc
userdbpw | userdb misc@1stbyte.com set systempwuserdbpw will ask for a password and pipe into the “set systempw” command and save it into the userdb database. You can see the data in /etc/courier/userdb.
When you are done run: makeuserdb
-
Setup any aliases
if you have any aliases, set them in aliases/system. Edit the file and add full email account names like:
vuser@domain.com: mailaccount@domian.comIt’s alias: realaccount.
The can be other domains too:
fakeuser@accptedmaildomain.com: realaccount@realhosteddomain.com
info@1stbyte.com: misc@1stbyte.comAnd of course, run: makealiases
Compile Apache 2 with PHP 4 and MySQL 5 (while MySQL 4 is also installed)
by Greg on Apr.02, 2006, under Databases, Linux
Download and unpack Apache and PHP. MySQL 5 is install already. (as per another blog: http://www.1stbyte.com/2006/04/02/mysql-5-upgrade-compiled/
Make sure you have the proper dev packages. In my case I had to install ‘libflex’ and ‘libgdbm-dev’ using apt-get install to install PHP. (I have Debian Unstable)
./configure –prefix=/var/httpd –enable-so –enable-proxy –enable-proxy-ftp –enable-proxy-http –enable-ssl –enable-headers –enable-rewrite –enable-cgi –enable-deflate –enable-mime-magic –enable-dav –enable-dav-fs –enable-userdir –enable-status –enable-info
make && make install
then I copied the original Apache conf from /etc/apache2 to the new root, /var/httpd/conf. I also had to update the httpd.conf file to set the correct server root and other misc server directives, but mostly they were all the same.
Test your install /var/httpd/bin/apachectl start
Goto http://localhost and make sure you get the web site.
Now install PHP.
./configure –with-apxs2=/var/httpd/bin/apxs –with-mysql=/var/mysql5010 –with-mysql-sock=/tmp/mysql5.sock –prefix=/var/httpd/php –with-config-file-path=/var/httpd/php –enable-force-cgi-redirect –disable-cgi –with-zlib –with-gettext –with-gdbm
make
cp -p .libs/libphp4.so /var/httpd/modules
cp -p php.ini-recommended /var/httpd/php/php.ini
I then put these into httpd.conf
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
LoadModule php4_module modules/libphp4.so
then ran:
make install
Edit: 10/25/05
Additional new notes:
When configure is run, I do it this way now:
./configure –prefix=/var/httpd –enable-so –enable-proxy –enable-proxy-ftp –enable-proxy-http –enable-ssl –enable-headers –enable-rewrite –enable-cgi –enable-deflate –enable-mime-magic –enable-dav –enable-dav-fs –enable-userdir –enable-status –enable-info –enable-cache –enable-disk-cache –enable-mem-cache
And…
For setup with Zope I am running ProxyPass instead of Rewrites:
ProxyRequests On ProxyPass / http://127.0.0.1:18080/VirtualHostBase/http/www.adomain.com:80/clients/adomain_com/VirtualHostRoot/ ProxyPassReverse / http://127.0.0.1:18080/VirtualHostBase/http/www.adomain.com:80/clients/adomain_com/VirtualHostRoot/ ProxyRequests On ProxyPass / http://127.0.0.1:18080/VirtualHostBase/http/domain.1stbyte.org:80/clients/domain_com/VirtualHostRoot/ ProxyPassReverse / http://127.0.0.1:18080/VirtualHostBase/http/domain.1stbyte.org:80/clients/domain_com/VirtualHostRoot/
When you add the PHP config, you need to first add flex.
apt-get install flex
Also, the httpd.conf additons are partially done in the mods-enabled folder for php.conf.
Make dynamic amount of columns with PHP
by Greg on Apr.02, 2006, under PHP, Programming
Below is a demonstration of how I created variable amount of columns in a table listing. In this example I was creating a picture gallery and using template files, so you can see even more than the dynamic columns, but anyway…
The only bit of important info here are these two snippets of code:
//Every x iteration based on GALLERYLISTCOLS, when 0, start new row
if (($c % GALLERYLISTCOLS)==0) {
$sdelim = $gll_startdelim;
} else {
$sdelim = ‘ ‘;
}
//Now, when x iteration is x – 1, then end the row (GALLERYLISTCOLS – 1)
if (($c % GALLERYLISTCOLS)==(GALLERYLISTCOLS – 1)) {
$edelim = $gll_enddelim;
} else {
$edelim = ‘ ‘;
}
It is using the modulus operator. And when we reach every x amount of columns, specified by GALLERYLISTCOLS global var, we make the $sdelim and/or the $edelim = the template row delimiters. (<tr> or </tr>) This makes the new row. If we set GALLERYLISTCOLS = 4, then we make 4 columns.
There are a lot of variable coming from external sources, so you’ll have to figure it out from there, but at least you can get the idea. (and more importantly, I can view this and remember how the hell I did it!)
—————————————
$gll_start= readFromFile(TEMPLATEDIR.’/gll_start.tpl’);
$gll_startdelim= readFromFile(TEMPLATEDIR.’/gll_startdelim.tpl’);
$gll_item= readFromFile(TEMPLATEDIR.’/gll_item.tpl’);
$gll_enddelim= readFromFile(TEMPLATEDIR.’/gll_enddelim.tpl’);
$gll_end= readFromFile(TEMPLATEDIR.’/gll_end.tpl’);
//////////////////////////////////
/// Show the main gallery
$gallinks = “”;
$webgallery=WEBGALLERY;
$webgallerythumbs=WEBGALLERYTHUMBS;
require_once ‘DB.php’;
$db =& DB::connect(”sqlite:///$sdb”);
if (DB::isError($db)) {
die($db->toString());
}
$sql = “SELECT imgid, imgname,imgthumb,imgcategory,category,imgcomment FROM vw_gallery where category = ‘$gallery’”;
$res = $db->query($sql);
if (PEAR::isError($res)) {
die($res->getMessage());
} else {
$c = 0;
$rc = $res->numRows();
$parsedresult = ”;
while ($res->fetchInto($row)) {
$imgid = $row['0'];
$imgname = $row['1'];
$imgthumb = $row['2'];
$imgcomment = $row['5'];
$imgcomment = str_replace(’\\”‘, ‘”‘, $imgcomment);
$imgcomment = str_replace(”\\’”, “‘”, $imgcomment);
$thispage = “$me?imgid=$imgid”;
/*
Here we want every x amount of iterations.
Ex. If GALLERYLISTCOLS = 3, then every third item.
$c is the current iteration of records. 1,2,3,4,…
So, when the modulus of $c and 3 is equal to 0, then
we have a group of three and should start a new row.
Modulus meaning, 3 goes into $c with x left over.
If current rowcount is 17, then 3 mod 17 = 5 with 2 left over.
Soon as we hit 18, 3 goes into it 6 times, with 0 left over,
making it another group of three.
To get start of col amount we to (($c % GALLERYLISTCOLS) == 0).
To get the end of the col we need one less than GALLERYLISTCOLS.
And we have (($c % GALLERYLISTCOLS) == (GALLERYLISTCOLS – 1)).
(the max leftover, else it would be 0)
*/
//Every x iteration based on GALLERYLISTCOLS, when 0, start new row
if (($c % GALLERYLISTCOLS)==0) {
$sdelim = $gll_startdelim;
} else {
$sdelim = ‘ ‘;
}
//Now, when x iteration is x – 1, then end the row (GALLERYLISTCOLS – 1)
if (($c % GALLERYLISTCOLS)==(GALLERYLISTCOLS – 1)) {
$edelim = $gll_enddelim;
} else {
$edelim = ‘ ‘;
}
$parsed = $sdelim . $gll_item;
$parsed = tplParser(’{gll_thumbsrc}’,$webgallerythumbs . ‘/’ . $imgthumb,$parsed);
$parsed = tplParser(’{gll_comment}’,$imgcomment,$parsed);
$parsed = tplParser(’{gll_imageurl}’,$thispage,$parsed);
$parsed = tplParser(’{gll_imagename}’,$imgname,$parsed);
$parsedresult = $parsedresult . $parsed . $edelim;
$c++;
}
echo($gll_start.$parsedresult.$gll_end);
}
Mysql 5 upgrade – compiled
by Greg on Apr.02, 2006, under Databases, Linux
I just upgraded my MySQL server from 5.0.7 to 5.0.10. I wanted to make a few notes about what I did to set it up.
1. I compiled MySQL 5.0.10-beta.
./configure --prefix=/var/mysql5010 --with-unix-socket-path=/tmp/mysql5.sock --with-mysqld-ldflags=-all-static --enable-assembler --with-low-memory --with-named-curses-libs=/lib/libncurses.so.5 --with-mysqld-user=mysql
2. Did a make && make install
3. Stop mysql507 (on my server I created a script to stop and start mysql and mysql5, this way I can easily run both servers at the same time) stopmysql5
4. mkdir /var/mysql5010/var
5. cp -Rv /var/mysql507/var/* /var/mysql5010/var
6. Chmod -Rv mysql.mysql /var/mysql5010
7. Updated the startmysql5 script to point to the new path (var/mysql5010), same with stopmysql5 script.
8. startmysql5
And I was running! Now, this might not work on future versions, particularly since MySQL 5.x is in beta right now.
I did not recompile MySQLdb yet, as it is working fine for me, however it might be wise. In fact, I really should do that because the libraries are pointing to the /var/mysql507 directory.
Edit: 10/25/05
The config options here are for a smaller/slower server. Use this for normal servers with decent amount of RAM:
./configure --prefix=/var/mysql --with-unix-socket-path=/tmp/mysql.sock --with-mysqld-ldflags=-all-static --enable-assembler --with-named-curses-libs=/lib/libncurses.so.5 --with-mysqld-user=mysql --enable-thread-safe-client
This also enables the Thread Safe client, which will work better with mysql-python modules.
Retrieve or return an output parameter from a Mysql stored procedure in Zope
by Greg on Apr.02, 2006, under Databases, Programming, Zope
Zope 2.7.6 – Mysql 5.0.7. I have always thought that output parameters from stored procedures were not useable in Zope’s ZSQL methods, but a few minutes ago is suddenly occured to me that I could do it by using the “sql_delimiter” function in Zope. To be quick, put something like this in a ZSQL method:
call sp_test(@y)
dtml-var sql_delimiter
select @y as thecount
(put the <> around dtml-var sql_delimiter)
This works perfectly! I simply return a count in a simple sproc, but it’s exciting because this makes it even more useable! I LOVE ZOPE! (and now the MySQL has stored procedures, I LOVE MYSQL!)
Sample code if you want it:
— Here is the stored procedure —-
— This simply returns the parameter vout
— as a count.
DELIMITER $$
DROP PROCEDURE IF EXISTS `fb`.`sp_test`$$
CREATE PROCEDURE `fb`.`sp_test` (
out vout int
)
BEGIN
select count(*) into vout from blogs;
END$$
DELIMITER ;
— Here is the ZSQL Method —
call sp_test(@y)
dtml-var sql_delimiter
select @y as thecount
(put the <> around dtml-var)
Now you should note… for some reason, in MySQL Query Browser you can’t issue the commands:
call sp_test(@y);
select @y as thecount;
It wont work. But you can do that at he command line client just fine.
Also, you cannot do this AND return a recordset in the same procedure. It works from the command line client, but not in the ZSQL method. So, you will be limited to only return parameters this way.
Install a non-linux USB Wireless adapter on Ubuntu
by Greg on Apr.01, 2006, under Linux, Networking
Wow! This has turned out to be a real pain. Below is a process I started, but ran into issues. I could see the module, but it would never make a Wlan0 to access using iwconfig or ifconfig.
I tried this on the Trendnet TEW-229UB and the TEW-424UB. Maybe because they are cheap devices, but heck, I spent something like $25 for both, and in Windows, they work perfectly.
After I had depmod -a and the ndiswrapper module listed (lsmod), everything seemed ok. The syslog had no errors on the 424, but never showed the wlan0. I could run lshw -C network, but would only show the wired adapter. I could run lsusb, and it would show the device. I could even run ndiswrapper -l and the device showed installed and hardware present. So, what the hell? No errors, everything working, but no WLAN0 shows up?
If I find more info, I’ll post it.
- make sure the ndiswrapper package is installed, so do that.
- Make sure that the wireless-tools package is installed. Probably is from the initial install.
- Get your wireless driver for Windows XP.
- Unpack the driver somewhere, then cd there and run ndiswrapper on driver. Something like so:
ndiswrapper -i driver.infI installed the Trendnet TEW-229 and that was:
ndiswrapper -i sis162u.inf - Then let ndiswrapper setup the module.
ndiswrapper -m - Then run: depmod -a
After that you’ll see the ndiswrapper module when you run lsmod.
And from here I can see the module, but don’t know what to do… I’ll try to figure it out though, and write it here!