Posted by & filed under Apple.

Don’t store IP addresses in a database as a string like (192.168.10.10). That is just the human readable form of that number. You want to store it in the database as an integer.

MySQL has built in functions to handle converting a dot-notation ip address to an integer equivalent.


mysql> SELECT INET_ATON('192.168.0.10') AS ipn;
+------------+
| ipn |
+------------+
| 3232235530 |
+------------+

mysql> SELECT INET_NTOA(3232235530) AS ipa;
+--------------+
| ipa |
+--------------+
| 192.168.0.10 |
+--------------+

But, I needed this type of functionality in PHP itself. Long story short, I’m using Doctrine to handle the relationship that PHP has to the database and I need to convert the human readable dot-notation IP address to the integer style (unsigned integer that is).

PHP’s built in function ip2long comes close, but there is a little bit more to work the magic.

$ip = long2ip(ip2long("192.168.1.10"));
print sprintf("%u", ip2long($ip));

sprintf

is used to convert the signed integer to an unsigned one.

Ready to be inserted into the DB.

Posted by & filed under Apple.

I’ve set up my project on a new server getting prepared to go live. With that comes, moving around some files getting things ready. One thing I’m working on it getting the Zend_Tool command line working.

On the server, I’ve configured

APPLICATION_ENV

to be

production

via

.htaccess

Problem

When I run

zf.sh show doctrine

it errors out because it’s trying to use my “development” DB config rather than the “production” one. I’m not sure how to get around this yet.

Solution

Not pretty, but you have to edit the source of the Zend Framework. The file to edit is
ZendFramework/library/Zend/Tool/Project/Context/Zf/BootstrapFile.php

Here is the diff for what needs to be changed.


--- BootstrapFile.php (saved version)
+++ (current document)
@@ -106,9 +106,11 @@
define('APPLICATION_PATH', $this->_applicationDirectory->getPath());
$applicationOptions = array();
$applicationOptions['config'] = $this->_applicationConfigFile->getPath();
+
+ $env = getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development';

$this->_applicationInstance = new Zend_Application(
- 'development',
+ $env,
$applicationOptions
);
}
,

Then you need to add the APPLICATION_ENV environmental variable to your shell.

In OS X, I’ve found this to work:

Insert this at the end of your .bash_profile

declare -x APPLICATION_ENV="local"

Now you can declare an environment in application.ini that works for the Zend Tool (and ZFDoctrine in my case).

Posted by & filed under Server Admin.

ionCube

http://www.ioncube.com/

For better or worse, ionCube is an encryption method for those that want to protect their code. A pain the neck for system admins, but some want to protect their PHP code, whatever.

Problem… Zend Optimizer +

Zend Optimizer+ does not play well with ionCube for whatever reason, so it’s really picky on what order they get loaded during startup. It’s important to put the configurations in the correct order, or it will just error out during start up.

Installing ionCube

You’ll want to grab the loader files from here

http://www.ioncube.com/loaders.php

I downloaded and unzipped them to

/usr/local/ioncube

Edit php.ini file

Since ionCube is a Zend Extension and not a Zend Module (what’s the difference? I couldn’t tell you, but there is a different) we need to open up the file

/usr/local/zend/etc/php.ini

and at the very bottom it should look something like this.

; Local Variables:
; tab-width: 4
; End:
[Zend]
zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.2.so
zend.install_dir=/usr/local/zend
zend.conf_dir=/usr/local/zend/etc
zend.ini_scandir=conf.d

Of course the important line is the ioncube line, it’s important that it appears before the other lines.

Big Note about versions

It wasn’t immediately obvious to me, but you need to match your PHP version with the version of ionCube (You can tell I’m using PHP version 5.2).

Verify install

After it’s done you can restart the web server (if the web server doesn’t start check your log files for clues). Then go to the Zend admin panel to see the PHP INFO page. You should see a section that looks like this….

php-info-ioncube.png

BD… BD.. BD.. That’s all folks

porky-pig.jpg

Posted by & filed under Apple.

Zend Framework… awesome.
Doctrine ORB… awesome.

Both of these combined…. PURE AWESOME.

I set up a project just at it says to on this page http://github.com/fmntf/zf-doctrine. It took some doing, but I got it working and was quite happy with my initial results. Then I needed to start a new project, so I just copied all the files, tweaked the DB name was flying with a new project… with one caveat.

One of the modules I created using a YAML file was not getting created in the DB when I ran zf build-project doctrine --reload. It was frustrating, I tried changing a bunch of things.

In the end the whole problem was that the module folder didn’t have a controllers folder and that was it. So I created a controllers folder and then it created the corresponding tables in the db. I think this code has much to do with it

application/Bootstrap.php
bootstrap(‘Frontcontroller’);

$fc = $this->getResource(‘Frontcontroller’);
$modules = $fc->getControllerDirectory();

foreach ($modules AS $module => $dir) {
$moduleName = strtolower($module);
$moduleName = str_replace(array(‘-’, ‘.’), ‘ ‘, $moduleName);
$moduleName = ucwords($moduleName);
$moduleName = str_replace(‘ ‘, ”, $moduleName);

$loader = new Zend_Application_Module_Autoloader(array(
‘namespace’ => $moduleName,
‘basePath’ => realpath($dir . “/../”),
));
}
}

}

Posted by & filed under Server Admin.

Every server administrator likes to sleep at night and every server admin knows server updates could prove disastrous. Just found out that RPM and Yum allow you the ability to rollback an update if some how it sent your system into a choking fit.

In your /etc/yum.conf add this in there somewhere

tsflags=repackage

