Home | About | Web Stories | View All Posts

15 May 2022

Best guidelines how to install Yii framework in Windows 10

The Yii 2.0 is the latest version of the Yii framework. The Yii is one of the most popular, efficient and robust free open source PHP framework which is used for developing the modern and commercial web applications.

How to install Yii2 using composer method

You need to install the Yii framework at the server for creating the web applications. It requires a running instance of web server with PHP 5.4.0 or above. We have used XAMPP(Apache web server, MySQL, PHP) server for setting up the Yii2 application in Windows 10 operating system.

The Yii2 standard installation provide both the framework files and a project template - "Basic Project Template(without backend and frontend folder structure)" and "Advanced Project Template(with backend and frontend folder structure)". The Yii2 provides pre coded or pre-programmed features for home page, register, login, contact form, about page in the project template. You can install one of the two project template as per your project or application requirement.

How to install Yii2? -
We can install the Yii using two ways, which are divided and explained as below -
  1. Using Composer package manager
  2. By downloading the archive file

How to install yii framework in windows 10
The following are details for each step that you can follow for "How to install Yii2" or "How to install Yii2 using composer " or "How to install Yii2 in windows" -

  1. Using Composer package manager -
    Following are steps for YII2 advanced installation -
    1. Installing composer
    2. Getting yii2 app files from yii git repository
    3. Yii application environment initialization
    4. Database creation
    5. Running and verifying the yii2 installation
    6. Invoking sign up functionality


    1. Installing composer in Windows machine -
      You can check your windows machine – if it has already composer installed. You need to press the combination of Windows and “R” key for opening the “Run” dialog box. Now write “cmd” in the open box for opening the command window. You need to write the command : “composer –v”. The composer version screen will be shown as following screenshot if you have already composer installed in your windows machine.

      How to install yii framework in windows 10 - check if composer present in your maching

      If you have not pre installed composer at your machine then you can install the composer using the windows installer or by using command-line installation. The first way - "Windows installer" is the easiest way to get Composer set up on your machine.

      You need to download and run "composer-setup.exe" from "https://getcomposer.org". It will install the latest composer version and set up your PATH environment variable so that you can simply call 'composer' from any directory.

      Now for verifying the composer installation, please press the combination of Windows and “R” key for opening the “Run” dialog box. Now write “cmd” in the open box for opening the command window. You need to write the command : “composer –v” and press the enter key. It will show composer version screen as the above command window screenshot.

    2. Getting yii2 app files from yii git repository
      Navigate and go at the preferred directory, where you want to install yii application. The following path shows the directory path in my case at XAMPP server -

      C:\xampp\htdocs>

      At here we will use the 'create-project' command for installing Yii2 framework application as following -

      For Basic application(without backend and frontend folder structure) -
      C:\xampp\htdocs>composer create-project --prefer-dist yiisoft/yii2-app-basic yii2cmstest

      For Advanced application(with backend and frontend folder structure) -
      C:\xampp\htdocs>composer create-project --prefer-dist yiisoft/yii2-app-advanced yii2cmstest

      Here,
      Command option : --prefer-dist
      Package : yiisoft/yii2-app-basic
      Directory : yii2cmstest

      Generally package url relates with github which is - https://github.com/yiisoft/yii2-app-basic. Directory will be automatically created that you have provided as name at above command line eg. 'yii2cmstest'.

      Please note - application will be installed in an auto created folder "yii2-app-basic or yii2-app-advanced", if you do not provide folder name. Also you need to answer the prompted questions in the command window during the installation process.

      You can use --dev or --no dev command option if you want to install production or development application.

      Finally all dependent module or packages like - bower-asset/bootstrap, yiisoft/yii2-swiftmailer, yiisoft/yii2-gii, symfony/yaml etc will be installed. Following is the screenshot for installation process.

      How to install yii framework in windows 10 - creating project screen

    3. Yii application environment initialization
      Now run the “init” file at command window for running the Yii application initialization tool -

      C:\xampp\htdocs\yii2cmstest>init

      You can also click and run the “init.bat” in the folder path –“ C:\xampp\htdocs\yii2cmstest” , instead of above command for initializing the Yii application.

      The yii “init” file creates necessary files at appropriate directory for Yii application environment initialization as the following screenshot -

      How to install yii framework in windows 10 - init command output screen

    4. Database creation
      Now open the configuration file “main-local.php” that have created by “init” command at C:\xampp\htdocs\yii2cmstest\common\config\ folder.

      In my case configuration file path is -
      C:\xampp\htdocs\yii2cmstest\common\config\main-local.php

      We will adjust the components['db'] configuration here. The Yii installation system write and use database named as “yii2advanced” by default in the database connection string in the components['db'] configuration.

      We will create a database named as same “yii2advanced” in our phpmyadmin so that signup and login functionality work properly. The user entry is taken place in this database while signup process.

      Please note - You are free to change the name of database if you do not want to use database name that has been created by default while Yii installation.

      How to install yii framework in windows 10 - main.php file for database name

    5. Running and verifying the yii2 installation
      We will verify and run the Yii installation process. You need to go and browse the url below to check the installation process of backend - “ /advanced/backend/web/” or frontend - “/advanced/frontend/web/”.

      In my case it was -
      http://localhost/yii2cmstest/frontend/web/
      http://localhost/yii2cmstest/backend/web/

      The following congratulation page(screenshot) will be shown after successful installation at -
      http://localhost/yii2cmstest/frontend/web/

      How to install yii framework in windows 10 - congratulation page

      The login form(screenshot) would visible after successful installation if you browse the backend at -
      http://localhost/yii2cmstest/backend/web/

      How to install yii framework in windows 10 - login form page

    6. Invoking sign up functionality
      The Yii installation system provide a pre built “Sign up” form in the frontend. You can view and check this page by clicking at the “signup” link in the top navigation bar. You can view this page directly using the following url -

      http://localhost/yii2cmstest/frontend/web/index.php?r=site%2Fsignup

      The above sign up form will not place user entry into the database. We need to invoke its functionality before start of the signup process.

      We need to run the migrate command at command window for invoking sign up functionality as following. This migration command primarily sets up the table for user management.

      Please go at command prompt and run the command -

      C:\xampp\htdocs\yii2cmstest >yii migrate

      It will run as below -
      Yii Migration Tool (based on Yii v2.0.6)
      
      Creating migration history table "migration"...Done.
      Total 1 new migration to be applied:
          m130524_201442_init
      
      Apply the above migration? (yes|no) [no]:yes
      *** applying m130524_201442_init
          > create table {{%user}} ... done (time: 0.007s)
      *** applied m130524_201442_init (time: 0.022s)
      
      
      Migrated up successfully.
      

      The two new table - "migration" and "user" is created in the phpmyadmin due to this migration command. The following is the screenshot of the phpmyadmin with two newly created table name.

      How to install yii framework in windows 10 - two new table created

      Finally go at sign up form and do sign up using mail and password then try to login into your Yii2 project.

      In my case sign up url was -
      http://localhost/yii2cmstest/frontend/web/index.php?r=site/signup

      In my case login url was -
      http://localhost/yii2cmstest/frontend/web/index.php?r=site/login

      Please visit the page at “Yii2 advanced login not working after installation” if you face problem in the login process after Yii2 installation.
  2. By downloading the archive file -
    Please browse the Yii official download page at http://www.yiiframework.com/download/ for viewing the download archive button for – “basic application template” and “advanced application template” – as following screenshot. You can download the archive file for basic or advanced template as per your requirement.

    How to install yii framework in windows 10 - installation by archive file

    Please extract the archive file downloaded from the above url at your custom project folder root at the server or at the root of the server as per your needs.

    Now follow the instructions that has been mentioned in the step 3 to step 6 above.
