I recently decided to have a look at a new PHP framework called Yii (-well new for me, it was first released 3 years ago!). I’ve heard a few good things about it so I decided to check it out. There are a few good tutorials for it on their website, however on first impressions it doesn’t seem quite as well documented as other PHP frameworks like CakePHP or Codeigniter.

Starting with their first blog tutorial, I installed the framework and started trying to create a skeleton application.

Downloading Yii Framework

No problems here. Downloading the latest stable release of the application is very easy. Download it from here and extract it to either your wwwroot directory or wherever you store all your site files.

Installing Yii Framework

For me, I keep all my files on a separate hard disk, so I set up a virtual host:

<VirtualHost *:80>
        ServerAdmin adminemail@yourdomain.com
	DocumentRoot "F:/yii/test"
	ServerName yii.local
	ErrorLog "C:/wamp/bin/apache/Apache2.2.17/yii.log"
</VirtualHost>

Then added yii.local to my hosts file in c:/windows/system32

127.0.0.1 yii.local

You can test you have everything you need installed by restarting apache and then typing http://yii.local/requirements/index.php into your browser.

Creating a Skeleton Project

This is where I ran into a few problems. To create a new blank project you need to use Yii’s command-line tool. But before run cmd.exe from the start menu check your eviromental variables are set up correctly!

Click on your Control Panel -> Advanced System Settings -> Environment Variables

Find your system variables and look for one called ‘Path’. Highlight it, click edit, and make your you have a path to your php install there. For example, I’m using WAMP and my php path is:

C:\wamp\bin\php\php5.3.5

Make sure you don’t link to the php.exe directly here. This should only be the path. Yiic will work out which file it needs.

Now you can run cmd.exe. Change directory to the folder that has your yii framework in. For me this was F:/yii so I typed this into my command prompt:

F: //this will change drives from c: to my f drive.
cd yii/framework

Now you are ready to create the application. Type:

yiic webapp ../test

This will create a new skeleton web application in a folder called ‘test’ outside the yii framework directory.

Finished!

Open your browser at http://yii.local to find your new web application ready and waiting for you!

Troubleshooting

If, when generating a new project through the command line you get the following error:

‘php.exe’ is not recognized as an internal or external command, operable program or batch file

Double check your environment variables are set up correctly.