3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansibleのmakeモジュールを使ってPHPをインストールしてみる

Posted at

今更ながらmakeモジュールを使ってPHPをインストールしてみた。

roles/php/vars/main.yml
---
php_version: "7.0.13"
php_install_dir: /usr/local
php_lib_dir: "{{ php_install_dir }}/lib"
php_bin_dir: "{{ php_install_dir }}/bin"
php_extensions_dir: "{{ php_lib_dir }}/php/extensions/no-debug-non-zts-20151012"
php_src_dir: /usr/local/src
php_make_dir: "/usr/local/src/php-{{ php_version }}"

php_with_jpeg_dir: /usr/lib
php_with_png_dir: /usr/lib
php_with_openssl: /usr/local/ssl 
php_with_iconv: /usr/local 
php_with_apx2: /usr/local/apache/bin/apxs
roles/php/tasks/main.yml
# ファイル・バージョンチェック
- name: Check php dir.
  stat: 
    path: "{{ php_bin_dir }}/php"
  register: php
- name: Check php version.
  shell: "{{ php_bin_dir }}/php -v"
  changed_when: false
  register: php_current_version
  when: php.stat.exists
- set_fact: php_installed=true
  when: php.stat.exists and
        php_version in php_current_version.stdout
- name: Ensure package directory exists
  file: 
    path: "{{ php_src_dir }}"
    state: directory

# php install
- name: Install php.
  block:
  - unarchive:
      src: http://jp2.php.net/distributions/php-{{ php_version }}.tar.gz
      dest: "{{ php_src_dir }}"
  - name: ./configure
    shell: >
      ./configure 
      --prefix={{ php_install_dir }} 
      --enable-sigchild 
      --enable-mbregex 
      --enable-bcmath 
      --enable-sockets 
      --enable-ftp 
      --enable-soap 
      --enable-opcache
      --with-iconv={{ php_with_iconv }} 
      --with-apxs2={{ php_with_apx2 }} 
      --with-openssl={{ php_with_openssl }} 
      --with-jpeg-dir={{ php_with_jpeg_dir }}
      --with-png-dir={{ php_with_png_dir }}
      --with-pgsql 
      --with-pdo-pgsql 
      --with-curl 
      --with-gd 
      --with-zlib-dir 
      --with-mcrypt 
      chdir={{ php_make_dir }}
  - name: make all
    make:
      chdir: "{{ php_make_dir }}"
      target: all
  - name: make install
    make:
      chdir: "{{ php_make_dir }}"
      target: install
  when: php_installed is not defined

# php config
- name: Copy php.ini.
  copy: 
    src: php.ini
    dest: "{{ php_lib_dir }}"
- name: Copy php extensions.
  copy: 
    src: "{{ item }}"
    dest: "{{ php_extensions_dir }}"
  with_items:
    - mbstring.so
    - memcached.so

「Ansible Galaxy使えば?」という声には耳を傾けない。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?