If you are preparing and looking for a career in Yii, please visit at "Interviews Questions and Answers" for getting your dream job.


Best Books for Web Development in PHP


1

Programming PHP : Creating Dynamic Web Pages

Programming PHP : Creating Dynamic Web Pages

Book Description

It's the new and updated version of this book - Fourth Edition - that teaches you everything you need to know to build effective web applications using the latest features in PHP 7.4.

The book explains language syntax, programming techniques, and other details using examples that illustrate both correct usage and common idioms.

For those with a working knowledge of HTML, the book contains many style tips and practical programming advice in a clear and concise manner to help you become a top PHP programmer.

The book teaches about fundamentals of the language including data types, variables, operators and flow control statements. It explores about functions, strings, arrays and objects.

It teaches to apply common web application techniques, such as form processing, data validation, session tracking, and cookies.

It teaches to interact with relational databases such as MySQL or NoSQL databases such as MongoDB. It also teaches to generate dynamic images, creating PDF files, and parsing XML files.

You can learn about secure scripts, error handling, performance tuning and other advanced topics in this book.

You can get a quick reference to PHP core functions and standard extensions in this book.

Book details

Format: Kindle Edition, Paperback
Rating: 4.6 out of 5
Author: Kevin Tatroe, Peter Macintyre
Print Length: 540 pages
Publication Date: 27 March 2020
Publisher: O′Reilly, 4th edition
Kindle Price: Rs. 1,567.50*
Paperback Price: Rs. 3,614.00*
*Price and stock are correct and available at the time of article publication.

