Setting up preview of Yii2

13,284

Seems like yiic has been removed for now, there are alternatives though, so read on.

It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.

There are 2 ways to do this now:

  1. Use composer. (I recommend this option.)

  2. Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.


There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.


For basic go through the basic readme.md, and for advanced go through the advanced readme.md.


  1. The directions for using composer are given in the respective readme.md files. Including them here for completeness:

    • Basic app:
      1. Install composer, if you don't have it.
      2. Use composer to install the app alongwith dependencies(Yii): php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
      3. Access app from http://localhost/my_yii2_trial/www

    • Advanced app:
      1. Install composer, if you don't have it.
      2. Use composer to install the app alongwith dependencies(Yii): php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
      3. According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command).
        Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
      4. Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www

  2. Here's how to copy the directory and get it working:

    • Basic app:

      1. create your web-accessible directory for the app : my_yii2_trial
      2. copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
      3. modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php. For me it was within yii2/framework/yii/
      4. comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
      5. Access from browser : http://localhost/my_yii2_trial/www

    • Advanced app:

      1. create your web-accessible directory for the app : my_yii2_trial
      2. copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
      3. modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
      4. comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
      5. Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www


Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.


I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.

Share:
13,284

Related videos on Youtube

Brett Gregson
Author by

Brett Gregson

Fullstack software developer based in Prague. PHP, JS/TS, C# I'm available (internationally) for certain development work or consulting/contract work. Feel free to contact me on me[at]brettgregson.com

Updated on June 04, 2022

Comments

  • Brett Gregson
    Brett Gregson almost 2 years

    The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:

    php yiic.php app/create /var/www/yii2
    

    With the error:

    Could not open input file: yiic.php
    

    Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:

    The following commands are available:
    - asset
    - cache
    - help
    - message
    - migrate
    

    Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?

  • bool.dev
    bool.dev almost 11 years
    Updated answer, more complete now.
  • dev1234
    dev1234 over 10 years
    i am getting an error like this, Parse error: syntax error, unexpected '[', expecting ')' in D:\xampp\htdocs\my_yii2_trial\vendor\yiisoft\yii2\yii\Yii.ph‌​p on line 25
  • bool.dev
    bool.dev over 10 years
    @mazraara, i have seen your question, and added an answer there.
  • Robert Went
    Robert Went about 10 years
    after installing the advanced example I was getting errors that there was no database so I created the database yii2advanced (user root no password) and then went to the root of the project and ran yii migrate which populated the database with the needed tables
  • Sarvar N
    Sarvar N about 10 years
    I've tried to install by copying the directory, but it is giving an error: ...vendor/yiisoft/extensions.php): failed to open stream. coudln't find extensions.php from any directory, and I commented this line, but it's giving more errors. What is the problem do you think?
  • bool.dev
    bool.dev about 10 years
    @SarvarNishonboyev which app(basic or advanced?) did u try to install? and from where did you download? did you also try installing with composer? I can try and tell you the exact solution only when u answer these questions.
  • Sarvar N
    Sarvar N about 10 years
    @bool.dev I've succeeded installing by composer. But couldn't fix the problem by copying files, it's just headache. better to install by composer. Thanks.
  • Gaurav Parashar
    Gaurav Parashar about 10 years
    i m getting error in run the composer.phar file please tell me how to run php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial command in my ubuntu
  • bool.dev
    bool.dev about 10 years
    @GauravParashar please ask a separate question with the exact error, the steps above are correct, your issue is somewhere else, hence i ask you to ask a new question.
  • Gaurav Parashar
    Gaurav Parashar about 10 years
    @bool.dev thanks for your reply ,Actually i am new here so i posted some wrong questions so i am banned to post questions for some days.
  • bool.dev
    bool.dev about 10 years
    @GauravParashar, that's ok, try to read the advanced readme.md link, provided in answer. maybe you missed a step.