mirror of
https://github.com/geerlingguy/ansible-role-php.git
synced 2025-01-24 21:41:21 +01:00
Fixes #35: Support compiling from source, PHP 7, and beyond!
This commit is contained in:
parent
30e9ef1a33
commit
e3486fe4b6
@ -3,7 +3,8 @@ language: python
|
||||
python: "2.7"
|
||||
|
||||
env:
|
||||
- SITE=test.yml
|
||||
- SITE=test-install-package.yml
|
||||
- SITE=test-install-from-source.yml
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
|
34
README.md
34
README.md
@ -40,6 +40,40 @@ You will also need to override the default `php_packages` list and add `php-fpm`
|
||||
|
||||
This role does not manage fpm-specific www pool configuration (found in `/etc/php-fpm.d/www.conf` on RedHat/CentOS and `/etc/php5/fpm/pool.d/www.conf` on Debian/Ubuntu), but rather allows you to manage those files on your own. If you change that file, remember to notify the `restart php-fpm` handler so PHP picks up the new settings once in place. Settings like `pm.max_children` and other `pm.*` settings can have a dramatic impact on server performance, and should be tuned specifically for each application and server configuration.
|
||||
|
||||
### Installing from Source
|
||||
|
||||
If you need a specific version of PHP, or would like to test the latest (e.g. master) version of PHP, there's a good chance there's no suitable package already available in your platform's package manager. In these cases, you may choose to install PHP from source by compiling it directly.
|
||||
|
||||
Note that source compilation takes *much* longer than installing from packages (PHP HEAD takes 5+ minutes to compile on a modern quad-core computer, just as a point of reference).
|
||||
|
||||
php_install_from_source: false
|
||||
|
||||
Set this to `true` to install PHP from source instead of installing from packages.
|
||||
|
||||
php_source_version: "master"
|
||||
|
||||
The version of PHP to install from source (a git branch, tag, or commit hash).
|
||||
|
||||
php_source_clone_dir: "~/php-src"
|
||||
php_source_install_path: "/opt/php"
|
||||
|
||||
Location where source will be cloned and installed, respectively.
|
||||
|
||||
php_source_make_command: "make"
|
||||
|
||||
Set the `make` command to `make --jobs=X` where `X` is the number of cores present on the server where PHP is being compiled. Will speed up compilation times dramatically if you have multiple cores.
|
||||
|
||||
php_source_configure_command: >
|
||||
[...]
|
||||
|
||||
The `./configure` command that will build the Makefile to be used for PHP compilation. Add in all the options you need for your particular environment. Using a folded scalar (`>`) allows you to define the variable over multiple lines, which is extremely helpful for legibility and source control!
|
||||
|
||||
A few other notes/caveats for specific configurations:
|
||||
|
||||
- **Apache with `mpm_prefork`**: If you're using Apache with prefork as a webserver for PHP, you will need to make sure `apxs2` is available on your system (e.g. by installing `apache2-prefork-dev` in Ubuntu), and you will need to make sure the option `--with-apxs2` is defined in `php_source_configure_command`. Finally, you will need to make sure the `mpm_prefork` module is loaded instead of `mpm_worker` or `mpm_event`, and likely add a `phpX.conf` (where `X` is the major version of PHP) configuration file to the Apache module config folder with contents like [`php7.conf`](https://gist.github.com/geerlingguy/5ae5445f28e71264e8c1).
|
||||
- **Apache with `mpm_event` or `mpm_worker`**: If you're using Apache with event or worker as a webserver for PHP, you will need to compile PHP with FPM. Make sure the option `--enable-fpm` is defined in `php_source_configure_command`. You'll also need to make sure Apache's support for CGI and event is installed (e.g. by installing `apache2-mpm-event` and `libapache2-mod-fastcgi`) and the `mpm_event` module is loaded.
|
||||
- **Nginx**: If you're using Nginx as a webserver for PHP, you will need to compile PHP with FPM. Make sure the option `--enable-fpm` is defined in `php_source_configure_command`.
|
||||
|
||||
### php.ini settings
|
||||
|
||||
php_use_managed_ini: true
|
||||
|
@ -48,3 +48,48 @@ php_short_open_tag: false
|
||||
php_error_reporting: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
|
||||
php_display_errors: "Off"
|
||||
php_display_startup_errors: "Off"
|
||||
|
||||
# Install PHP from source (instead of using a package manager) with these vars.
|
||||
php_install_from_source: false
|
||||
php_source_version: "master"
|
||||
php_source_clone_dir: "~/php-src"
|
||||
php_source_install_path: "/opt/php"
|
||||
# For faster compile time: "make --jobs=X" where X is # of cores present.
|
||||
php_source_make_command: "make"
|
||||
php_source_configure_command: >
|
||||
./configure
|
||||
--prefix={{ php_source_install_path }}
|
||||
--with-config-file-path={{ php_conf_path }}
|
||||
--enable-mbstring
|
||||
--enable-zip
|
||||
--enable-bcmath
|
||||
--enable-pcntl
|
||||
--enable-ftp
|
||||
--enable-exif
|
||||
--enable-calendar
|
||||
--enable-opcache
|
||||
--enable-pdo
|
||||
--enable-sysvmsg
|
||||
--enable-sysvsem
|
||||
--enable-sysvshm
|
||||
--enable-wddx
|
||||
--with-curl
|
||||
--with-mcrypt
|
||||
--with-iconv
|
||||
--with-gmp
|
||||
--with-pspell
|
||||
--with-gd
|
||||
--with-jpeg-dir=/usr
|
||||
--with-png-dir=/usr
|
||||
--with-zlib-dir=/usr
|
||||
--with-xpm-dir=/usr
|
||||
--with-freetype-dir=/usr
|
||||
--enable-gd-native-ttf
|
||||
--enable-gd-jis-conv
|
||||
--with-openssl
|
||||
--with-pdo-mysql=/usr
|
||||
--with-gettext=/usr
|
||||
--with-zlib=/usr
|
||||
--with-bz2=/usr
|
||||
--with-recode=/usr
|
||||
--with-mysqli=/usr/bin/mysql_config
|
||||
|
97
tasks/install-from-source.yml
Normal file
97
tasks/install-from-source.yml
Normal file
@ -0,0 +1,97 @@
|
||||
---
|
||||
- name: Ensure dependencies for building from source are installed (RedHat).
|
||||
yum: "pkg={{ item }} state=installed"
|
||||
with_items:
|
||||
- recode-devel
|
||||
- aspell-devel
|
||||
- libmcrypt-devel
|
||||
- t1lib-devel
|
||||
- libXpm-devel
|
||||
- libpng-devel
|
||||
- libjpeg-turbo-devel
|
||||
- bzip2-devel
|
||||
- openssl-libs
|
||||
- libicu-devel
|
||||
when: ansible_os_family == 'RedHat'
|
||||
|
||||
- name: Update apt cache (Debian).
|
||||
apt: update_cache=yes cache_valid_time=86400
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Ensure dependencies for building from source are installed (Debian).
|
||||
apt: "pkg={{ item }} state=installed"
|
||||
with_items:
|
||||
- build-essential
|
||||
- autoconf
|
||||
- automake
|
||||
- libtool
|
||||
- bison
|
||||
- re2c
|
||||
- libxml2-dev
|
||||
- libcurl4-openssl-dev
|
||||
- libbz2-dev
|
||||
- libjpeg-dev
|
||||
- libpng-dev
|
||||
- libxpm-dev
|
||||
- libfreetype6-dev
|
||||
- libgmp-dev
|
||||
- libgmp3-dev
|
||||
- libmcrypt-dev
|
||||
- libmysqlclient-dev
|
||||
- libpspell-dev
|
||||
- librecode-dev
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Ensure gmp.h is symlinked into a location accessible to gcc.
|
||||
file:
|
||||
src: /usr/include/x86_64-linux-gnu/gmp.h
|
||||
dest: /usr/include/gmp.h
|
||||
state: link
|
||||
|
||||
- name: Clone the PHP repository.
|
||||
git:
|
||||
repo: https://git.php.net/repository/php-src.git
|
||||
dest: "{{ php_source_clone_dir }}"
|
||||
version: "{{ php_source_version }}"
|
||||
accept_hostkey: yes
|
||||
depth: 1
|
||||
|
||||
- name: Check if PHP is installed.
|
||||
command: which php
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: php_installed
|
||||
|
||||
- name: Ensure PHP installation path exists.
|
||||
file:
|
||||
path: "{{ php_source_install_path }}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
when: php_installed|failed
|
||||
|
||||
- name: Build configure script.
|
||||
shell: >
|
||||
./buildconf
|
||||
chdir={{ php_source_clone_dir }}
|
||||
when: php_installed|failed
|
||||
|
||||
- name: Run configure script.
|
||||
shell: >
|
||||
{{ php_source_configure_command }}
|
||||
chdir={{ php_source_clone_dir }}
|
||||
when: php_installed|failed
|
||||
|
||||
- name: Make and install PHP.
|
||||
shell: >
|
||||
{{ item }}
|
||||
chdir={{ php_source_clone_dir }}
|
||||
with_items:
|
||||
- "{{ php_source_make_command }}"
|
||||
- make install
|
||||
when: php_installed|failed
|
||||
|
||||
- name: Ensure php executable is symlinked into a standard path.
|
||||
file:
|
||||
src: "{{ php_source_install_path }}/bin/php"
|
||||
dest: /usr/bin/php
|
||||
state: link
|
@ -25,10 +25,14 @@
|
||||
|
||||
# Setup/install tasks.
|
||||
- include: setup-RedHat.yml
|
||||
when: ansible_os_family == 'RedHat'
|
||||
when: (php_install_from_source == false) and (ansible_os_family == 'RedHat')
|
||||
|
||||
- include: setup-Debian.yml
|
||||
when: ansible_os_family == 'Debian'
|
||||
when: (php_install_from_source == false) and (ansible_os_family == 'Debian')
|
||||
|
||||
# Install PHP from source when php_install_from_source is true.
|
||||
- include: install-from-source.yml
|
||||
when: php_install_from_source == true
|
||||
|
||||
- name: Check the installed version of PHP.
|
||||
shell: php -r "echo PHP_VERSION;"
|
||||
|
10
tests/test-install-from-source.yml
Normal file
10
tests/test-install-from-source.yml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
|
||||
vars:
|
||||
php_enable_webserver: false
|
||||
php_install_from_source: true
|
||||
|
||||
roles:
|
||||
- ansible-role-php
|
@ -1,7 +1,9 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
|
||||
vars:
|
||||
php_enable_webserver: false
|
||||
|
||||
roles:
|
||||
- ansible-role-php
|
Loading…
Reference in New Issue
Block a user