Get it here from Amazon


2

PHP Web Development with Laminas

PHP Web Development with Laminas

Book Description

This book teaches how to build fully secure and functional e-commerce applications with PHP using the next generation Zend Framework-Laminas. You can learn to develop modern object-oriented applications with PHP by using Test-Driven Development (TDD) and Behavior-Driven Development (BDD) aided by mature reusable components.

This book provides a practical approach to equip you with the knowledge of the Laminas framework needed to start building web applications based on reuse of loosely coupled components.

You will learn how to build the basic structure of a PHP web application divided into layers. You can understand the MVC components of Laminas and be able to take advantage of the Eclipse platform as a method to develop with Laminas.

Books teach to explore how object-relational mapping is implemented with Laminas-DB, behavior-driven development concepts to sharpen your skills, how to build complete models and reusable components, practice testing How to Create HTML Forms With Laminas-Forms.

By the end of this web development book, you will be able to build completely secure MVC applications in PHP language using Laminas.

Book details

Format: Kindle Edition
Author: Flávio Gomes da Silva Lisboa
Text-to-Speech: Enabled
Enhanced typesetting: Not Enabled
X-Ray: Not Enabled
Word Wise: Not Enabled
Publication Date: 9 December 2022
Publisher: Packt Publishing
Kindle Price: Rs. 750.74*
*Price and stock are correct and available at the time of article publication.

Get it here from Amazon


3

Getting started with Laravel 9, master the most popular PHP framework

Getting started with Laravel 9, master the most popular PHP framework

Book Description

This book is for all those who want to build their first application in Laravel 9. This book provides a step-by-step introduction to the writing framework, gets to know its most relevant aspects and focuses above all on practice.

Using this book you will be able to build any basic application with the framework. There are total 19 chapters in this book. Using this book, you will be able to know what are the required software to install Laravel for different operating systems.

In this book you can learn - project creation, database configuration, routing, view controllers, redirection, directive and templating engines in the form of blades, model building, CRUD applications etc.

You can learn to perform common eloquent operations that can be applied to databases using query builders. You can learn how to generate test data using classes.

You can also learn the file upload process. You can learn how to use REST APIs through CRUD type applications in VU3 using Axios requests and web components with Oruga UI.

You can also learn how to configure Browsersync with Laravel to automatically reload applications. You can learn how to protect an app in Vue with the login required to access its various modules using SPA authentication or Laravel Sanctum tokens.

Book details

Format: Kindle Edition
Rating: 1 out of 5
Author: Andrés Cruz Yoris
Print Length: 453 pages
Publication Date: 8 May 2022
Text-to-Speech: Enabled
Screen Reader: Supported
Enhanced typesetting: Enabled
X-Ray: Not Enabled
Word Wise: Not Enabled
Kindle Price: Rs. 449.00*
*Price and stock are correct and available at the time of article publication.

Get it here from Amazon


4

