Yii PHP interactive shell

During the dark ages, I tested/played with php by writing them on a file and then viewing the result in the browser. But since I was introduced to PHP CLI, that was a thing of the past :)

Assuming you have php-cli installed, you could from your terminal, type:

php -a

in order to initiate the shell. If you want to initiate the shell with Yii objects and data loaded, you need to do it slightly differently. First go into your yii application 'protected' folder and then key in:

// linux
./yiic shell config/main.php
 
// windows
yiic shell config/main.php

assuming of course main.php is the configuration file that you want the shell to be loaded with. From there, you could treat it as a normal PHP shell but with your application loaded. I normally use the Yii shell to run static methods, for example getting the hash of passwords to key in the fixtures, or just simply fooling around testing simple things.


deploying website using git

I once read an article by YongFook titled: 10 Dirty Little Web Development Tricks. Before I continue, I really need to say that I really love the article, it has taught me a lot of things in a very succinct manner.

Moving forward - in the aforementioned article, YongFook suggested using SVN to deploy websites to the server. I thought that this was brilliant and took the wisdom and did the same thing using git. I have been deploying Dapur and this blog using git since their first day on www.

There are many - in my opinion - advantages of doing this. First of all, compared to FTP, deploying using git is blazing fast. This is logical since git only updates the files that has been modified and since git in itself is very fast. Secondly, with some adjustments, you can examine easily if your files have been tampered with. But I love it mostly due to the speed :)

A few assumptions:

  1. You have knowledge using git.
  2. You have root access to your server.
  3. git is installed in your server.
  4. You are already using git for development of your site.

First you need to create a bare repository in your production server in your desired directory. For the sake of this tutorial, let say the name of the folder is ABC (anywhere but in the root folder of your web directory)

// on your production server
git init --bare ABC

Since this is a bare repository, everytime you push to it, it will only update its database, no physical file will be created. In order to update/create physical files everytime you push, you need to name a 'working directory' for it and set a hook to update that directory for every push.

Go in to the directory where you have created the bare repository and look for a folder named 'hooks' and create a file name post-receive and enter the following.

#!/bin/sh
GIT_WORK_TREE=[directory-path] git checkout -f

Next, go into your local development directory and push the master (or any other branch you like) branch to the server. In the example below

git push [username]@[server-ip]:[port][path to the bare repository] master

Then the server will ask the password as per usual, enter them and you are done. Go to the work directory that you have supplied and view the result.

As a side note, if you know how to use virtualbox, you can practice this method first locally before applying them online. Good luck :)


commit -m 'first post'

First post ever!!!

Finally I manage to create a blog for this self-named domain. It took me probably in total less than 12 hours in the span of three days to complete writing the basic code for this blog (apparently, I have other things to do as well).

Why write the code for my own blog? Why not? Plus, I am using mongodb for data storage and since i am still familiarizing myself with this mongodb, I thought that creating this blog would be a great platform for experimenting :)

Just as an introduction entry, I created this blog for the following reasons:

  1. to have an online log of things that I have learned (linux, php, databases, javascript - things like that, no life lessons to be found here)
  2. to publish my portfolio
  3. and because some stranger said that every web developers need to have a blog. Obviously, I am a sheeple.

I hope I would not turn this blog into a rant space, for me to make my rants public when I can't contain them to myself. I heard people use twitter for that, another thing I need to learn how to utilize, sigh, I feel old.