Skip to content


Getting Started with the Yii Framework

This entry is part 2 of 8 in the series Learning the Yii Framework

Many, many moons ago I wrote a post introducing the Yii framework. It’s a framework for creating Web applications using PHP 5 (or greater) that I’ve really liked since I originally started with it. Ruby on Rails was the first Web development framework I personally used (back in 2005) and Zend was the first PHP framework. I love the former, and Yii is quite like it in many ways, but I never really took to Zend. In that first post, I discussed just downloading and testing Yii; here I’ll walk through creating the beginnings of a Web application.

(Note: In October 2010, I’ve updated this entire series to reflect changes in Yii since this series was written, and to take into account feedback provided through the comments. Some outdated material will be crossed out, but left in to reflect how things have changed since the series was begun in June 2009.)

For the specific example, I’ll use an employees-departments Web application, with a list of departments and a list of employees, each employee being in only one department. This is a classic go-to example, as it’s easy to understand, practical, uses more than one database table, and is extensible in many ways. To start, though, you’ll use the command-line Yii tools to create the application’s frame. If you’ll be putting the site on a server that you do not have command-line access to, then you should install a complete Web server (Apache, PHP, MySQL, etc.) on your computer, run through these steps, then upload the finished project once you’ve completed it. If you don’t already have a Web server on your computer, I’d recommend using XAMPP (for Windows) or MAMP (for Mac), both of which are free and extremely easy to use.

The first thing you’ll need to do is make sure you have the latest version of the Yii framework. My first post discusses how to get it. Then you’ll want to put the framework folder in a logical location on the server. You don’t need to put it within the Web directory (arguably, you shouldn’t) but nearby, like in the directory below makes the most sense. For example, on my setup, the htdocs folder is the Web root, which is to say that http://www.example.com points there.

My directory structure.

My directory structure.

Tip: If you’re going to be using Yii for multiple sites on the same server, place the framework folder in a logical directory relative to every site. That way, when you update the framework, you’ll only need to replace the files in one place.

Next, you’ll need to get yourself into a command-line environment, like a DOS window/console on Windows or the Terminal application on Mac OS X (and some versions of Linux). Then move yourself into the framework directory. On my server, this means executing this line:

cd /Users/larryullman/Sites/YiiBlogSite/framework

You’ll need to change the particulars to match your setup.

The next step is to tell the yiic application, found in the framework folder, to create a new site. The syntax is

yiic webapp path/to/directory

But before you even begin to use this command, let me explain it a bit, as it’s very important and can be complicated. The yiic file is an executable that runs using the computer’s command-line PHP and that really just invokes the yiic.php script. You may be able to call it using just yiic or using ./yiic (i.e., run the yiic command found in the current directory). Or you can more explicitly call either script using php yiic or php yiic.php. Or you may need to indicate the PHP executable to be used: C:\php\php.exe yiic. You should try the variations on this command, as applicable to your computer, just to make sure you can invoke yiic, prior to trying to create the Web application.

Besides properly executing the yiic script, another gotcha can arise if you have more than one version of PHP installed on your computer. To confirm the version being used, run php -v (again, you may need to provide the full path to the PHP executable). On Mac OS X and Unix, you can use which php to reveal the PHP executable being used by the command php. These steps can help solve confusing problems. For example, on my Mac, I use MAMP Pro for PHP and MySQL Web development, but when I execute PHP through the command-line, I’ll actually be invoking the PHP installed with the operating system. This can be a problem, as the different versions of PHP may or may not meet the Yii requirements outlined in my first post. I know when I first tried this, the command-line PHP (installed with the OS) did not support the required PDO extension, even though the Web version of PHP (in MAMP Pro) did. My solution was to explicitly name my MAMP PHP executable when running yiic: /Applications/MAMP/bin/php5.3/bin/php yiic.

Once you know you’ve figured out the proper syntax for invoking yiic, you follow that by webapp, which is the command for “create a new Web application”. Follow this with the path to the Web application itself. Given the directory structure already indicated (in the above figure), the command would be just

./yiic webapp ../htdocs

or

php yiic webapp ../htdocs

Or whatever variation on that you need to use.

You’ll be prompted to confirm that you want create a Web application in the given directory. Enter Y (or Yes) and press Return. After lots of lines of responses, you should see a message saying that the application has successfully been created. To confirm this, load the site in your browser (by going through a URL, of course):

The Basic Yii Application

The Auto-Generated, Basic Yii Application

