Computer Magic
Software Design Just For You
 
 

Cpanel and custom Apache or PHP modules

September 1st, 2010

Recently I had to recompile PHP to add additional support for modules not listed in the CPanel easyapache config options. CPanel has thought of most things even if they haven’t created a nice GUI interface for them yet.

In this case, you can add custom parameters to add to your apache or PHP compile.

By adding entries to the appropriate file, easyapache will pick them up when you use it’s wizard to rebuild your web stack.

For Apache 1.3.x — /var/cpanel/easy/apache/rawopts/Apache1
For Apache 2.0.x — /var/cpanel/easy/apache/rawopts/Apache2
For Apache 2.2.x — /var/cpanel/easy/apache/rawopts/Apache2_2
For all PHP 4.x versions — /var/cpanel/easy/apache/rawopts/all_php4
For all PHP 5.x versions — /var/cpanel/easy/apache/rawopts/all_php5
For Mod_suPHP — /var/cpanel/easy/apache/rawopts/all_suphp
For a specific PHP Version — /var/cpanel/easy/apache/rawopts/PHP-X.X.X

For example, to add LDAP support to PHP5, you would do the following…
echo “–with-ldap” >> /var/cpanel/easy/apache/rawopts/all_php5
echo “–with-ldap-sasl” >> /var/cpanel/easy/apache/rawopts/all_php5

Next time you rebuild Apache/PHP5, it will include LDAP and LDAPS modules.

The documentation on this is at: http://docs.cpanel.net/twiki/bin/view/EasyApache3/CustomConfigureFlags

Intro to Relational Databases

December 28th, 2009

A database is just a series of one or more tables. Each table is a separate and distinct entity. What makes a database “relational” is the ability to define relationships between one table and another. In some db systems (mssql), you can actually tell the system that there is a relationship. In others (mysql) you don’t have to define it. In either case, the nature of the relationships don’t change.

How relationships are defined
To setup a relationship, you just need a field on each table that matches. The field can be a number, a string, just about any field that isn’t a text field (cause they use pointers internally, that’s another lesson).

Student Table

  • Student ID
  • Social Security Number
  • Student Name

Government Table

  • Social Sec Number
  • Name

In the example above, there are two tables. One is a government table with your social sec number. The school table would be an example of your enrollment info at college. They assign their own student ID in an attempt to expose your ssn less, but they still use it to match up with govt information. Using this analogy you could match against the two tables using the ssn field. That would be the relational field. The key is to keep the info in the two fields matching.

One to One
A one to one relationship is like husband and wife. There is one in each table. A husbands table, and a wives table. Keep in mind that there are two tables involved, so it is very possible to have one in the first table with no corresponding item in the other. The key here is that when there is a match, it will only be one record on each side that matches. A more appropriate analogy would be with a table for men and a table for women and use a field to indicate the couple. Also, the previous example above using the ssn number is a good example of a one to one relationship.

Men

  • manID
  • Name
  • CoupleID

Women

  • womenID
  • Name
  • CoupleID

In this example, you can have a list of men and women. When you want them to be a couple, set the couple id field to the same number on both sides. Then you can pull a report of married couples. We will assume that anyone with a couple id of 0 is single, and that anyone with an id > 0 is a couple. You could use null values here too for single, but to make things easy we will use 0 (some db systems require you to deal with nulls differently and I don’t want to confuse things).

To get a list of single men:
Select * from men where `coupleid`=0
Same for women, just change the table name:
select * from women where `coupleid` = 0

To get a list of couples, you do what we call a join. This creates a merge of the two tables based on your criteria. There right, left, and inner joins. We won’t worry about all the differences right now.
select men.manid, men.name, women.womenid., women.name, men.coupleid from men, women where men.coupleid=women.coupleid

This will look like the following:
1 | Bob Smith | 3 | Sandy Smith | 1
It will create a temporary table (recordset) in memory that you can use in your code (PHP?) the same way as any other query. The joined information contains the elements you asked for from both tables.

Notice that after the SELECT you use table.column notation to avoid any confusion since both tables may have similar column names. After the where statement is where we indicate how to join the tables. We specify that the coupleid column is the one that needs to match. The database will only return records when that field matches.

