Instalando Yii 2

Yii2 es un framework de desarrollo que me ha gustado utilizar para programar en PHP, tiene dos versiones, la versión básica y la versión más completa donde se tiene la parte pública y la parte administrativa. En este post sólo explicaré cómo instalar la versión básica.

Yii tiene varias formas de instalarse aunque la recomendada es la siguiente, para lo cuál deberemos tener instalado Composer.

En el siguiente post indico como instalarlo:

Composer: herramienta para administrar dependencias en PHP

Una vez que tenemos instalado Composer, nos moveremos al directorio donde trabajaremos el proyecto, ya sea el directorio htdocs de Apache o el public_html de una cuenta de usuario o un directorio donde se configuró un Virtual Host. Para este ejemplo yo lo realizaré en el directorio public_html de mi cuenta.

Para ello nos moveremos a la carpeta:

javoaxian@vaiolinuxmintjx $ cd $HOME/public_html

Ahora ejecutamos la instalación del proyecto el cual lo llamaré: proyectoyii:

javoaxian@vaiolinuxmintjx $ composer create-project --prefer-dist yiisoft/yii2-app-basic proyectoyii

Puede que nos mandé algunos mensajes de error como el siguiente que a mi me mostró, en el cuál se especifica que me falta una configuración hecha en PHP para que Yii2 trabaje correctamente:

Installing yiisoft/yii2-app-basic (2.0.13)
  - Installing yiisoft/yii2-app-basic (2.0.13): Loading from cache
Created project in proyectoyii
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - yiisoft/yii2 2.0.9 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.8 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.7 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.6 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.5 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.13.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.13 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.12 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.11.2 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.11.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.11 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - yiisoft/yii2 2.0.10 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - Installation request for yiisoft/yii2 ~2.0.5 -> satisfiable by yiisoft/yii2[2.0.10, 2.0.11, 2.0.11.1, 2.0.11.2, 2.0.12, 2.0.13, 2.0.13.1, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9].

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/php/lib/php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Para resolverlo deberemos compilar PHP con la opción –enable-mbstring.

Aquí dejo el post de instalar PHP, sólo hay que agregar en el comando configure poner la opción –enable-mbstring.

Aquí dejo un ejemplo:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-pdo-mysql --with-openssl --with-zlib --enable-mbstring

Una vez compilado de esta manera PHP, se nos indicará que fue creado correctamente nuestro proyecto:

Installing yiisoft/yii2-app-basic (2.0.13)
  - Installing yiisoft/yii2-app-basic (2.0.13): Loading from cache
