2.8.4.3.1. Install Yii

To install Yii, follow these steps:

  1. Install Composer (if it isn't already installed).
  2. Go to the root directory of your site and create a subdirectory named "source" where the framework files will be installed:
    cd ~/site_name.com/www && mkdir source
  3. Create a new project using Composer:
    composer create-project yiisoft/yii source
  4. Create the framework for your project in the site root directory, "www":
    php source/framework/yiic.php webapp ~/site_name.com/www

    When prompted to confirm the action, type yes and press Enter.

This completes the installation of the project framework, and it is now accessible in a browser via a link such as www.site_name.com.

To improve security, disable web access to the source directory:

cd ~/site_name.com/www/source && touch .htaccess && echo "deny from all" > .htaccess && cd ..

If your project will use a database, make the necessary changes to the file site_name.com/www/protected/config/main.php. By default, the Yii framework is configured to work with an SQLite database. We use MySQL on our hosting. To specify the database connection settings, edit the file site_name.com/www/protected/config/main.php and comment out the following lines:

'db'=>array(
    'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),

After that, uncomment the following lines:

'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),

This section contains your database connection credentials.

Content