One To Many
One to many relationships are more common in databases. This is where you have one item on the left table and 0 or more items on the right side. Think of a parent. You can have zero or more children. You can’t just create 10 fields for children names, you will find people who have 14 or 15 children. And creating that many fields wastes massive space since the average couple will have 2.5 children. It is a better solution to build a new table with information for just one child per row.

Parent

  • ParentID
  • Name

Children

  • ChildID
  • ParentID
  • Name

In this example, you have a parent with an ID. You then have another table that holds children. Each row is a child. To tell which ones are yours, you put your parentid in their parentid field. Then you can pull your kids out of the mess of children in the table. A little like picking your kid up from school.

To get your children (assuming your parentid is 1):
select * from children where ParentID=1

The key here is to make sure you know what your parent ID is. When writing code for this, you would need to track what parent you are looking at. In the example of a blog entry (parent) where you would want to view comments (children) you would want to track which blog entry you are viewing. This shouldn’t be a big issue as you are likely to have a url like the following when viewing the blog entry already:
/viewblog.php?blogid=1

The blogid=1 should be what you would use to grab comments and print them on the page:
select * from comments where blogid=1
Here it is in PHP code:
$sql = “SELECT * FROM comments WHERE blogid=” + $_GET["blogid"];
$rs = mysql_query($sql);
while ($record = mysql_fetch_assoc($rs)) {
print $record["comment"];
}

Many to Many
You can also do many to many relationships. This can get confusing though. Think plural wives and plural husbands at the same time. Generally this is just a really bad idea and shouldn’t be done unless there is no other way to represent the information. The linkage gets confusing and if you forget to update the linkage (relational fields) in your code somewhere it leads to trashed data. I am a firm believer in the KISS concept. The more you keep it simple, the fewer bugs you will introduce and the easier it will be to maintain later. Google many to many if you want for more information, but if you are reading this article and learning things, than stay away from many to many for now.

Crystalfontz LCD – 635 on FreeBSD and OpenSolaris

December 16th, 2009

I have recently gotten a hold of a CFA 635 LCD + Keypad device. Very slick. I was doing some work with it and wanted to use a unix OS to drive the device for some custom work. I ran into a couple minor things when getting the device setup.

1) It works great in windows, just use the USB driver from the crystalfontz website.
2) It works great in FreeBSD (v 6.3 +) but you need to load the kernel module (kldload uftdi or add uftdi_load=”YES” to the /boot/loader.conf file). See below for patch to allow examples to compile.
3) Works great in OpenSolaris if you update to the dev version. I couldn’t find the uftdi (SUNWuftdi package) in the standard 0906 install until I updated to the current dev version (b128+). I didn’t look hard though. After install reboot and you are golden.

In both unix systems, the device would be detected and light up and even get devices to show up in the /dev area. This was confusing at first because they were the wrong devices. You need the uftdi driver loaded and then it loads different/correct devices and it works like a charm.

Here is where it detected properly on my installs.
Freebsd: /dev/ttyU0
Opensolaris: /dev/term/0

I put this down because I had trouble finding this information out on the net and in the crystalfontz forums. There is lots of info for Linux/Win, but less for Unix.

FreeBSD Patch
FreeBSD is missing some entries in the termios.h file. Here are the lines you can add to your code (include/serial.h is recommended) if you are compiling the crystalfontz examples on freebsd. I used the ifndef around each so that it wouldn’t re-declare if it was present so it should be safe to put this in your code even if you are running on a system where they are defined.

#ifndef OFILL
#define OFILL 00000100
#endif
#ifndef OFDEL
#define OFDEL 00000200
#endif
#ifndef NLDLY
#define NLDLY 00001400
#endif
#ifndef TABDLY
#define TABDLY 00006000
#endif
#ifndef CRDLY
#define CRDLY 00030000
#endif
#ifndef FFDLY
#define FFDLY 00040000
#endif
#ifndef BSDLY
#define BSDLY 00100000
#endif
#ifndef VTDLY
#define VTDLY 00200000
#endif

When free isn’t free – enforcement of the GPL just because

December 15th, 2009

