詳細検索

FuelPHP + Ansible for Super Easy Development/Operation - Installing FuelPHP

Avatar
by 吉亨斗
3 min read

FuelPHP + Ansible for Super Easy Development/Operation - Installing FuelPHP
Translated from 日本語 • View original

It's time for developers to easily build infrastructure. Building an environment is easy with Ansible, a powerful environment building tool.

There are various other tools for building an environment, such as chef, puppet, and docker, but please refer to the following article I wrote before to understand why I chose Ansible.

Comparison and impressions of Qiita software engineers' environment construction automation tools

PHP frameworks such as Lalavel, the classic CakePHP, and ultra-fast Phalcon have become increasingly popular in recent years, but the reason why I chose FuelPHP is because of its rich features and a lot of Japanese information. It's simply a preference.

From now on, I would like to introduce the know-how of development using FuelPHP + Ansible in the following order.

  • Part 1: Installing FuelPHP
  • Part 2: Switching Maintenance Mode
  • Part 3: Deployment
  • Part 4: Configuration and precautions during development/production operation

We will explain based on the following development environment. It is also for those who know the concept of Ansible.

  • MacOS X 10.10.2
  • ansible 1.7.2
  • FuelPHP 1.7

※ There are many installation instructions for ansible if you search Google, so I will omit it.

To run the playbook to install FuelPHP in Ansible, you need to write the steps in yaml format in ~/role/rolename/subordinate. The following is the process content of ~/role/role name/task/main.yml.

- name: ①Copy the code from repository
git: repo={{ repository }} dest={{ root_dir }} accept_hostkey=yes
sudo: no

- name: ②comporser self-update
shell: php composer.phar self-update chdir={{ root_dir }}

- name: ③comporser update
shell: php composer.phar update chdir={{ root_dir }}

- name: ④set fuel_env.
shell: env FUEL_ENV=production php oil -v chdir={{ root_dir }}

- name: ⑤create link.
file: path={{document_root_path}} src={{fuel_public_dir_path}} state=link

- name: ⑥db migrantion.
shell: FUEL_ENV=production php oil refine migrate chdir={{ fuel_dir_path }}

The {{ }} used in the process contains the variable name. Define the variable in /role/rolename/vars/main.yml. As for the above content,

# fuelPHP github repository name
repository: git@github.com:fuel/fuel.git

# DIR where the source body is stored
root_dir: /var/www/

# DIR name for FuelPHP
fuel_dir_path: /var/www/test

# FuelPHP public DIR name
fuel_public_dir_path: /var/www/test/public

# DIR name of the document root
document_root_path: /var/www/html/public

The order of processing is as follows: (1) Download the FuelPHP source from github. (2) Update the comporser itself (3) Install the core part of FuelPHP with the comporser (4) Set production and production to the environment variable of FUEL_ENV (specify production) (5) Paste a symbolic link to the public directory of FuelPHP in the document root (6) Auto-generate tables with FuelPHP migration

This is the content of the role for installing FuelPHP in Ansible. Next, let's write a process to run the playbook.

~/fuelphp.yml specifies the name of the Role to run in the playbook.

- name: install FuelPHP.
hosts: ec2_web01
sudo: yes
remote_user: root
roles:
- Roll name

Next, create an inventory file. Set the IP of the server you want to run Ansible on in a file called host.

[ec2_web01]
00.00.000.000

Finally, just run the playbook.

ansible-playbook -i host fuelphp.yml

So far, we have implemented the installation instructions required for FuelPHP development in Ansible code. I think that the idea of immutable infrastructure is that by visualizing the installation procedure of middleware and environment construction in this way, it is easier to share information among team members and save the time and effort of construction. Actively adopt Ansible to increase your development efficiency!

Next time, I will introduce a super easy and speedy maintenance mode switch using Ansible+FuelPHP.

Related Articles