Archive

Archive for the ‘Hobby’ Category

PHP 5.3 symlink() in Windows Vista and Server 2008

June 17th, 2009

I just discovered that Vista can create symbolic links via the command mklink! It performs the same thing as ln in linux with both hard and soft links. My understanding of links is fairly limited but I use them on my web server to apply seam-less templates. Until now, this was something that I could only test on my web server and not my Windows 7 development PC. PHP 5.3 automatically uses the mklink command when you use symlink() but the problem comes with enabling it in Windows Vista or 7.

If you pull up a command prompt and try to use mklink, you’ll see something like this:

D:\Web>mklink /D nnnnn.com\content templates\bluemoon
You do not have sufficient privilege to perform this operation.

Or PHP will throw this back at you:

Debug Warning: /includes/templates.inc.php line 78 - symlink() [function.symlink]: Cannot create symlink, error code(1314)

To fix this:

  1. Bring up your run box, type “secpol.msc” and click OK.
  2. Navigate under the Security Settings \ Local Policies \ User Rights Assignment folder.
  3. Find “Create symbolic links” and add the Users group to it.

I think you need to restart your computer or something after doing this.

Josh Guides, Web Development , , , , , ,

Install PHP 5.3.0 on CentOS 5 as CGI along side PHP 5.2.9

June 16th, 2009

Well, turns out I’d rather play with just PHP 5.3 RC4 for now. Here is my guide to installing it onto my CentOS 5 64-bit VPS from 1&1.

Update: PHP 5.3.0 has been released and there are some changes.

It went pretty smoothly. Here is the guide, minus the hours of trial and error, of course:

First, install anything you may need to compile with.

yum install gcc gcc-c++.x86_64

yum install \
  libicu-devel.x86_64 \
  libxml2-devel.x86_64 \
  mysql-devel.x86_64 \
  libpng-devel.x86_64 \
  libjpeg-devel.x86_64 \
  curl-devel.x86_64 \
  bzip2-devel.x86_64 \
  gettext-devel.x86_64 \
  gmp-devel.x86_64 \
  pcre-devel.x86_64 \
  freetype-devel.x86_64 \
  gd-devel.x86_64 \
  aspell-devel.x86_64

NOTE: You can copy that entire block and paste it, the backslash (\) will carry the command over to the next line automatically.

Next, make the folders for the configs and binaries.

mkdir /usr/local/php53 /etc/php53 /etc/php53.d


Begin, by downloading and extracting the latest snapshot. Don’t use the file name I have below, get it fresh from snaps.php.net.

cd ~
wget http://us2.php.net/get/php-5.3.0.tar.bz2/from/us.php.net/mirror
tar xjf php-5.3.0.tar.bz2
cd php-5.3.0.tar.bz2

# gz: tar xzf php-5.3.0.tar.gz
# bz2: tar xfj php-5.3.0.tar.bz2
# zip: tar xfZ php-5.3.0.zip


Now, set up all of your configuration options. You may want to adjust these. To see what they mean, type: ./configure --help

./configure \
  --prefix=/usr/local/php53 \
  --with-libdir=lib64 \
  --with-config-file-path=/etc/php53 \
  --with-config-file-scan-dir=/etc/php53.d \
  --with-bz2 \
  --with-curl \
  --with-exec-dir=/usr/bin \
  --with-freetype-dir=/usr \
  --with-png-dir=/usr \
  --enable-gd-native-ttf \
  --without-gdbm \
  --with-gettext \
  --with-gmp \
  --with-iconv \
  --with-jpeg-dir=/usr \
  --with-openssl \
  --with-png-dir=/usr \
  --with-pspell \
  --with-libexpat-dir=/usr \
  --with-pcre-regex=/usr \
  --with-zlib \
  --with-layout=GNU \
  --enable-exif \
  --enable-ftp \
  --enable-magic-quotes \
  --enable-sockets \
  --enable-sysvsem \
  --enable-sysvshm \
  --enable-sysvmsg \
  --enable-wddx \
  --with-kerberos \
  --enable-ucd-snmp-hack \
  --enable-shmop \
  --enable-calendar \
  --with-mysql=mysqlnd \
  --with-mysqli=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-mysql-sock=/var/lib/mysql/mysql.sock \
  --with-libxml-dir=/usr \
  --without-mysql \
  --with-gd=/usr