As for functionality, the generated application already includes:

  • a home page with further instructions
  • a contact form, complete with CAPTCHA
  • a login form
  • the ability to greet a logged-in user by name
  • logout functionality

It’s a very nice start to an application, especially considering you haven’t written a line of code yet. Do note that the contact form will only work once you’ve edited the configuration to provide your email address. For the login, you can use either (username/password): demo/demo or admin/admin. Lastly, the exact look of the application may differ from one version of the Yii framework to another.

In terms of files on the server, within the application directory (htdocs, for me), you’ll find:

  • assets
  • css
  • images
  • index-test.php
  • index.php
  • protected
  • themes

The assets folder will be used by the Yii framework primarily for jQuery (the JavaScript framework) integration. The css and images folders are obvious. The entire site will also be run through one of the two index files (more on this in the next post). The protected folder is actually the most important one: you’ll edit code found in that folder to change the look and behavior of the site. And themes allows you to create variations on the site’s template, just like themes in a WordPress blog.

Tip: The assets folder must be writable by the Web server or else odd errors will occur. This shouldn’t be a problem unless you transfer a Yii site from one server to another and the permissions aren’t correct after the move.

So that’s the start of a Yii-based Web application. For every site you create using Yii, you’ll likely go through these steps. In the next post, I’ll start demonstrating how you can configure the application, and alter it for an employees-departments example.

As always, thanks for your interest in what I have to say and please let me know if you have any questions or comments.

Larry

Series NavigationIntroduction to the Yii FrameworkConfiguring Yii

Posted in MySQL, PHP, Web Development.

Tagged with , , .


