📜 ⬆️ ⬇️

Development on the Yii2 framework on the IBM Bluemix platform

I am having difficulty deploying php applications using the Yii2 framework on the IBM Bluemix platform. I’m sure I’m not the only one, so this post contains short instructions on how to avoid these difficulties.

What we need to do:
  1. create project in bluemix
  2. connect git
  3. create a project Yii2 and change the file structure
  4. set up a cloud
  5. enable application, fill code

Create an application in Bluemix


Bluemix is ​​structured for the final product, so the project should be developed locally or (like me) on a separate server.

After registering on bluemix.net, go to the DASHBOARD and create an environment for the php application in Cloud Foundry. To do this, on the start page, click the Create App button.
')



Choose WEB ...



... and choose PHP.



We take his code on your car


Now we need to pick up the code of the newly created application on our work machine, because besides the simplest Hello world, there are several configuration files that run the code in the cloud. To do this, go to the Overview of the application and click Add GIT ...



... and get a link to the repository ...



... from which we clone the application to itself.

Install Yii2


Install Yii2 according to the official instructions from the framework site on your computer or remote server. All files, except the web folder, need to be transferred to the lib folder. Files from the web are transferred to the project root. Such an arrangement of project files is needed to achieve two goals:
  1. Disable automatic execution of composer install found on the project root composer.lock / composer.json.
  2. Move the framework files outside the public part of the project. The lib folder is unpacked outside the folder accessible to the web server (/ home / vcap / app / htdocs), but within the include_path (/ home / vcap / app / lib)

These folders are configured by separate parameters (WEBDIR and LIBDIR), so that you can later customize the environment as you prefer. For simplicity, I use the default values.

Customize the project


To properly load Yii2 with each update, you need to perform additional configuration related to the dependencies of Yii2 and other link libraries. In particular, I mean the impossibility to install fxp / composer-asset-plugin at the project level - we can only install this library globally. To solve this problem, in the root of the project, create a folder .bp-config, and in it - the file options.json.

This is the place where the Cloud Foundry PHP Buildpack settings will be loaded from , which we connected to the project during creation.

The contents of the file that we use:
{ "PHP_VERSION": "{PHP_56_LATEST}", "PHP_EXTENSIONS": [ "bz2", "zlib", "openssl", "curl", "mcrypt", "mbstring", "pdo" ], "ADDITIONAL_PREPROCESS_CMDS": [ "cd ./app/lib/", "php -r \"readfile('https://getcomposer.org/installer');\" | php", "php composer.phar global require \"fxp/composer-asset-plugin:~1.1.1\"", "php composer.phar install", "cd ../../" ] } 

PHP_VERSION indicates the version of PHP. PHP_EXTENSIONS indicates which add-ons we need. Then ADDITIONAL_PREPROCESS_CMDS specifies the commands that need to be run after the project is installed in the cloud:
  1. go to the folder with Yii2
  2. install composer
  3. download fxp / composer-asset-plugin (see installation Yii2)
  4. download all necessary dependencies from composer.lock / composer.json
  5. return to the original folder - it is necessary to continue normal work

Run the application in the cloud


Once you have made all the necessary changes, just send them to Bluemix using git push. Bluemix will see the changes in the repository and install all the necessary dependencies, including fxp / composer-asset-plugin, and we will get a working test page with Hello world from Yii2 without any problems with bower assets.

Source: https://habr.com/ru/post/273837/


All Articles