This will repackage all your old files from the package (including config files) and store them in /var/spool/repackage

Also add the file /etc/rpm/macros and place this in that new file

%_repackage_all_erasures 1

When things go wrong

If you want to rollback changes to a certain time, then just issue commands like


rpm -Uhv --rollback '9:00 am'
rpm -Uhv --rollback '4 hours ago'
rpm -Uhv --rollback 'december 25'

Untested Yet

This is just stuff I’m reading, I have yet to test this under fire, maybe I’ll play around on a test server

Resources

http://dailypackage.fedorabook.com/index.php?/archives/17-Wednesday-Why-Repackaging-and-Rollbacks.html

Posted by & filed under Apple.

IMG_3623.JPG

I installed Zend Server CE on one of my machines. The next day I noticed that you could not checkout from the website. It would bring you to the to the Billing Address, then after you hit “continue” it would redirect you back to the checkout page. No errors that I could see.

Then I remember a problem I had many moons ago that was very similar and a forum comment jogged my memory. Magento is looking for a Com.php file buried deep in the bowls of Zend Framework.

Did you know that Zend Server includes the latest copy of the Zend Framework? Yes and therein lies the problem, the Zend Framework version of Zend Server was overriding the built in Zend Framework of Magento.

Easy solution

Open up your .htaccess file and add this section in there somewhere. This will reset your include path, Magento will build this for you anyway so it shouldn’t cause a problem.

###########################################
## Reset Include path

php_value include_path "."

Resources:

http://www.magentocommerce.com/boards/viewthread/28231/#t200692

Posted by & filed under Apple.

This was a strange error with Magento. I was in a product, trying to upload an image. The image would upload fine, but then error out with “Upload HTTP Error”. I changed permissions up and down the /media and /var directories and made them as loose with permissions as I could.

Still no change.

Then I happened upon this comment in the forums.

To anyone that has a HTTP upload error AND has a password protected store directory (for under construction reasons):
remove the directory password protection and you’ll be able to upload your files again! That was what happened to me.

BINGO!

I removed the password protection for the admin (not the Magento password, but Apache basic password protection).

Reference:

http://www.magentocommerce.com/boards/viewreply/154831/

Posted by & filed under Apple.

Have you ever wanted to have a link show as “Active” when a users is on that link? If you have a navigation at the top of your site and you want to visually indicate that the visitor is on that link, then you would usually add and “active” class to that link and style it appropriately.

This little snippet of code will do that.

<code>
$(document).ready(function(){
var path = location.pathname.substring(1);
if ( path ) {
$(‘.header a[href$="' + path + '"]‘).addClass(‘active’);
}
});

</code>

location.pathname.substring(1); will return the url that you are on, subtract the hostname name.
a[href$="' + path + '"] looks for all anchor tags inside of the header block whose end match the path.

This is pure genius.

References:

http://docs.jquery.com/Tutorials:Auto-Selecting_Navigation

Posted by & filed under Server Admin.

This summarizes how I currently set up my servers so that I can have multiple developers accessing certain client files, but retain control on which clients. The key to this whole process is groups.

Users

Create user accounts for your developers.

# useradd developer1
# passwd developer1
# useradd developer2
# passwd developer2

Groups

Create groups that section off your clients. For example.

# groupadd client1
# groupadd client2

Add apache to your groups

The web server is going to need access to the files so we will add apache to any groups we create for this purpose.

# usermod -a -G client1 apache
# usermod -a -G client2 apache

This will add apache to the groups client1 and client2.

Add developers to your groups

Your developers need to access your client files as well so we assign them to the groups. This will assign developer1 -> client1 and developer2 -> client2. Fun stuff.

# usermod -a -G client1 developer1
# usermod -a -G client2 developer2

Note: the “-a” appends, if you don’t have this option, then it overwrites the users groups list, not good.

You could also section off your groups in other ways, such as by website.

DocumentRoot Folders

The web server folders will be located at /var/www/. So you will have :


/var/www/client1
/var/www/client2

Setting the setgid bit


# chmod 2770 /var/www/client1
# chmod 2770 /var/www/client1

Assigning User and Group ownership to the directories

This will have to be done by root, because you cannot assign ownership to another person unless you are root. Also, I created a dummy user of “www” to be the user owning the files, it doesn’t matter who owns the files because we are not relying on that part of the permissions.

# chown www:client1 /var/www/client1
# chown www:client2 /var/www/client2

The permissions on these folders will now look like

#ls -l /var/www/
drwxrws--- 6 www client1 4.0K Apr 14 15:28 client1
drwxrws--- 6 www client2 4.0K Apr 14 15:28 client2

This will ensure that all files and folders created below this directory

Result

Developer1 can access Client1′s files, change them, create new folders/files, but cannot get to Client2′s files. Developer2 has the visa-vers result.

NOTE: any new file created by the developers will be owned by the developer and the group (e.g. the ownership will be developer1:client1). This is not a problem since we are not really checking user level permissions.

Helpful commands

Set the setgid on all folders.


# find ./* -type d -print0 | xargs -0 chmod 2775

Set all files to appropriate permissions


# find ./* -type f -print0 | xargs -0 chmod g+rw

Posted by & filed under CSS.

We all know that IE is full of bugs and just plain sucks as a browser… if you didn’t know that you can drop your geek badge off on the way out. So today I ran across the Z-Index bug in IE7.

Sometimes you’ve seen this behavior before:
Screen shot 2010-05-13 at 12.15.21 PM.png

The fix is to give the parent of the element with a z-index a slightly higher z-index

 

Content Here

 

Resources:

http://brenelz.com/blog/squish-the-internet-explorer-z-index-bug/