Chris Tankersley

· PHP Jack of All Trades ·

Within a few days I will be changing server hosts for dragonmantank.com, but if all goes well no one will be the wiser (except for the fact I just told you...) Anyway, if the site is acting somewhat funky, it is probably my doing.

The site has been moved, and as you can see I'm in the process of rebranding it. Upgrading Wordpress caused all the catagories to disappear so I'll be fixing that as soon as I can.

Posted on 2008-07-15

Comments


One of the aspects that I believe that has kept PHP from gaining significant ground as a legitimate enterprise language is that it hasn't had the tools to prove that it is beyond merely a hobbyist's tool or just merely a language that is good for building prototypes of an application. I don't think anyone will say that PHP slows down the development process, but a lot of people outside the PHP community (and inside) would say that PHP can make for very sloppy, insecure code.

They would be correct. One can say that about any language but PHP enables just about anyone to sit down and build an application without them really needing to know what they are doing. PHP gives the coder a large amount of power without babysitting them. This strength has also caused a lot of problems as it has let coders get away with a lot of things that have lead to large security holes.

One thing that can help mitigate a lot of bad coding mistakes is to use a good set of tools to help the coder make the correct decisions. While nothing can replace good training in both PHP syntax and coding in general, one of the strongest tools a coder can give themselves is a framework that has taken care of many of the common tasks associated with application building. The Zend Framework, while being a somewhat new kid on the block in terms of frameworks, gives a coder a large amount of usable code to speed up development while making sure that good design decisions are enforced.

Before I get too far, I should explain what the Zend Framework is. The Zend Framework an at-will application framework for building applications. This means that a coder has the ability to pick and choose which parts of the framework that they want to use and how they want to use them, unlike full-stack frameworks Ruby on Rails or symfony which tend to confine the coder into a specified way of setting up and building an application.

Do What You Want

There are people on both sides of the camp as to what kind of framework one should use, but the beauty of an at-will framework is that a programmer can use only what they need. Don't want to build a database abstraction layer? Just pull in Zend/Db.php . Want an easy way to manipulate RSS? Include Zend/Feed.php . Accessing Google's APIs? Take a look at Zend_Gdata.

The best part is the programmer is not constrained to just what the Zend Framework supplies. You are more than welcome to use your own DB objects, RSS manglers, or custom hooks into whatever. If you need something, why reinvent the wheel when Zend has taken the time to put such useful code into an easy to use system?

The Zend Framework can even extend full-stack frameworks that allow outside objects. The symfony project doesn't contain code for every programming problem out there, so they built in a mechanism for bringing in outside code. If you need to manipulate PDFs, you can bring in the Zend_PDF code into your symfony application and still save yourself time compared to attempting to build a PDF system inside symfony.

** Look Ma, I Can Do Full-Stack Too!**

Yes, I said that the Zend Framework is considered an at-will framework, and it is. The Zend Framework is such a well designed and powerful framework that it also pulls double duty as a full-stack MVC (model-view-controller) framework. While it will not set up the folder layout for you like some full-stack frameworks, Zend does have a suggested folder layout that follows the standard MVC rules.

Throw in an extremely short and generic boot strap file and you have yourself the skeleton for an MVC application that is ready to take on building a brand new application from scratch. All of the Zend Framework components fit together and play nicely to build just about any sort of application that you need.

** It Takes a Village**

All of the advantages of the Zend Framework are naught if no one can figure out how to use it. The guys working on the framework take great care in their documentation, not only at the code level to generate API documentation via PHPDocumentor but to also write and keep an up-to-date usage manual online with code examples online at the Zend Framework website.

In addition to documentation, there is a lively community available on the Zend Framework mailing lists. There is a great signal-to-noise ratio on the list. Contributers to the framework are always willing to lend a helping hand and take suggestions on the direction that the framework is heading. Even the trolls are taken care of in short order and such threads are short and quickly ended in a professional manner.

You can also get updates on what is going on via Twitter and Zend's DevZone. Many of the contributers are constantly writing great tutorials to better explain some of the more esoteric sections of the framework (Form Decorators, I'm looking in your direction).

** Why, as a Programmer, Should I Care?**