Learning Drupal as a framework: Your guide to custom Drupal 9. Full code included

Learning Drupal as a framework: Your guide to custom Drupal 9. Full code included

Book Description

This book uses PHP> 7.4. This course teaches you about the advanced concepts of Drupal 9, object-oriented PHP and Symfony components.

After the course, you will be able to build a variety of robust and scalable software solutions.

This book discusses advanced topics such as custom entities, entity forms, access controls, events, caching, workflows, and more when building real software.

It gives you powerful and ready-to-use snippets for your next Drupal project with +2400 lines of custom code.

Book details

Format: Kindle Edition
Rating: 5 out of 5
Author: Stef Van Looveren
Print Length: 282 pages
Publication Date: 17 July 2022
Text-to-Speech: Enabled
Screen Reader: Supported
Enhanced typesetting: Enabled
X-Ray: Not Enabled
Word Wise: Not Enabled
Kindle Price: Rs. 449.00*
*Price and stock are correct and available at the time of article publication.

Get it here from Amazon


5

Getting started with CodeIgniter 4

Getting started with CodeIgniter 4

Book Description

This book is for anyone who wants to build their first applications in CodeIgniter 4 a popular PHP framework, this writing offers a step-by-step introduction to the framework, knowing the most relevant aspects of it, and is focused above all on practice.

The book is aimed at those people who want to learn something new, learn about a framework that has very little documentation, who want to improve a skill in web development, who want to grow as a developer, and who want to continue scaling their path with other frameworks superior to this one.

This book has a total of 15 chapters and consists of explanations and practices. It teaches you how to run the framework, how to configure a database, how to create the first components, how to use of migrations for table management, working with the MVC, how to prepare CRUD application, how to use the routes, grouped routes, their options, and the different types.

You can learn about the use of the session and also of the flash session to save data and present it to the user. You can learn to manage views in a reusable way. You can learn about how to work with HTML forms and apply validations from the server side in CodeIgniter. You can learn about the authentication module with the login interface, and how to build a Rest Api type CRUD that can be consumed with JSON or XML.

You can also learn about generating test data with seeders, how to handle the relational schema of the database, how to do uploading files in the application, how to use libraries and help functions, how to integrate the PayPal platform, etc.

Book details

Format: Kindle Edition
Author: Andres Cruz
Print Length: 328 pages
Publication Date: 13 May 2022
Text-to-Speech: Enabled
Screen Reader: Supported
Enhanced typesetting: Enabled
X-Ray: Not Enabled
Word Wise: Not Enabled
Kindle Price: Rs. 319.00*
*Price and stock are correct and available at the time of article publication.

Get it here from Amazon


FAQ - Frequently Asked Question


How do I know if Yii is installed?

In Windows machine, run the command yii.bat at the folder that having the Yii2 application template. This will show the installed Yii version screen. In Linux, you need to run ./yii in the base directory for viewing the Yii2 version screen.

How do I find my composer version?

You can check the composer version by using command - “composer –v”. Please press the combination of Windows and “R” key for opening the “Run” dialog box. Now write “cmd” in the open box for opening the command window. You need to write the command : “composer –v” and press the enter key. This will show the composer version screen.

What are yii2 components?

Yii application is based on components. The component is the base class which uses the property, event, and behavior features which are used by other classes.

What is widget in yii2?

In Yii2, widget is a resuable code blocks implemented in views in an object oriented design pattern. It contains HTML, CSS, and JS as client side code. We can call the yii\base\Widget::widget() method to use a widget in a view. For example - date picker widget

How do I remove Composer from Windows 10?

You need to open the control panel in the windows machine, then navigate to the Programs and Features. It will show all the installed program list in your computer. Select the "Composer" and right click to view the "uninstall" menu item. You need to further click at this "uninstall" menu for uninstalling the Composer from your computer.

Tags :
Aashutosh Kumar Yadav

By Aashutosh Kumar Yadav

He is a PHP-based UI/Web designer and developer by profession and very interested in technical writing and blogging. He has been writing technical content for about 10 years and has proficient in practical knowledge and technical writing.
@www.infotokri.in

0 comments:

Post a Comment