Finally, compile and install!

gmake
gmake install


Lastly, you’ll likely want to use it in Apache… Here is how I set up my domain to use PHP 5.3:

<VirtualHost 74.208.46.111:80>
  ServerName php53.mainelan.com:80
  ServerAlias www.php53.mainelan.com
  UseCanonicalName On
  ServerAdmin "webmaster@mainelan.net"
  DocumentRoot /var/www/vhosts/php53.mainelan.com/httpdocs

  # PHP 5.3
  ScriptAlias /php53-cgi /usr/local/php53/bin/php-cgi
  Action application/x-http-php53 /php53-cgi
  AddHandler application/x-http-php53 .php

  . . .

Josh Guides, Web Development ,

Installing PHP 6 on CentOS 5

June 15th, 2009

I started playing in PHP 5.3 with Zend’s Early Access 7.0 Studio and Server CE and wanted to put it on my web server. Problem: It isn’t released yet and the library name is “php5″, same as PHP 5.2. I didn’t want to replace my production-ready PHP installation with a release candidate. I’m sure that would make my clients happy about unknown security holes, yadda yadda. The only solution is to install PHP 6 and enable it by virtual domain or directory. Please note that it is entirely possible to install PHP 5.3 along side PHP 5.2.9 using the first as CGI, but I want to avoid the confusion.

My CentOS 5 64-bit server is a VPS from 1&1.

Final notes before we get started. I did a “yum update” to bring my system to the latest everything. And no, installing libxml2 or icu via yum won’t help you. You can skip the gmake test, it is 7180 individual tests that can take a LOT of time on slower servers. CentOS is based on RedHat, so this will likely work with it as well.


# install the stuff you need to compile

yum install gcc gcc-c++.x86_64
yum install mysql-devel.x86_64 libpng-devel.x86_64 libjpeg-devel.x86_64

# compile and install icu where php6 can find it

mkdir /usr/local/icu
wget ftp://ftp.software.ibm.com/software/globalization/icu/3.6/icu4c-3_6-src.tgz
tar xkmfz icu4c-3_6-src.tgz
cd icu/source
./configure --prefix=/usr/local/icu
gmake
gmake install
cd ../..

# compile and install icu where php6 can find it

mkdir /usr/local/libxml2
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz
tar xkmfz libxml2-2.7.3.tar.gz
cd libxml2-2.7.3
autoreconf
./configure --prefix=/usr/local/libxml2
gmake
gmake install
cd ..

# compile php6 from http://snaps.php.net
# with libxml2, GD (jpeg + png) and MySQL

# make the config path
mkdir /etc/php6
mkdir /etc/php6.d

# download and extract the latest path, get it from snaps.php.net
wget http://snaps.php.net/php6.0-############
tar xkmfz php6.0-############
cd ~/php6.0-############

# refresh the conf
autoconf

# paste in this entire block and press enter:
./configure \
--prefix=/usr/local/php6 \
--with-config-file-path=/etc/php6 \
--with-config-file-scan-dir=/etc/php6.d \
--with-icu-dir=/usr/local/icu \
--with-libxml-dir=/usr/local/libxml2 \
--with-gd \
--with-jpeg-dir=/usr/lib64 \
--with-png-dir=/usr/lib64 \
--with-zlib-dir=/usr/lib64 \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/var/lib/mysql/mysql.sock

# alt for mysqli: --with-mysqli=/usr/bin/mysql_config

# compile and install. you can skip test if you want.
gmake
gmake test
gmake install

# prepare configuration
cp php.ini-* /etc/php6

# and ONE of the following to set up your php.ini

# if you plan to host pages to the outside world
cp php.ini-production /etc/php6/php.ini

# if you plan to use this installation as a test site for development
cp php.ini-development /etc/php6 php.ini

# if you have issues with mysql:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

Oh yeah, and running along side PHP 5? Toss something like this in a new file: /etc/httpd/conf.d/php6.conf


ScriptAlias /php6-cgi /usr/local/php6/bin/php-cgi
Action application/x-http-php6 /php6-cgi
AddHandler application/x-http-php6 .php6