All I can say is wow. I read this article http://www.computerworld.com/s/article/9142262/Multiple_consumer_electronics_companies_hit_with_GPL_lawsuit today and I am unfortunately not surprised. This is a perfect example of why many developers shy away from the GPL license when distributing their open source code.

First, I want to say I am a big fan of Open Source. I have used it extensively and even contributed in my own way over the years. The concept that code can be free and the fruits of some one’s labor can be shared is very noble. But I have never understood the idea that you will give your code away for free and then put major restrictions on it. Is it free or not?

How is it that an individual that feels so strongly that code should be freely available and who encourage others to use it and contribute to it would throw a tantrum when some one actually uses it. If you are so worried about some one “ripping off” your free code, then don’t release it for free!

I hear a lot of talk about empowerment and sharing. It is time for people to quit preaching and start walking the walk. Until then, it isn’t free and open is it?

As a side note, the article states that the BusyBox code has most likely not even been modified. I am all for giving back to the community, but legal action because you don’t distribute something that is readily available from the source? Seriously?

Recovering from a compressed ZFS root pool

September 24th, 2009

Opensolaris and ZFS are great, but not without their limitations. A more recent addition is that Solaris can boot from a zpool, but not if you compress it or raidz it. Only single drives or mirrors, and no compression.

A good practice is to setup your root pool for the system, then setup a separate data pool for your files. Since we are using Solaris in this instance as a Virtual Machine host, this model works quite well.

Compression has some advantages. Aside from saving hard drive space, the compressed information means fewer IO writes and reads which can increase performance under the right conditions. Too often though, the warning to NOT compress the root pool is not present when you read the ZFS literature. Don’t compress your root pool!

For those who have done it, you may not realize your mistake until it is too late. If you turn on compression, it doesn’t compress existing files. Compression settings ONLY take effect when a file is written. That also means that turning compression off is not enough if you need to recover your boot drive.

If you have compression turned on and rewrite your boot files, you will end up with an error message on boot indicating file system corruption. Note the following instructions assume root access, add pfexec in front of each command or su – (opensolaris) as appropriate.

To recover, you will need to do the following:
1) Boot from the live Solaris CD
2) Open a terminal
3) Find your ZFS Pools: zpool list
4) Import your ZFS Pool (Only need the root pool, mine is called rpool): zpool import rpool
5) Turn off compression: zfs set compression=off rpool
6) List your mount points (you need the current mount under ROOT, mine is – rpool/ROOT/opensolaris – take note of the mount point, should be / ): zfs list
7) Setup a folder to mount to: mkdir /mnt/root
8 ) Change the mount point on you rpool: zfs set mountpoint=/mnt/root rpool/ROOT/opensolaris
9) Mount your ROOT: zfs mount rpool/ROOT/opensolaris
10) Move to your root pool: cd /mnt/root
11) Copy each system folder. You NEED to copy it so that a NEW copy is made. With compression off, it will write the new copy uncompressed. Moving it isn’t enough. Copy each folder, then move it back to the original name. Here is the command for the boot folder (notice we copy to _tmp, then move it back over the original): cp -R boot boot_tmp; mv boot_tmp boot
Copy each of these system folders in the /mnt/root folder:
- boot
- kernel
- system/objects
- etc
- platform
12) Now you have uncompressed copies of your system folders, unmount the file system: zfs unmount rpool/ROOT/opensolaris
13) Make sure to close the zpool so there is no corruptoin: zpool export rpool
14) Reboot – type the reboot command and remove the live CD, you should now be able to boot into your Solaris install with an uncompressed root pool.

NOTE: If you realize you compressed things before you reboot, you can do this all before you reboot and save yourself the trouble of mounting the live CD. The system/objects folder will not be able to copy some stuff, but you should be able to reboot correctly.

Hope this save some one some time. Use at your own risk.

Ray Pulsipher


Home | My Blog | Products | Edumed | JParks Design | About Us | Portfolio | Services | Location | Contact Us | Embedded Python | College Courses | Quick Scan | Web Spy | EZ Auction | Web Hosting
This page has been viewed 209729 times.

Copyright © 2005 Computer Magic And Software Design
(360) 417-6844
computermagic@hotmail.com
computer magic