SQLite and PHP5 in LAMP

FOSS — Tags: , , , — admin @ 11:54 am

It seems that most articles written about SQLite and PHP are at least two years old and might leave some feeling like they are outdated and do not work. Here’s something recently dated (relatively speaking, assuming you’re reading this in 2008).

This article will help you get sqlite working with a directory hosted in your /home that is symlinked to /var/www

Using your favorite package manager, install a LAMP (Linux, Apache, MySQL, Perl) server. Ignore the fact that you are installing M (for MySQL).

Next, use the package manager to install php5-sqlite (NOTE: this is assuming that your package manager installs PHP5 by default)

Restart the apache webserver

sudo /etc/init.d/apache2 restart

And now php5-sqlite should be playing nice with apache.

At this point, I ran into trouble. I couldn’t get any examples of sqlite within PHP to work properly. The problem: permissions.

Create the directory that will host the files.

mkdir ~/mytest

Change the group permission from your username to www-data

sudo chgrp www-data ~/mytest

Create the symlink to the web directory

sudo ln -s ~/mytest /var/www/mytest

Rejoice in an sqlite-capable directory (specifically located at http://localhost/mytest). Give it a test with the example here (but in this example remove the “unsigned” part of “unsigned primary key” first) or here.

Three Door Monty

Here’s a thought experiment for you.

You’re on a game show and you are given the opportunity to choose from three doors. Behind one door is a great reward. Behind two of the doors are goats (which you probably don’t want to win).

You choose one of the doors but the host says he will open one of the doors as well.

Say you chose door A and he opened door B. Now he presents you with the option of changing the door you originally chose, A, and switching to door C.

Is it in your interest to swap doors?

Interestingly enough, yes it is. How so? Consider this.

The host opened up “every door but yours and another door seemingly at random”. What if the host had done so with 100 doors? You choose door 17, he opens every door except door 97. Now there are 98 open doors and 2 closed doors. The host knows which door has the prize and he knows that you originally had a 1 in 100 chance of choosing the winning door. Effectively, the host now turned your odds to almost a 99 in 100 chance of choosing the correct door if you make the switch.

Whether it was 100 doors or 3 doors, the odds better favor you if you always make the switch.

You see that, right?

Well… Write a simulation and figure it out.

You were burned

Uncategorized — Tags: , , , , , — admin @ 1:43 pm

I’m in the habit of reinstalling my operating systems every couple months. It’s just something I do and I suppose it keeps me in practice. To the point, this weekend I had planned on reinstalling the OS’s on my main PC. This means whiping the data, resizing the partitions based on how much space I took up in the previous months, and then reinstalling WindowsXP on one partition and then (hopefully) Ubuntu on the other.

The only thing new this time around, compared to the previous installation two months ago, was the inclusion of another 500GB SATA2 hard-drive during installation.

Windows installed fine, being the main reason for the reinstall in the first place (Hello, windows bloat?). My next step would be to reinstall Ubuntu.

I recalled that back in April I encountered a problem with the installation on my PC. It didn’t like my hard-drive setup or something like that and I needed to start the installation with the “pci=nomsi” command (Press F6 and then type pci=nomsi <enter>).

This is where I encountered my problem, Friday night, which has led me up to this point Sunday afternoon. The disc somehow became corrupt. Every time the base-install would get to the point where it would install mii-diag it would debootstrap red-screen me. I won’t expect you to have ever heard of that .deb package as I never had. That file was corrupt, along with a few others.

I fished around for my Ubuntu server installation, got that installed but with some funny side-effects (duh, I wasn’t looking for a server install). Next up, I downloaded the 8.04.1 Ubuntu .iso and burned that (at full speed) and tried the install. Same problem!

At this point, I thought maybe it was a file being served to me from the Canada repositories that was corrupt so I tried the install again! This time, with the USA repos. And then again with the UK repos… always the same problem.

Now it’s Sunday morning and I decide to check the Ubuntu forums and launchpad discussions. Turns out that if you burn at a fast speed then you, like I did, will get burned. So I’m successfully installing this very moment after a 1xburn of the iso.

Burn your linux distros at a slow speed to prevent a weekend of headaches and time from your loved ones.

VirtualBox Sharing

FOSS — Tags: , , , , , , , — admin @ 1:35 pm

In my spare (and not so spare) time lately I’ve been playing around with Sun’s VirtualBox. I’ve been using it for a long time now, but only recently did I decide I wanted to turn on “shared folders”. The thing is, there is no intuitive way of doing so.

More for myself, than anyone else, this is how I managed to share a folder in my Windows host “x:\shared\” and access it from within my virtual (guest) Ubuntu.

Though it is a bit dated, these instructions pretty much sum it up.

From within the VirtualBox launcher, select the Virtual OS that you want to share with. Click the settings button and select “Shared Folders” from the list. Click the little ‘+’ folder on the right side of the “Shared Folders” screen and create a directory that you want to share. Odds are you’ve already done that, which is why you’re here looking for the next step.

Start the Ubuntu VirtualBox and log in.
Open a terminal and type
sudo apt-get install build-essential module-assistant
followed by
sudo m-a prepare

I don’t understand why, but that’s what the instructions say. Now this is where I ran in to trouble (and maybe you did, too). A Google search will result with instructions telling you to “install Guest Additions” but they don’t tell you how. Here’s how.

You already have the virtual Ubuntu running so press the escape key (right-control by default) and you’ll notice along the top of that window is a “Devices” button.

Press the "Devices" button.

At the bottom of the menu that opens is where you’ll find “Install Guest Additions”.

Press "Install Guest Additions..."

For me, nothing seemed to happen. It appears that in the background VirtualBox downloaded a 10MB .iso to the VirtualBox directory.

Press "Mount CD/DVD-ROM" > "CD/DVD-ROM Image..."
Double-Click "VBoxGuestAdditions.iso"
type
sudo sh /media/cdrom0/VBoxLinuxAdditions.run

Though if that last command doesn’t work then you may have to mount it

sudo mount /dev/cdrom

or do what I did and navigate to the /media/cdrom0/ directory within a filebrowser (I used rox) to have it automatically mount the drive. Then try the command again.

Finally, mount the shared folder to a directory in the virtual OS

sudo mkdir /mnt/host
sudo mount -t vboxsf shared /mnt/host

Notice that you omit “x:\shared\” and reference the shared drive simply as “shared”. Now you can read (and write) files to the host folder through /mnt/host

Next Page »
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2008 n3wt0n! | powered by WordPress with Barecity