Created project in proyectoyii
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 60 installs, 0 updates, 0 removals
  - Installing yiisoft/yii2-composer (2.0.5): Loading from cache
  - Installing swiftmailer/swiftmailer (v5.4.8): Loading from cache
  - Installing bower-asset/jquery (3.2.1): Loading from cache
  - Installing bower-asset/yii2-pjax (2.0.7.1): Loading from cache
  - Installing bower-asset/punycode (v1.3.2): Loading from cache
  - Installing cebe/markdown (1.1.2): Loading from cache
  - Installing ezyang/htmlpurifier (v4.9.3): Loading from cache
  - Installing bower-asset/inputmask (3.3.11): Loading from cache
  - Installing yiisoft/yii2 (2.0.13.1): Loading from cache
  - Installing yiisoft/yii2-swiftmailer (2.0.7): Loading from cache
  - Installing bower-asset/bootstrap (v3.3.7): Loading from cache
  - Installing yiisoft/yii2-bootstrap (2.0.7): Loading from cache
  - Installing yiisoft/yii2-debug (2.0.13): Loading from cache
  - Installing bower-asset/typeahead.js (v0.11.1): Loading from cache
  - Installing phpspec/php-diff (v1.1.0): Loading from cache
  - Installing yiisoft/yii2-gii (2.0.6): Loading from cache
  - Installing fzaninotto/faker (v1.7.1): Loading from cache
  - Installing yiisoft/yii2-faker (2.0.3): Loading from cache
  - Installing sebastian/diff (2.0.1): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Loading from cache
  - Installing sebastian/exporter (3.1.0): Loading from cache
  - Installing sebastian/comparator (2.1.2): Downloading (100%)         
  - Installing behat/gherkin (v4.4.5): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.6.0): Loading from cache
  - Installing symfony/dom-crawler (v4.0.3): Loading from cache
  - Installing symfony/css-selector (v4.0.3): Loading from cache
  - Installing symfony/browser-kit (v4.0.3): Loading from cache
  - Installing symfony/yaml (v4.0.3): Loading from cache
  - Installing symfony/event-dispatcher (v4.0.3): Loading from cache
  - Installing symfony/console (v4.0.3): Loading from cache
  - Installing symfony/finder (v4.0.3): Loading from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing guzzlehttp/psr7 (1.4.2): Loading from cache
  - Installing doctrine/instantiator (1.1.0): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing phpunit/phpunit-mock-objects (4.0.4): Loading from cache
  - Installing theseer/tokenizer (1.1.0): Loading from cache
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/environment (3.1.0): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-token-stream (2.0.2): Loading from cache
  - Installing phpunit/php-file-iterator (1.4.5): Loading from cache
  - Installing phpunit/php-code-coverage (5.3.0): Loading from cache
  - Installing sebastian/resource-operations (1.0.0): Loading from cache
  - Installing sebastian/object-reflector (1.1.1): Loading from cache
  - Installing sebastian/object-enumerator (3.0.3): Loading from cache
  - Installing sebastian/global-state (2.0.0): Loading from cache
  - Installing phpunit/php-timer (1.0.9): Loading from cache
  - Installing webmozart/assert (1.2.0): Loading from cache
  - Installing phpdocumentor/reflection-common (1.0.1): Loading from cache
  - Installing phpdocumentor/type-resolver (0.4.0): Loading from cache
  - Installing phpdocumentor/reflection-docblock (4.2.0): Loading from cache
  - Installing phpspec/prophecy (1.7.3): Loading from cache
  - Installing phar-io/version (1.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.1): Loading from cache
  - Installing myclabs/deep-copy (1.7.0): Loading from cache
  - Installing phpunit/phpunit (6.4.4): Loading from cache
  - Installing codeception/base (2.3.7): Loading from cache
  - Installing codeception/verify (0.3.3): Loading from cache
  - Installing codeception/specify (0.4.6): Loading from cache
symfony/browser-kit suggests installing symfony/process ()
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
symfony/console suggests installing symfony/lock ()
symfony/console suggests installing symfony/process ()
symfony/console suggests installing psr/log (For using the console logger)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.5.5)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit suggests installing phpunit/php-invoker (^1.1)
phpunit/phpunit suggests installing ext-xdebug (*)
codeception/base suggests installing aws/aws-sdk-php (For using AWS Auth in REST module and Queue module)
codeception/base suggests installing codeception/phpbuiltinserver (Start and stop PHP built-in web server for your tests)
codeception/base suggests installing flow/jsonpath (For using JSONPath in REST module)
codeception/base suggests installing phpseclib/phpseclib (for SFTP option in FTP Module)
codeception/base suggests installing league/factory-muffin (For DataFactory module)
codeception/base suggests installing league/factory-muffin-faker (For Faker support in DataFactory module)
codeception/base suggests installing symfony/phpunit-bridge (For phpunit-bridge support)
codeception/base suggests installing stecman/symfony-console-completion (For BASH autocompletion)
Writing lock file
Generating autoload files
> yii\composer\Installer::postCreateProject
chmod('runtime', 0777)...done.
chmod('web/assets', 0777)...done.
chmod('yii', 0755)...done.
> yii\composer\Installer::postInstall

Ahora desde nuestro navegador podremos entrar ya a nuestro proyecto con Yii2. Cabe recordar que este proyecto lo coloqué en el directorio public_html de mi cuenta de usuario, por lo que ingresaré de la siguiente forma en el navegador:

http://localhost/~javoaxian/proyectoyii/web/index.php

se nos mostrará la siguiente pantalla:

jx_post_1104_01

Existe un archivo de requerimientos mínimos de Yii2, para ingresar a él:

http://localhost/~javoaxian/proyectoyii/requirements.php

se nos mostrará la siguiente pantalla:

jx_post_1104_02

Con esto ya tenemos nuestro primer proyecto de Yii2, ahora será cuestión de empezar a desarrollar en él.