Now anything .php6 will run php6 as cgi. If you have problems with CGI or MySQL, try nixing SuExec first. If you want to use it, you’ll need to be recompile it with a special folder permission for PHP 6.

Josh Guides, Web Development , , , ,

JavaScript (V8 Engine) and Source

February 17th, 2009

I decided that I would try implementing V8 with the only game engine I am familiar with: Source.  With no intention to finish the project, it should at least be a good learning experience.  But regardless, I didn’t foresee such a hindering factor…  Now, my skills are: BASIC (G/W to .NET 3.5), C/C++ (GNU to .NET), PHP (3, 4 & 5), C#, SQL, HTML/CSS, Java, lua.  With one crucial thing missing…  You guess it: JavaScript.  I don’t know hardly anything about the structure of the language.  I can do a document.write like nobody’s business but beyond that, I’ve got nothing.  Another project failed before it started…. Or maybe I’ll just learn JS.

Josh Game Programming

My first breadboard

September 6th, 2008

I started getting paid for my last hobby so I had to obtain another one, my pick?  Engineering.

It has always been my dream to create devices and program them.  I really never cared what, whether TV remotes, clock radios or smart phones.  I just always wanted the ability to create but I never had the ambition or money to get started.  I used to break apart my radios and other electronics that I’d find lying around.  I never fully understood how they worked but I was determined to learn something from them.  I supposed there was one thing, I learned that four 1.5v batteries powering a single led using tinfoil as a conductor could start a cardboard box on fire.  Like I’d know to use resistors when I was 8 years old.

I came across a website named Sparkfun.  They sell various “goodies” for people that want stuff cheap and in small quantities.  Not to be confused with Digikey, which just supplies components, Sparkfun has layman-termed descriptions, pictures, comments, tutorials and forums.  They also have breakout boards for components too difficult to solder.

After finding a tutorial from Sparkfun named Beginning Embedded Electronics, the dream of starting seemed within reach.  On the second page, it lists the parts I needed, it even added them to my shopping card.  Only delayed by the fact that I forgot to add a breadboard.  With my second order, I nabbed a couple black-light LEDs to play with, neat!

Soldering the Breadboard Power Supply Kit

With my new soldering iron and breadboard power kit, I began my first attempt at soldering.  It seemed to go alright.  I had to reflow some joints and straighten them.  Once it came to testing it, it was a different story.  My multimeter read 3.01V on 3.3V setting and 3.23V on 5V setting.  Not good.  I discovered that the wall wart I purchased wasn’t within the minimum voltage, 5V and the range is 6V to 12v.  Oops.  So with a 6.5V in one hand and my multimeter in the other I tried again.  15mV on 3.3V and 1.1V on 5V.   My first guess, I didn’t solder my joints properly.  Under close examination, that was the case.  My solder didn’t make it all the way though the board in several places.  After reflowing those pads and adding some solder, the final test was very exciting.  Ready?  3.32V and 5.05V!

Breadboard Power Kit (Top) Breadboard Power Kit (Bottom)

The First Project

After making a button turn on an LED, it was time to really get my feet wet and touch the breaker box.  Pulling out my ATmega168 (basically a little CPU that runs at 1 or 8MHz by itself, 20MHz with a quartz).  I did Sparkfun’s little “make the LED blink” then “make it blink faster” using the quartz.  Well, installing someone else’s code was boring.  I wanted to interact with my new toy.  How could I make it think?

Since I had a button, three LEDs (well, more LEDs but only three resistors to use them), and elite programming skills, I’d make a little recording program.  Basically, you enter a pattern using the button and it plays it back after.  It can remember up to 128 button pressed and up to 4.99 seconds per event (a press or release).  The whole process took about two hours to debug, after I released that you have to put a resistor on a button’s pin, it went a lot smoother.

Nark Pattern Record - Version 1

That’s my first completely custom circuit!

On day three with my breadboard, I decided to recode it a bit and make the layout a little prettier.  Here is version two:

Nark Pattern Record (Front) - Version 2 Nark Pattern Record (Back) - Version 2

Code anyone? nark_patternrecorder.zip

Josh Electrical Engineering