The Zend Framework is flexible enough to do just about anything that you want it to do. Just need a piece? Great. Want to build a web app from scratch? Go ahead. Need help? There is plenty available. The Zend Framework is one that doesn't care if you are updating an application, converting it to something like MVC, or starting from scratch, it just worries about helping the programmer get results.

Posted on 2008-05-13

Comments


What happens when that server that was always humming along nicely all of a sudden needs you to log in as root to check something or install something new. What was the root password? Didn't it just get changed? All of a sudden, the cold sweat starts - the root password is unknown. What do you do?

Reset it! Thankfully there are a few ways to do this.

Depending on exactly what is wrong with your system, there are three different ways that the root password can be reset (not recovered). Some of these steps will be common to the different methods but a time may come when one method works on one system but not another. As you go down the list, the attempts to reset the password become harder and harder.

1. Use a user with sudo access

If you are lucky, you have access to a user that has sudo access. All you have to do is type in the following command to reset the root password:

$ sudo passwd

Type in the new password, confirm it, and you are all set. Of course, if you have sudo access then you probably can run the command that needs root access using just sudo, and this assumes that sudo access has actually been set up for a user.

2. Reboot into recovery mode

If you don't have access to a user with sudo or sudo is not installed on the machine then the next best thing is to reboot into recovery mode (MacOSX/*BSD users may know this as single user mode). Many newer distros put a GRUB entry into the boot menu to do just this.

Simply shut down the machine and when the GRUB menu appears (this may require hitting ESC or another key to have this appear at boot), select the upper-most kernel entry that ends in (recovery mode) or something similar. On my Ubuntu workstation, this is labeled:

Ubuntu, kernel 2.6.20-16-generic (recovery mode)

The machine will boot into a special shell that is used to fix the machine with a user that has full root access. Once you get to a prompt, just type in:

$ passwd

and you can enter the new password, confirm it, and reboot. Now the root account has the password you just entered.

** 3. Boot off of a Rescue/Live CD**

This is probably the last resort if your boot menu doesn't have a rescue option. Check with your distribution and see if they offer a Rescue CD (Redhat-variants usually do). This Rescue CD should drop you into a shell to run the commands needed.

If your distro does not have a Rescue CD, download a LiveCD like Helix and use it. I recommend Helix not only because it is useful as more than a rescue CD, it lets you boot straight into a command line instead of waiting for a GUI to load.

The other thing you will need to know are the mount points for your installation. If possible, before you reboot the machine, run the following command:

df -h

This will give you an output similar to the following:

Filesystem     Size      Used      Avail     Use%      Mount On




/dev/sda1      3.2G      1.4G      1.7G      46%       /




/dev/sdb1      34G       29G       3.9G      88%       /home




/dev/sdc1      3.9G      586M      3.1G      16%       /var

Write this information down as we will need it when we reboot.

Now that we have everything that we need, boot from your CD. After a few moments you will be greeted with a command prompt, but this is may not be a prompt for your installation (unless this is a Rescue CD, in which case it will probably auto detect your mount points).

If you are not running as the root user by default, change to the root user (See your CD's documentation).

If your mount points were not automatically detected, you will need to mount enough of the file system to run the passwd command. Assuming that we do not have /usr/bin and /etc on seperate mount points, just run

$ mount /dev/sda1 /mnt

to mount what we need.

In the df output above, we can get away with mounting just /dev/sda1, but this may not be the case for you. For example, if you had

/dev/sda1     /




/dev/sda2     /usr




/dev/sda3     /home

Then you would need to do

$ mount /dev/sda1 /mnt




$ mount /dev/sda2 /mnt/usr

to get access to the passwd command and the /etc/passwd file.

Now that we have everything mounted, we can switch to our system by typing:

$ chroot /mnt

and any commands that we run will be as if we are on our installation, not the live CD. Run the following commands to reset the password:

$ passwd

$ exit

$ reboot

The CD should unmount everything cleanly, shut down and then reboot the system.

Hopefully one never has to reset the root account on their machine, but the time may come. It might be easy or it might be hard, but it can be done.

Posted on 2008-02-28

Comments