FreeBSD step by step guide To Install Yii PHP Framework

Yii stands for yes, it is a component-oriented PHP framework. Yii has high performance making it very suitable for scalable web applications. Yii comes with a variety of features, including MVC, DAO/ActiveRecord, I18N/L10N. The framework also supports jQuery-based AJAX, role-based access control, scaffolding, input validation, widgets, events, themes, web services, and more. Written in pure OOP, Yii is easy to use, as well as highly flexible and extensible.

Yii's advantages compared to other frameworks are its high speed and excellent OOP support. Yii also has a large number of libraries. With the help of Yii, you can easily create web applications that meet all modern standards. Built-in methods are one of the features that can help you reduce the amount of code significantly.

A framework is a kind of framework for developing a web application. Frameworks can help simplify and speed up web project development.

Yii is released under a BSD license that can be used for commercial purposes, embedded in proprietary products. Yii has great documentation and a large community. A large developer community is an opportunity to get help and discuss important topics quickly.



The developers of the Yii framework adhere to the philosophy of simplicity and elegance of code, so the framework is extensible and easy to use. You can replace or edit almost any major part of the code, and you are also given the freedom to share code provided by the community. Another thing worth mentioning is that Yii promotes rapid prototyping of projects.

This post will explain how to install and run the Yii framework on a FreeBSD server.


1. Install Yii PHP Framework

PKG packages and FreeBSD ports are not available on Yii, you must install Yii with Composer. So make sure your FreeBSD has PHP composer installed. Follow the guide below to install Yii on FreeBSD.

Download Yii from Github
root@ns3:~ # cd /usr/local/www
root@ns3:/usr/local/www # git clone https://github.com/yiisoft/yii2.git
Once you download Yii from the Github repository, you can install Yii in two ways
1. Use Composer
2. Download the Yii archive directly.

For most people installing Yii with composer is preferable because it allows new extensions to be installed or updates to Yii with a single command line. In Yii 2, it is a little different from Yii 1, after the installation process is complete you will get the framework and application template.

Run the following command to install Yii 2 with composer.

/usr/local/etc/yii2
root@ns3:/usr/local/www # cd yii2
root@ns3:/usr/local/www/yii2 # composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic


2. Create database Yii

Yii 2 uses a database as a backend, its function is to store all Yii user information. In this article we will use a database server commonly used by developers, namely MySQL server.

We will create the Yii 2 database using MySQL. With the help of PHP, the MySQL database will be connected to the Yii 2 server. The guide below will explain the process of creating a Yii 2 database.

Create database yii2basic
root@ns3:~ # mysql -u root -p
Enter password:
root@localhost [(none)]> CREATE DATABASE yii2basic CHARACTER SET utf8;
root@localhost [(none)]> CREATE USER 'useryii'@'localhost' IDENTIFIED BY 'freebsdyii';
root@localhost [(none)]> GRANT ALL PRIVILEGES ON yii2basic.* TO 'useryii'@'localhost';
root@localhost [(none)]> FLUSH PRIVILEGES;
root@localhost [(none)]> exit;
Bye
root@ns3:~ #
After that, you open the /usr/local/www/yii2/basic/config directory, look for the db.php file and change the script as in the example below.

/usr/local/www/yii2/basic/config
root@ns3:~ # cd /usr/local/www/yii2/basic/config
root@ns3:/usr/local/www/yii2/basic/config # ee db.php
<?php

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
    'username' => 'root',
    'password' => 'freebsdyii',
    'charset' => 'utf8',

    // Schema cache options (for production environment)
    //'enableSchemaCache' => true,
    //'schemaCacheDuration' => 60,
    //'schemaCache' => 'cache',
];
Match the password to the database password you created above.

The final step is to run the Yii 2 server with the following command.

/usr/local/www/yii2/basic
root@ns3:/usr/local/www/yii2/basic/config # cd /usr/local/www/yii2/basic
root@ns3:/usr/local/www/yii2/basic # php yii serve 192.168.5.2 --port=8888
Please open the Google Chrome web browser and type "http://192.168.5.2:8888/", see the results. If there are no incorrect configurations, something like the image below will appear.




After reading this article, we assume you have successfully installed Yii 2 on FreeBSD. Apart from that, you have also learned about the Yii PHP Framework and its features. You can modify each feature according to the needs of the website you are working on.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post