105 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Patrick says

    Larry,

    This is a wonderful tutorial series and you are stepping into my coding career with this at the perfect moment. I had just settled on using Yii and MVC in general last week but really needed additional help.

    I’ve found from your other tutorials you have a knack for explaining well the things one is going to need to understand. Keep up the series when you can, and thanks again!

    • Larry says

      Thanks, Patrick. Much appreciated! I’m glad what I’m writing is useful to you. I should have three new posts on this series this week. Also, in case you didn’t know, I also write books on PHP, MySQL, and more. If you like my writing in these blogs, you’ll probably like those, too.

  2. Patrick says

    I found this helpful for Windows users, so I’ll post it here. It’s a description, from the Yii site, on how to get Yii running on Windows with a wamp server. I found wamp to be, by far, the easiest way to get a PHP5+/Apache server running in Windows. At any rate, wamp creates a nice taskbar controller for starting and stopping the server as well as a link to the root folder.

    I’m very open to better approaches or server installs, if anyone wants to suggest them.

    Here’s the link:

    http://www.yiiframework.com/doc/cookbook/3/

  3. Patrick says

    Following the directions at the link above requires knowledge of how to set PATH variables in Windows. The gist is that you set additional PATH variables and edit the yiic.bat file in a text editor. Watch the paths that are suggested to paste into the yiic.bat file…they probably will need to be modified to reflect the actual paths in your system. I was able to get the yiic command to work from the commandline and generate a site with the hints found at the link above in the last post I made.

    • Larry says

      Big thanks for your comments and for adding some info that might help others. I avoid using Windows when I can, so I don’t have as many Windows-specific tips for this series. Your additions are most appreciated! Larry

  4. William says

    A tip for Dreamhost customers:

    For folks running a Yii app on Dreamhost’s servers, they’ll first need to set the command-line to run at PHP5 (it’s set to 4 by default). Otherwise, an error will occur when trying to create a new ‘webapp’.

    This can be done via ssh and running the following command once logged in: export PATH=/usr/local/php5/bin/:$PATH

    • Larry says

      Many thanks for the input. I don’t use Dreamhost so hadn’t known about this. Cheers, Larry!

  5. Smoothcoder says

    I met the problem on DH. Thanks for the solution William!

    • Larry says

      Glad to hear it. I second my thanks to William as well.

  6. Shridhar says

    Dear Sir/Madam,
    I have successfully installed yii. The requirements page is clear and passed.
    My directory structure is C:wampwwwyii.
    I am unable to Get Started with yii because I am unable to run command line.
    Kindly help me to run yii so that I can progress further.
    with regards,
    Shridhar

    • Larry says

      Okay, well, it’d help to know what operating system you’re using, but presumably it’s some form of Windows. So to get to the command line, you hit Start, then select Run. In the prompt you enter cmd, then click OK. That will get you to the command prompt. Next you’d enter cd C:\wamp\www\yii, which will get you into the Yii framework directory.

  7. hi5s says

    Hi Shridhar, If you still run into errors… try editing the yiic.bat file as follows:

    if “%PHP_COMMAND%” == “” set PHP_COMMAND=php.exe -c c:\wamp\php\php.ini

  8. hi5s says

    Thanks Larry. Good Job.

    • Larry says

      Thanks for saying so! Let me know if there’s something in particular you’d like me to write about.

  9. Shridhar says

    Dear Sir/Madam,
    I have tried what you have suggested and I am sending the message that I received on cmd mode.
    I am using wamp on XP-SP3
    Kindly help me.
    my sincere thanks to your response.
    This is the messege that I get when try to activate yiic.
    ___________________________________________________
    C:wampwwwyii>yiic ‘yiic’ is not recognized as an internal or external command, operable program or batch file.
    _______________________________________
    with regards,
    Shridhar

  10. Shridhar says

    Dear Sir/Madam,
    I have tried something and finally i got this message

    __________________________________
    C:wampwwwyiiframework>yiic
    Yii command runner (based on Yii v1.0.10)
    Usage: C:wampwwwyiiframeworkyiic [parameters...]

    The following commands are available:
    – message
    – shell
    – webapp

    To see individual command help, use the following:
    C:wampwwwyiiframeworkyiic help

    C:wampwwwyiiframework>
    _________________________
    Unable to progress further.
    kindly help me
    with regards,
    Shridhar

    • Larry says

      Right. That’s all fine and good. The next step is to follow this command with webapp, then the path to the directory where the application should be created. See my explanation in the text above.

  11. Shridhar says

    Dear Sir/Madam Larry,

    I am thankful for your help. Still I am unable to reach the required goal i.e., Guest book of yii.

    However as the purpose of MVC is to provide a secured and authenticated website, which, happens by using hierarchy, I wish you could write about creating hierarchy using wamp/yii/ and some time saving methods in doing so please.
    with regards,
    Shridhar.

    • Larry says

      First of all, it’d be “Sir” or just “Larry”. And you’re quite welcome for the help. I’d be glad to continue you trying to help but you don’t say what the problem is. As for MVC, it’s purpose is to define a way to quickly develop and maintain software. I don’t understand what you’re saying about hierarchy at all.

  12. Shridhar says

    Dear Sir Larry,
    I manage lot of e-governance projects using OSS for the government of India. Most of the time my team prefers to use hard-coding technique for developing the required project under MVC architecture. Whereas I insist them to go for techinques similar to yii.
    we use the method of hierarchy to define the levels of authentication with in an application. For example, say user level, Superintendent level, Asst Director level and then Director level in ascending order. Also the dynamic pages which need to viewed by them whichi, will be restricted depending upon the level of the login person. This process we create using hierarchy technique with in MVC.
    I wish to create this using yii by time saving techniques and with accuracy.
    I will be thankful to you if you can help me in this regard using yii or a similar software.
    I am once again thankful for showing interest in my comments and requests and trying to help me.
    with regards,
    Shridhar

    • Larry says

      Ah, I see what you mean. Those are called “access control lists” or ACLs and they dictate who can do what with what. I talk about this some in my post on Controllers.

  13. Shridhar says

    Dear Sir Larry,
    Wish you a very Happy and Merry Christmas.
    Ref: 22.
    Yes Sir, I wish to know that by using Yii, is it possible to prepare such (Access Control Lists) etc speedily? Can you help me in doing it through your write up please.
    Shridhar

    • Larry says

      Thanks. In my Basic Controller Edits post, I introduce Access Control Lists. I’ll try to write about it more one of these days, but in the meantime, you can always check out the Yii documentation.

  14. Shridhar says

    Dear Sir Larry,
    Much pleased with your +ve response. Waiting for your write up. This will help many young software engineers to improve their skills effectively.
    Wish you a VERY HAPPY AND PROSPEROUS 2010!
    with regards,
    Shridhar

    • Larry says

      You’re welcome. Keep an eye on the blog and I’ll see when I can write something up. Happy New Year to you as well!

  15. Shridhar says

    Dear Sir Larry,
    Yes, I was greeted with the page “My Web Application”, when I created the command line folder in my wamp webroot.
    For the sake of other readers: Remaining in the framework folder (in Command prompt) type
    yiic webapp C:wampwwwtest2yii (this is the path of the folder, here it is test2yii created in the wamp webroot folder. You will be see the confirmation:
    Create a Web application under ‘C:wampwwwtest2yii’? [Yes|No]. To accept type Yes and then enter.
    Check the site through URL: http://localhost:xxxx/test2yii/index.php
    For further progress read Mr. Larry Ullman’s Blog.
    Shridhar

    • Larry says

      Glad that’s working for you and thanks for sharing. Just so this is clear for others, that exact command will work but only on Windows with WAMP installed in C:\.

  16. Daniel Shanahan says

    Hi Larry,

    I noticed in your first photo above (http://www.larryullman.com/wp-content/uploads/2009/10/Yii_started_1.png) that the htdocs is inside of the yii folder.

    I am using MAMP (Mac 10.5) and not terribly familiar with it. Anyway, my path is MAMP/htdocs/yii/framework (etc.). I am not clear on where to put my framework folder; seems like it needs to stay in the yii directory. However, my yii directory is in my web root. Any suggestions?

    Thanks.

    • Larry says

      Sorry for that confusion. I just created a folder called Yii for the purposes of these posts. I then put the framework directory in it and created a new htdocs folder. Then I pointed MAMP to use the new htdocs folder for the Web root. So the framework and htdocs folders aren’t really in the downloaded Yii folder. I don’t really have a suggestion except to say not to overthink it. If you want to use your existing MAMP/htdocs folder, that’s fine, you’ll just need to change path references accordingly when you get into the command line (i.e., ../../../htdocs is where the application would be created).

  17. Bogdan says

    Great tutorial ! Very useful for someone who has no knowledge in installing such an application.

    • Larry says

      Thank you for saying so. Very much appreciated!

  18. DevCom says

    Hi All,
    I don’t install WAMP, but i have used Apache, PHP, Mysql by manual configure on XP SP2.
    While i run command yiic webapp ../myweb it show this error
    i have tried to change in yiic.bat on line

    if “%PHP_COMMAND%” == “” set PHP_COMMAND=php.exe -c c:\PHP\php.ini

    still have this error.

    php.exe is not recognized as an internal or external command

    Help please

    • Larry says

      Okay, if you’re getting that error, then you need to explicitly reference the PHP executable. So it sounds like you’d use C:\PHP\php.exe.

  19. Daniel Shanahan says

    Thanks Larry, for addressing my question (#29 above). I moved the framework folder to be a sibling of htdocs and used the command line: cd Applications/MAMP/framework. Then, as suggested, I typed php yiic webapp ../htdocs.

    After I did that, I realized that I really wanted the files to go into a folder within htdoc, so I repeated the process (which is great for practice), typing php yiic webapp ../htdocs/yiiTest. The new directory was created (yiiTest) and populated.

    Your instructions are very helpful as I am a novice with the command-line.

    Thanks.

    • Larry says

      I’m glad you’ve got it working and thanks for letting me know. More practice is almost always a good thing!

    • Sarvesh Jangid says

      Hello Daniel ,
      This helped me set it in Linux.
      Thanks.

  20. Abe says

    ็Hi All Please help me,
    I would like to know one important thing about YII for CODE EDITORS.

    Before i have experience with PRADO i have used Dreamweaver to write code and design interface by add-on Prado Extension PRADO.mxp and it works very well on file .PAGE example when i want a component just write <com:T… and then it shows list of component to select and also press space bar to get property. My question is how can we do like for YII?? Which Text Editor should i use to write code of CHtml and etc for YII please advise me.

    I would like to move from Prado to YII

    • Larry says

      This is a good question but unfortunately I don’t have an answer for you. I have not seen any editor extension for Yii myself, but I haven’t looked either.

  21. Phil says

    Larry, thank you for the great information. I’m curious about one thing though. I also use MAMP and, like you, I had to type in /Applications/MAMP/bin/php5/bin/php yiic webapp…

    I was wondering if you knew of a way to make my mac default to MAMP’s version of php when I type a php command in the terminal.

    Thank you very much!

    • Larry says

      Sure thing. Create a file in your home directory called .bash_profile, if one doesn’t already exist. Then create an alias using this line:
      alias php='/Applications/MAMP/bin/php5/bin/php'
      After that, every time you use ‘php’ in the Terminal, it’ll execute the MAMP PHP.

  22. Phil says

    Thanks, works great!

  23. David says

    Just a point for Vista users. I found that since my web dir was restricted to admin access only, I had to run the command line yiic as administrator – i.e right-click runas administrator – If I didn’t, the command line would just dump – what I can only assume as the yiic.php file to the terminal.
    Obvious really – but something to be aware of.
    Good work on the tuts Larry – I come from CakePHP but I’m finding these a really useful source for learning Yii. Cheers

    • Larry says

      Thanks for that note, David. I don’t have Vista, so wouldn’t have known. And thanks for the nice words!

  24. GargantulaKon says

    A quick tip for anyone using Windows 7. Pressing Shift+Right Click in a folder will add options to the context menu and one of them is “Open command window here”. I use it to quickly go to a specific folder instead of using cd multiple times to get to a path. Finally, Windows 7 added little features to make it better than Vista/XP. You can Shift+Right Click files too to see additional options.

  25. Eduardo Russo says

    Man… you saved my live! I was having really a bad time trying to use Yii.

    I tried MAMP, but when using yiic, I was using OS X PHP, so, nothing worked.

    With your tutorial, now I use MAMP’s PHP and everything is OK.

    Can’t wait to see th other ones!

    Thanks a lot!

    • Larry says

      I’m glad you found the posts to be useful. Thanks for the comments!

  26. Richard says

    Hello Larry,
    I use the LAMP-stack from openSuse together with PHP 5.3.1 from Zend and Yii 1.1.0. The first time I fired up the generated website I got an error-message concerning the used date() function. It complains that there is no proper timezone set. Solution is to uncomment the date.timezone directive in the php.ini file and set it to a proper timezone (see the php-manual for syntax), in my case that was Europe/Amsterdam. Than restart the webserver and the yii generated website fires up without error.
    Changing the error-level in php.ini can also solve this issue but is not recomanded (E_STRICT).

    • Larry says

      Thanks, Richard, for sharing your experience. Just so you, and anyone reading this, knows, that’s not a Yii-specific issue, just something that’s come up in PHP since version 5. Thanks for posting your solution!

  27. Mars says

    Hi Larry,

    great tutorial.

    First, i’m getting the error message same as shidhar.

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

    i tried your solution.

    @setlocal

    set YII_PATH=%~dp0

    if “%PHP_COMMAND%” == “” set PHP_COMMAND=php.exe -c D:\wamp\bin\php\php5.3.0\php.ini

    %PHP_COMMAND% “%YII_PATH%yiic” %*

    @endlocal

    But when i run yiic in cmd, i would get
    ‘Maximun setLocal recursion reached.’ endlessly.

    Pls. help.

    I really want to start w/ yii.

    thank you so much!

    • Larry says

      I don’t know what you mean by my solution, but if you do a full path to the yiic file, it should work.

  28. Mars says

    hi larry,

    sorry to bother you.

    i already figured out how to run yiic. saw the sol’n in the cookbook.
    http://www.yiiframework.com/doc/cookbook/3/

    now, i’m ready for your next tute. :)

    thanks! ^_^

  29. Joe Coder says

    Just an extra note for people who are still struggling as I was with the command prompt (on windows).

    Make sure you include both your php.exe path and Yii framework folder inside your System Variable ‘Path’ on your computer. This is found by right-clicking ‘computer’ from the start menu and selecting properties. Navigate to the advanced system properties and click on ‘Environment Variables…’.

    Add these to your path variables: Separate all paths with a semi-colon… no spaces.
    …old\paths;c:\wamp\bin\php\php5.3.0\php.exe;c:\wamp\www\framework
    (Of course, change your file-paths where needed)

    Also, a handy trick is to restart the command prompt. Variables will be reset.

    From there, there is only one added thing I would suggest, and that would be to use the .bat extention.

    Change the
    “if “%PHP_COMMAND%” == “” set PHP_COMMAND=php.exe”
    To
    “if “%PHP_COMMAND%” == “” set PHP_COMMAND=c:\wamp\bin\php\php5.3.0\php.exe”
    in the yiic.bat file using a text editor

    Then call the .bat file in the command prompt
    c:\wamp\www\framework>yiic.bat webapp ..\newSiteFolder

    That .bat file seemed to run perfectly, giving me the prompt to say Yes|No at installing the new folders. This may be cheating, but everything uploaded nicely.

  30. Paul says

    Hi Larry,

    I am creating a script in Second Life that sends an http request to my yii-powered website.

    I need raw output from my yii view however that isn’t wrapped in the main.php template.

    How can I return results to my http request without it being wrapped in main.php?

  31. Shannon says

    I had an issue running the yiic.bat file via command line. on Windows XP sp3.

    I would get the unrecognised command \Prgram.
    I tried all the options on this blog page.

    including changing the line in the yiic.bat file
    if “%PHP_COMMAND%” == “” set PHP_COMMAND=c:\Wamp2\bin\php\php5.3.0\php-cgi.exe php.exe

    Finally moved wampp directory from
    C:\Program Files\Wamp2\www
    to
    C:\Wamp2\www
    And this corrected the issue.

    Hope if anyone is having the same issue it helps, or if there is a better way please let me know.

    • Larry says

      Thanks for sharing that. I don’t use Windows, if I can help it, so I’m unaware of these little tricks and issues. I’m sure your post will help others!

  32. hefestos says

    Thank’s, i’m checking these tutorial and it’s great.

  33. Jorge says

    Hi Larry

    Just starting to learn Yii. I like your tutorial, I’m going to try it in my Mac with Postgres. I’ll let you know if everything works. Just wondering about yiic… I’ve read at the yii site that it’s been deprecated and we should use Gii instead. I’ve seen you talk about Gii later but, I understand that we still need yiic to create the basic skeleton, as Gii works on an app already created. Am I right?

    Thanks a lot for sharing :)

    • Larry says

      Hello Jorge. Thanks for the comments. I hope things go smoothly for you. Yes, you still use yiic to create the skeleton, but then turn to the Web-based Gii to create the MVC components. I actually still kind of prefer yiic for that stuff, though, as you don’t need to mess with the file permissions as you do for Gii.

  34. Gift Baskets says

    Larry,

    Thanks for putting this out here. Yii is definitely pretty damned easy. I was reading over ASP.net tutorials with Visual Studio and OMG what a PIA. It is nowhere near as easy as this. Just bought your book PHP6 and MySQL 5. I love the fact that you actually write back to every one of your comments. I also love the pictures and step by step stupid user friendly tutorials you provide. I am hoping the book is the same exact way. That is the way that I love to be trained (as if I know nothing from the ground up and don’t presume that I know it). Good stuff. – Wayne – http://www.scrfix.com

    • Larry says

      Thanks, Wayne, for the feedback. I’ve done some ASP.net myself, and did find it to be annoying (all that compiling). Thanks, too, for the book purchase. I hope you like it and I really appreciate the extra support. You should find the book to be similar to my posts, although probably better proofread and with more images.

      • Gift Baskets says

        I was reading some more comments from months ago where people were asking about IDE that would handle YII. I think they mean an IDE that will handle PHP. I am currently using two items to handle and view the code.

        1. Visual Studio with the VS.php addon. This is really nice because of the layout and many items you can do with Visual Studio. The VS.php addon is fantastic and has a million things you can do with PHP.
        2. Dreamweaver warns you when you edit something in PHP and it has an error before you ever save. I really like that. – Wayne
        http://www.scrfix.com

        • Larry says

          Thanks for your suggestions, but I expect they really meant an IDE that recognizes Yii keywords and classes. Many IDEs recognize PHP, but if you’re using Yii, an IDE that can do code completion and such for Yii is a bonus.

  35. Nand2k10 says

    i have read all comments but still problem for XAMPP users
    firstly i opened up cmd from start menu then i went to my framework directory.
    c:\xampp\htdocs\yii\framework>

    once there i ran the command
    c:\xampp\htdocs\yii\framework>yiic webapp ..\testdrive

    and then i got this error:
    ‘php.exe’ is not recognized as an internal or external command,
    operable program or batch file.
    I follow read instruction for edit the yiic.bat file but unable to resolve!
    finally i replace below line in the yiic.bat file now working good so I suggestion to XAMPP user edit the yiic.bat as following instruction.

    this old line replace
    if “%PHP_COMMAND%” == “” set PHP_COMMAND=php.exe

    if “%PHP_COMMAND%” == “” set PHP_COMMAND=C:\xampp\php\php.exe

    • Larry says

      Thanks for sharing that. Much appreciated!

    • Iftikhar says

      Thank you Nand. I was having the same problem with xampp. Now it is solved. I m just the beginner with Yii.

  36. Gareth says

    I am using a Qnap Nas Server, Yii runs fine on it.

    Path to run Yii from command line and create a app found was:
    /usr/local/apache/bin/php yiic webapp /your/Dir/Here
    Hope that helps someone! :)

    Thanks Larry for the tutorial.

    • Larry says

      Thanks for the nice words and for sharing what you learned!

  37. Tyler C says

    Hi, I found your website and im very interested in Yii and I see your still active in answering questions. Im new to programming however decided that PHP and Yii would be the way to go for a beginner like me interested in quality performing websites.

    However as much as ive tried im stuck on something that should be simple. Im using MAC OSX snow leopard using MAMP

    I got here
    “Yii command runner (based on Yii v1.1.6)
    Usage: /Applications/MAMP/htdocs/webroot/framework/yiic [parameters...]

    The following commands are available:
    – message
    – migrate
    – shell
    – webapp

    To see individual command help, use the following:
    /Applications/MAMP/htdocs/webroot/framework/yiic help
    logout

    [Process completed]”

    It makes no sense as I cannot input Web App nor is anything made to my knowledge. It dosent allow me to input anything else. I saw someone using Windows SP3 that looked liked the same problem.

    Im not sure if I configured something wrong. I believe php is updated, I know mamp is, maybe not OSX the code checking seemed a little wired as it stated zend framework 2.5. Maybe that is the problem?

    Im not sure and any help is accepted.

    Thank you

    • Larry says

      If you’re typing “Web App”, two words, as you wrote it, then that’s the problem. As in my post and in the yiic help response, it’s “webapp”.

  38. Manoj Madhavan says

    Larry,

    This is a wonderful series and this series will help me understand how to start off with YII framework. Thanks! Great work.

  39. Stephen Cox says

    Larry.. I’m a long time reader of yours.

    THANKS so much for turning me on to YII. I’ve been using CI for a while, and happen to come across a link to these tutorials. I was like, “What?!! I got to read…”. I’m actually a little stunned. What an amazing framework.

    Thanks again.

    • Larry says

      Hello Stephen. Thanks for the nice words and the feedback. I’m glad you’re liking the tutorials and Yii. For some reason, Yii just fits right for me.

  40. DrDarbin says

    Supper! :)
    I like it! :)

  41. Yogi says

    Hi Larry,
    I have installed latest version of yii Framework. I have WAMP installed on my windows system.
    PROBLEM: When I tried to run the comman in my command prompt i m getting errorl , currently yii is instaled on. ( E:\wamp\www\yii\framework ) this is my folder.

    in COMMAND PROMPT i TYPE : ( E:\wamp\www\yii\framework> yiic ) and getting error like “php.exe is not recognizable as an internal or external command, operable programmer or batch file.

    Please hel me to run in command prompt. or is there any other way for me to setup the project If I DONT WANT TO USE COMMAND PROMPT.

    Thanks in advance.

    - Yogi

    • Larry says

      You’ll need to provide the full path to your PHP executable then. To setup a Yii project, you have to use the command line once.

  42. Noah says

    So there’s no way to install Yii w/o running that script? Why can’t I just download a ZIP file that has the folder structure all mapped out for me so I can start adding my controllers as required like every other MVC I’ve used?

    • Larry says

      To install Yii, you just download the framework and put it wherever you want. To have Yii create a new Web application, you run the script through the command-line.

  43. yang says

    thanks for your contribution~

  44. Wesley Hardin says

    Please change the font and the color. It’s really difficult to read

  45. Jason Bullough says

    First time trying and got an error on my Win32/PHP5.3.2 install after loading up index.php – turns out 5.3.2 requires a timezone set. place this line in the index.php file on line two after the php opener:
    date_default_timezone_set(‘Europe/London’); //choose your location as appropriate

  46. wesley hardin says

    wow! you changed the font!!! It’s so readable and easier to understand now. Thanks. I think I put off reading this tutorial for more than a month because I my eyes were getting tired so fast. I can now continue from where I left off last month. Thanks :)

    • Larry says

      Hello Wesley. Actually, I didn’t make any changes at all, but I’m glad you’re finding it to be more readable now for whatever reason.

  47. Vivek says

    Hi
    I would like to share my initial experience in using Yii for the first time on my WIndows based maching runiing Apache 2.2.18 from Apachelounge / PHP 5.3.6 ( (TS/VC9) / MySql / PhpMyAdmin . All were installed independetly and not as a preconfigured package. Following were the changes I had to do to make Yii framework run successfully:
    1. Enable the pdo_mysql.dll in php.ini
    2. Install the compiled pho_apc.dll for my configuration. I sourced it from http://dev.freshsite.pl/php-accelerators/apc.html
    3. Created a tmp folder in my webroot folder /www/html
    4. Edited php.ini and added the following lines
    [APC]
    apc.enabled = 1
    apc.shm_segments = 1
    apc.shm_size = 64M
    apc.max_file_size = 10M
    apc.stat=1
    apc.cache_by_default = Off
    apc.enable_cli = Off
    apc.file_update_protection = 2
    apc.filters =
    apc.gc_ttl = 3600
    apc.include_once_override = Off
    apc.num_files_hint = 1000
    apc.optimization = Off
    apc.report_autofilter = Off
    apc.slam_defense = 0
    apc.ttl = 0
    apc.user_entries_hint = 100
    apc.user_ttl = 0
    apc.write_lock = On
    apc.filters = “-/phpmyadmin/*.*”
    Especially the “apc.cache_by_default = Off” setting was vital for the PhpMyAdmin to work. Otherwise the apache server would just keep crashing every time that I would launch phpMyAdmin in browser. The apc.filters = “-/phpmyadmin/*.*” setting was tried alone at first but that did not work for me.
    6. Copied the file apc.php (included in the source package at http://pecl.php.net/package/apc ) to my web server
    7. restarted server
    8. load phpinfo to check that that APC module had been loaded

    In addition I had to add the date.time declarationin my php.ini config file.
    So far so good!

    V

    • Larry says

      Thank you for sharing your detailed experience!

  48. Ali says

    Dear Larry,
    I can continue with the following part of the tutotial
    “Once you know you’ve figured out the proper syntax for invoking yiic, you follow that by webapp, which is the command for “create a new Web application”. Follow this with the path to the Web application itself. Given the directory structure already indicated (in the above figure), the command would be just
    ./yiic webapp ../htdocs

    or
    php yiic webapp ../htdocs

    Or whatever variation on that you need to use.”
    I can not execute the above mentioned commands kindly help me and let me know what to do !!

    • Ali says

      I am using window 7 professional and php 5.3.1
      I have done with invoking yiic.php but i can not proceed with “Creating a Web Application” folder !!
      Kindly help me !!

      • Larry says

        Well, although you do say what OS and version of PHP you’re using, which is great, you don’t say what command you’re trying to execute, what the error message/response is, where PHP is installed, or where you’re trying to create the webapp. So any answer I’d be offering would be a blind guess.

        • Ali says

          I am creating the web application folder in c:/xampp/htdocs/yii/framework path using command line.

  49. Cleverson says

    Hi Larray, really thanks for your tutorial and awesome explanation… I’m having a problem executing the demo app that’s come with YII, it says: Warning: require_once(/Applications/XAMPP/xamppfiles/htdocs/yii/framework/yii.php) [function.require-once]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/testdrive_yii/index.php on line 12. Could you help me please? Thanks again!

    • Larry says

      You haven’t really provided enough information here for me to answer the question, and the comments to a blog aren’t really a good spot for debugging help. If you need assistance, please use either my support forums or the Yii support forums.

  50. suresh says

    after installation of yii, i go to cmd mode and type accoriding to ur suggestion
    then using;

    c:\xampp\htdocs\yii>yiic webapp c:\xampp\htdocs\myapp

    it appears “php.exe is not recognized as internal or external command.

    please help me

    • Larry says

      Your command won’t work in your environment, which I suggest could be a problem in the post. For starters, you’ll need to provide a full path to your PHP executable.

    • Martin says

      on your yii\framework
      edit yiic.bat

      find
      if “%PHP_COMMAND%” == “” set PHP_COMMAND=php.exe
      replace with your php location
      if “%PHP_COMMAND%” == “” set PHP_COMMAND=D:\my\php\php.exe

Continuing the Discussion

  1. Tweets that mention Getting Started with the Yii Framework – Larry Ullman -- Topsy.com linked to this post on February 21, 2011

    [...] This post was mentioned on Twitter by R. Mullen, Legal Data Services. Legal Data Services said: WIsh I'd found this yesterday, but it's enough I can appreciate it today: #Yii tutorial by Larry Ullman. http://ht.ly/40Aa0 [...]

  2. Guida introduttiva ad Yii Framework | Programmando Facile linked to this post on February 9, 2012

    [...] Fonte: Larry Ullman [...]

If you need quick assistance with a question or problem related to one of my books, please use the support forums instead.

Some HTML is OK

or, reply to this post via trackback.