Coder Social home page Coder Social logo

ansible-role-php's Introduction

Ansible Role: PHP

CI

Installs PHP on RedHat/CentOS and Debian/Ubuntu servers.

Requirements

If you're using an older LTS release of Ubuntu or RHEL, with an old/outdated version of PHP, you need to use a repo or PPA with a maintained PHP version, as this role only works with PHP versions that are currently supported by the PHP community.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

php_packages: []

A list of the PHP packages to install (OS-specific by default). You'll likely want to install common packages like php, php-cli, php-devel and php-pdo, and you can add in whatever other packages you'd like (for example, php-gd for image manipulation, or php-ldap if you need to connect to an LDAP server for authentication).

Note: If you're using Debian/Ubuntu, you also need to install libapache2-mod-fastcgi (for cgi/PHP-FPM) or libapache2-mod-php7.0 (or a similar package depending on PHP version) if you want to use mod_php with Apache.

php_packages_extra: []

A list of extra PHP packages to install without overriding the default list.

php_enable_webserver: true

If your usage of PHP is tied to a web server (e.g. Apache or Nginx), leave this default value. If you are using PHP server-side or to run some small application, set this value to false so this role doesn't attempt to interact with a web server.

php_webserver_daemon: "httpd"

The default values for the HTTP server deamon are httpd (used by Apache) for RedHat/CentOS, or apache2 (also used by Apache) for Debian/Ubuntu. If you are running another webserver (for example, nginx), change this value to the name of the daemon under which the webserver runs.

php_enablerepo: ""

(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. remi-php70,epel). This can be handy, as an example, if you want to install the latest version of PHP 7.0, which is in the Remi repository.

php_default_version_debian: ""

(Debian/Ubuntu only) The default version of PHP in the given OS version repositories. The specific version is set per distro and per version, but you can override it by providing a value here, like "7.4".

If you'd like to be able to switch PHP versions easily, or use a version that's not available in system packages: You can use the geerlingguy.php-versions role to more easily switch between major PHP versions (e.g. 5.6, 7.1, 7.2).

php_packages_state: "present"

If you have enabled any additional repositories such as geerlingguy.repo-epel or geerlingguy.repo-remi, you may want an easy way to swap PHP versions on the fly. By default, this is set to "present". You can override this variable to "latest" to upgrade to the latest available version. Combined with php_enablerepo, a user now doesn't need to manually uninstall the existing PHP packages before installing them from a different repository.

php_install_recommends: true

(Debian/Ubuntu only) Whether to install recommended packages when installing php_packages; you might want to set this to no explicitly if you're installing a PPA that recommends certain packages you don't want (e.g. Ondrej's php PPA will install php7.0-cli if you install php-pear alongside php5.6-cli... which is often not desired!).

php_executable: "php"

The executable to run when calling PHP from the command line. You should only change this if running php on your server doesn't target the correct executable, or if you're using software collections on RHEL/CentOS and need to target a different version of PHP.

PHP-FPM

PHP-FPM is a simple and robust FastCGI Process Manager for PHP. It can dramatically ease scaling of PHP apps and is the normal way of running PHP-based sites and apps when using a webserver like Nginx (though it can be used with other webservers just as easily).

When using this role with PHP running as php-fpm instead of as a process inside a webserver (e.g. Apache's mod_php), you need to set the following variable to true:

php_enable_php_fpm: false

If you're using Apache, you can easily get it configured to work with PHP-FPM using the geerlingguy.apache-php-fpm role.

php_fpm_state: started
php_fpm_enabled_on_boot: true

Control over the fpm daemon's state; set these to stopped and false if you want FPM to be installed and configured, but not running (e.g. when installing in a container).

php_fpm_handler_state: restarted

The handler restarts PHP-FPM by default. Setting the value to reloaded will reload the service, intead of restarting it.

php_fpm_pools:
  - pool_name: www
    pool_template: www.conf.j2
    pool_listen: "127.0.0.1:9000"
    pool_listen_allowed_clients: "127.0.0.1"
    pool_pm: dynamic
    pool_pm_max_children: 5
    pool_pm_start_servers: 2
    pool_pm_min_spare_servers: 1
    pool_pm_max_spare_servers: 3
    pool_pm_max_requests: 500
    pool_pm_status_path: /status

List of PHP-FPM pool to create. By default, www pool is created. To setup a new pool, add an item to php_fpm_pools list.

Specific settings inside the default www.conf.j2 PHP-FPM pool. If you'd like to manage additional settings, you can do so either by replacing the file with your own template using pool_template.

php.ini settings

php_use_managed_ini: true

By default, all the extra defaults below are applied through the php.ini included with this role. You can self-manage your php.ini file (if you need more flexility in its configuration) by setting this to false (in which case all the below variables will be ignored).

php_fpm_pool_user: "[apache|nginx|other]" # default varies by OS
php_fpm_pool_group: "[apache|nginx|other]" # default varies by OS
php_memory_limit: "256M"
php_max_execution_time: "60"
php_max_input_time: "60"
php_max_input_vars: "1000"
php_realpath_cache_size: "32K"
php_file_uploads: "On"
php_upload_max_filesize: "64M"
php_max_file_uploads: "20"
php_post_max_size: "32M"
php_date_timezone: "America/Chicago"
php_allow_url_fopen: "On"
php_sendmail_path: "/usr/sbin/sendmail -t -i"
php_output_buffering: "4096"
php_short_open_tag: false
php_error_reporting: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
php_display_errors: "Off"
php_display_startup_errors: "On"
php_expose_php: "On"
php_session_cookie_lifetime: 0
php_session_gc_probability: 1
php_session_gc_divisor: 1000
php_session_gc_maxlifetime: 1440
php_session_save_handler: files
php_session_save_path: ''
php_disable_functions: []
php_precision: 14
php_serialize_precision: "-1"

Various defaults for PHP. Only used if php_use_managed_ini is set to true.

OpCache-related Variables

The OpCache is included in PHP starting in version 5.5, and the following variables will only take effect if the version of PHP you have installed is 5.5 or greater.

php_opcache_zend_extension: "opcache.so"
php_opcache_enable: "1"
php_opcache_enable_cli: "0"
php_opcache_memory_consumption: "96"
php_opcache_interned_strings_buffer: "16"
php_opcache_max_accelerated_files: "4096"
php_opcache_max_wasted_percentage: "5"
php_opcache_validate_timestamps: "1"
php_opcache_revalidate_path: "0"
php_opcache_revalidate_freq: "2"
php_opcache_max_file_size: "0"

OpCache ini directives that are often customized on a system. Make sure you have enough memory and file slots allocated in the OpCache (php_opcache_memory_consumption, in MB, and php_opcache_max_accelerated_files) to contain all the PHP code you are running. If not, you may get less-than-optimal performance!

For custom opcache.so location provide full path with php_opcache_zend_extension.

php_opcache_conf_filename: [platform-specific]

The platform-specific opcache configuration filename. Generally the default should work, but in some cases, you may need to override the filename.

APCu-related Variables

php_enable_apc: true

Whether to enable APCu. Other APCu variables will be ineffective if this is set to false.

php_apc_shm_size: "96M"
php_apc_enable_cli: "0"

APCu ini directives that are often customized on a system. Set the php_apc_shm_size so it will hold all cache entries in memory with a little overhead (fragmentation or APC running out of memory will slow down PHP dramatically).

php_apc_conf_filename: [platform-specific]

The platform-specific APC configuration filename. Generally the default should work, but in some cases, you may need to override the filename.

Ensuring APC is installed

If you use APC, you will need to make sure APC is installed (it is installed by default, but if you customize the php_packages list, you need to include APC in the list):

  • On RHEL/CentOS systems: Make sure php-pecl-apcu is in the list of php_packages.
  • On Debian/Ubuntu systems: Make sure php-apcu is in the list of php_packages.

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_clone_depth: 1
php_source_install_path: "/opt/php"
php_source_install_gmp_path: "/usr/include/x86_64-linux-gnu/gmp.h"
php_source_mysql_config: "/usr/bin/mysql_config"

Location where source will be cloned and installed, and the location of the GMP header file (which can be platform/distribution specific), and mysql_config binary (this may be mariadb_config in newer operating system versions).

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.
  • 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.

Dependencies

None.

Example Playbook

- hosts: webservers
  vars_files:
    - vars/main.yml
  roles:
    - { role: geerlingguy.php }

Inside vars/main.yml:

php_memory_limit: "128M"
php_max_execution_time: "90"
php_upload_max_filesize: "256M"
php_packages:
  - php
  - php-cli
  - php-common
  - php-devel
  - php-gd
  - php-mbstring
  - php-pdo
  - php-pecl-apcu
  - php-xml
  ...

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.

ansible-role-php's People

Contributors

ajsalminen avatar doenietzomoeilijk avatar eiriksm avatar geerlingguy avatar guessit-dev avatar j-koehler avatar kindlehl avatar lewisw avatar louim avatar mikebell avatar oxyc avatar petrox avatar pfrenssen avatar pporada-gl avatar remicollet avatar ricoli avatar robruma avatar rockholla avatar rsicart avatar rvdbogerd avatar schwarz-b5c avatar shakalandy avatar solonair avatar stevenspasbo avatar tjoelsson avatar tobiasehlert avatar vincentlanglet avatar vkononov avatar vonhraban avatar yaron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-php's Issues

php5-mcrypt on Ubuntu 14.04 LTS

Hello

When installing php5-mcrypt via apt on Ubuntu 14.04 it is not enabled by default like it is on 12.04 :(

Once installed it can be enabled with the following commands

sudo php5enmod mcrypt
sudo service apache2 restart

Im not sure if this effects any other distro's currently.

I can have a look at submitting a PR but i'm not sure on the consequences for other distro's and the best method to update the role.

Cheers, Ben.

Can't override debian.yml variables

I'm driving myself a bit crazy trying to override the __php_packages variable in a variables file that I call in the playbook. It's just ignoring it and installing apache, which I don't want it to do. I can override others (php_enable_apc, php_enable_php_fpm), but something perhaps to do with the underscores?

I basically don't want it to install apache at all, I want to use a seperate role because I can't find a way to stop it using prefork

An extract of the playbook:

- name: Install base packages to new cloud server
  hosts: deploy
  user: root
  gather_facts: True

  vars_files:
    - "vars/lamp.yml"

  tasks:
    - name: Dump all vars
      action: template src=templates/dumpall.j2 dest=/tmp/ansible.all
  roles:
      - { role: roles/geerlingguy.php }

The variables file


---
php_packages:
  - php5
  - php5-mcrypt
  - php5-cli
  - php5-common
  - php5-curl
  - php5-dev
  - php5-fpm
  - php5-gd
  - php-pear
  - php-apc
  - libpcre3-dev
# Start and enable the PHP fpm service.
php_enable_php_fpm: true
# Don't need APC in php 5.5 as it has opcode caching built into core
php_enable_apc: false
php_enable_webserver: false

CentOS (6) needs additional php-opcache package.

When installing php on CentOS with remi, IUS or webtatic repository, php-opcache is not installed and no opcache.so is present. This leads to this error:
Failed loading /usr/lib64/php/modules/opcache.so: /usr/lib64/php/modules/opcache.so: cannot open shared object file: No such file or directory

An additional install of php-opcache is required.
remi: php55-opcache or php-56-opcache
IUS: php55u-opcache or php56u-opcache
webtatic: php55w-opcache or php56w-opcache

Then php_opcache_conf_filename should be 10-opcache.ini rather than opcache.ini

msg: service not found: [u'a', u'p', u'a', u'c', u'h', u'e', u'2']

Now when running my provision scripts, I get the following error:
msg: service not found: [u'a', u'p', u'a', u'c', u'h', u'e', u'2']

I assume it's because of the recently added list filter in tasks/main.yml:

php_webserver_daemon: "{{ __php_webserver_daemon | list }}"

Another fix for Debian - php_extension_conf_path can be a symlink

Trusty Travis was giving:

TASK: [ansible-role-php | Ensure configuration directories exist.] ************ 
ok: [localhost] => (item=/etc/php5/apache2)
failed: [localhost] => (item=/etc/php5/apache2/conf.d) => {"failed": true, "gid": 0, "group": "root", "item": "/etc/php5/apache2/conf.d", "mode": "0777", "owner": "root", "path": "/etc/php5/apache2/conf.d", "size": 9, "state": "link", "uid": 0}
msg: /etc/php5/apache2/conf.d already exists as a link

Use proper configuration paths in Debian/Ubuntu

Because of Debian/Ubuntu's handling of PHP/Apache configuration paths, both the php_conf_path and php_extension_conf_path are incorrect if you're using PHP as php-fpm or with a different webserver, like Nginx... Therefore, we need to be able to put the configuration files in the correct locations (e.g. /etc/php5 and /etc/php5/conf.d, then only symlink them into the apache2-specific folders if PHP is being run with Apache.

OpenSSL libraries

Installing from source with these vars:

...
php_install_from_source: true
php_source_version: "master"

i have an error during configure step that i could resolve adding packages to apt items:

- name: Ensure dependencies for building from source are installed (Debian).
  apt: "pkg={{ item }} state=installed"
  with_items:
...
    - libcurl4-openssl-dev
    - pkg-config

is it possible to add them in order to proper configure last php?
(fyi, i found information about how to solve this issue here: serverfault.com/questions/415458)

i don't know what about CentOS or other rpm based distro.

Pear and APC should not be installed for PHP 7

When building DrupalVM with PHP 7, I got an error in the Ensure PHP packages are installed. task from this role.

It is due to the vars/Debian.yml file containing the php-pear and php-apc packages, and I could get the machine to build by commenting out those packages.

I am on Ubuntu and Ansible 2.x, Vagrant 1.8 and Virtualbox 5.
Is there something I have overlooked?

phpenmod/phpdismod on Ubuntu

Currently this role creates static .ini's for php modules for apache, fpm & cli, so modules can't be easily enabled and disabled with this helper script.

Would need to create the static common .ini files @ /etc/php5/mods-available and then symlink them to the /conf.d folders, phpenmod could be used to do the symlinking, depending on OS support.

example >>

php5dismod xdebug
WARNING: Module xdebug ini file doesn't exist under /etc/php5/mods-available
WARNING: Module xdebug ini file doesn't exist under /etc/php5/mods-available
WARNING: Module xdebug ini file doesn't exist under /etc/php5/mods-available

relates to geerlingguy/ansible-role-php-xdebug#22

Debian variables file is coupled to apache

See #15.

Currently the variable file mentions apache explicitly, when this should really the generic conf.d folder, and then the config files should be symlinked into the appropriate folder (so apache2 for apache, not entirely sure about nginx - fpm I think, depending on the setup).

PHP session errors, possible misconfiguration?

I'm working with a fork of the Drupal-VM repo, and PimpMyLog is throwing the following error:

PHP Notice:  session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5/sessions) failed: Permission denied (13) in /usr/share/php/pimpmylog/inc/classes/Session.php on line 45

From what I can tell, this is because PHP's built-in session garbage collector is kicking in, when it should actually be disabled (on Ubuntu) because there is a cron job to take care of that.

I found a recommended fix which involves setting session.gc_probability = 0 in php.ini, but it looks like this role doesn't give a lot of flexibility to update the template. I could replace the whole PHP.ini file per the documentation, but that seems like overkill for what might be just a misconfiguration.

My config overrides, in case it helps for debugging:

php_memory_limit: "256M"
php_display_errors: "On"
php_display_startup_errors: "On"
php_enable_php_fpm: 1
php_enable_apc: 0
php_opcache_enable: 0
php_realpath_cache_size: "16K"
php_sendmail_path: "/usr/sbin/ssmtp -t"
php_opcache_enabled_in_ini: true
php_opcache_memory_consumption: "192"
php_opcache_max_accelerated_files: 4096
php_max_input_vars: "4000"

Ansible-galaxy. Can't download the role

Here is the output:

$ sudo ansible-galaxy install geerlingguy.php
- downloading role 'php', owned by geerlingguy
https://galaxy.ansible.com/roles/432/versions/?page=2&page_size=50
Traceback (most recent call last):
  File "/usr/local/bin/ansible-galaxy", line 959, in <module>
    main()
  File "/usr/local/bin/ansible-galaxy", line 953, in main
    fn(args, options, parser)
  File "/usr/local/bin/ansible-galaxy", line 819, in execute_install
    if len(role_versions) > 0:
TypeError: object of type 'NoneType' has no len()

At the same time other roles, like geerlingguy.mysql are being installed properly.

Support compiling from source, PHP 7, and beyond!

Partly inspired by Rasmus' presentation Speeding up the web with PHP7, and also from my personal desire to compare some things in Drupal 8 between in 5.5, 5.6, and 7.x, I'd like to add the ability to install/use PHP7 (or other specific version) by allowing PHP to be installed from source, similar to how I do it in the geerlingguy.git Galaxy role.

Add php_apc_enable_cli variable

Currently this option is hardcoded to 0 in the configuration. Add some flexibility by defaulting to 0 but allowing the setting to be configured through a new php_apc_enable_cli variable.

"Ensure configuration directories exist." task is never executed

on Ubuntu 14.04 LTS I noticed that the "Ensure configuration directories exist".

here is the execution log on my server

TASK: [geerlingguy.php | Include OS-specific variables.] *************
ok: [
]

TASK: [geerlingguy.php | Define php_packages.] ***********************
skipping: [
]

TASK: [geerlingguy.php | Ensure PHP packages are installed (RedHat).] *
skipping: [
*]

TASK: [geerlingguy.php | Ensure PHP packages are installed (Debian).] *
ok: [
*] => (item=php5,libapache2-mod-fastcgi,php5-mcrypt,php5-cli,php5-common,php5-curl,php5-dev,php5-fpm,php5-gd,php5-imagick,php5-xdebug)

TASK: [geerlingguy.php | Place PHP configuration file in place.] *****
failed: [
] => {"failed": true}
msg: Destination directory /etc/php5/apache2 does not exist

FATAL: all hosts have already failed -- aborting

Get gooky Apache-specific packages out of default config

As the title says. More than once I've had reports of poor Deb/Ubuntu-based users get semi-hosed by the fact that this role triggers Apache installation in its default state. If you're using Nginx or anything else as a webserver, then this can break things.

php5-fpm.sock is missing

Hi,

The recent updates to this role seem to have removed the php5-fpm.sock file from /var/run.

We were using this file in our nginx site config:

location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

Was this intentional? Am I setting up nginx incorrectly?

It is resulting in this error:

2016/01/22 18:57:43 [crit] 6648#0: *9 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: <IP>, server: <HOST>, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "<HOST>"

Thanks.

Unable to install it on Mac

Hi!

I am using ansible for the first time to create a VagrantBox for web development on CentOS 7.

I was able to install geerlingguy.mysql and geerlingguy.repo-epel using the following commands on my Mac:
ansible-galaxy install geerlingguy.mysql -p ./provisioning/roles/
ansible-galaxy install geerlingguy.repo-epel -p ./provisioning/roles/
and they were successful installed. Thank you for creating these!

When I try to install geerlingguy.php I get the following error:

 downloading role 'php', owned by geerlingguy
ERROR! Unexpected Exception: object of type 'NoneType' has no len()
to see the full traceback, use -vvv

*When I run the same command with -vvv I get: *


No config file found; using defaults
Opened /Users/marius/.ansible_galaxy
Validate TLS certificates: True
Connecting to galaxy_server: https://galaxy.ansible.com
Base API: https://galaxy.ansible.com/api/v1
Installing role geerlingguy.php 
Opened /Users/marius/.ansible_galaxy
Validate TLS certificates: True
Connecting to galaxy_server: https://galaxy.ansible.com
Base API: https://galaxy.ansible.com/api/v1
- downloading role 'php', owned by geerlingguy
https://galaxy.ansible.com/api/v1/roles/?owner__username=geerlingguy&name=php
https://galaxy.ansible.com/api/v1/roles/432/versions/?page_size=50
https://galaxy.ansible.com/api/v1https://galaxy.ansible.com/api/v1/roles/432/versions/?page=2&page_size=50
ERROR! Unexpected Exception: object of type 'NoneType' has no len()
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-galaxy", line 86, in <module>
    sys.exit(cli.run())
  File "/usr/local/lib/python2.7/site-packages/ansible/cli/galaxy.py", line 153, in run
    self.execute()
  File "/usr/local/lib/python2.7/site-packages/ansible/cli/__init__.py", line 114, in execute
    fn()
  File "/usr/local/lib/python2.7/site-packages/ansible/cli/galaxy.py", line 404, in execute_install
    installed = role.install()
  File "/usr/local/lib/python2.7/site-packages/ansible/galaxy/role.py", line 210, in install
    if len(role_versions) > 0:
TypeError: object of type 'NoneType' has no len()


From what I can tell this url is incorect
https://galaxy.ansible.com/api/v1https://galaxy.ansible.com/api/v1/roles/432/versions/?page=2&page_size=50

Any idea what am I missing?

Thank you!

php-fpm and environment variables

Hey Jeff,

Thanks for this role (and tons of others, for that matter)! I ditched my own in favor of this one.

This is more of a PHP question with an Ansible twist and too long to ask on Twitter. Surprisingly, there doesn't seem to be anybody else talking about this use case either.

Is there a [better] way to pass environment variables into php-fpm without templating a value into the pool configs?

Right now, I do something like this in a php-fpm.conf.j2:

env[MY_VAR] = {{ app_my_var }}

I also export the same vars into the shell environment for php-cli:

export MY_VAR={{ app_my_var }}

Ideally, I'd for something like Consul to be able to update the environment vars and simply reload php-fpm without templating the values into the config.

I also tried reading from the current environment based on an example in the php-fpm manual, but apparently the $HOSTNAME in that example is not a normal environment variable...

env[MY_VAR] = $HOSTNAME

Add tests for different PHP versions

Unfortunately, we're somewhat limited by the Travis build environment, which is currently on Ubuntu 12.04 (and could change here and there), but it would be nice to at least run the same playbook tests over at least PHP 5.4 and 5.5/5.6, so we can make sure changes to PHP-version-dependent features like the OpCache configuration (see #24) work correctly and don't cause regressions.

PHP5 module is not activated in Apache2

Tried the role on a mint server, php5 was installed, but not working in Apache2.

I added

- name: Enable PHP in Apache
  apache2_module: 
    state: present 
    name: php5
  notify: restart webserver
  when: php_enable_webserver

in configure.yml to fix it.

Default naming of opcache.ini symlinks

The OS default names of the opcache.ini sysmlinks (apache and cli) are:
RedHat: 10-opcache.ini
Debian: 20-opcache.ini
The Ansible role vars for the OS family are:
Redhat: opcache.ini
Debian: 05-opcache.ini
If PHP gets updated (e.g. security update) the default symlinks will be created and you will have two (both the default and the ansible created ones).
This causes errors when Apache restarts and tries to load the module twice.
I think the best solution is to use the OS default names (unless the oredr of inclusion is important?)
This can be overridden in plays using this role using:
php_opcache_conf_filename
But may be worth updating the defaults in the vars?

Doc improvment - APC is dead, long live the OpCache

Doc refers to "APC"

This is dead, and opcache should be prefered (when available).

But people using PHP >= 5.5 main need APC, only for user data cache. In this case APCu (or apcu_bc with PHP 7) is available.

Perhaps the documentation shoudl (try) to explain this...

In all case, everything which make people away from APC (original) is good ;)

Allow php executable to be configurable

When installing PHP in non-standard ways, running the php command by itself won't always point to a valid or correct installation of PHP, so this should be overridable.

Why is APC configured by default?

The task "Place PHP configuration files in place." containing an APC configuration by default is very restrictive, and it feels very much like this should be an option to include not the default.

In context, using the role pbuyle.php-pecl that has a dependency on this role, and because I'm using php-fpm, the destination conf.d does not exist, so I'm getting errors trying to perform an action that isn't desired or useful.

It seems like there should be an option for both files to easily include or suppress them as desire?

How can I turn error reporting on?

Not sure if there's a good way to do this—there definitely isn't a config option. I like to use the same provisioning on vagrant when I develop that I use on my server in production, so it would be useful to be able to change this option.

Wrong variable "php_installed_versionl"

Hi,

in file " ansible-role-php/tasks/main.yml" on line 48 there is:

shell: '{{ php_executable }} -r "echo php_installed_version;"'

but "php_installed_version" is not PHP variable. It should be "PHP_VERSION":

shell: '{{ php_executable }} -r "echo PHP_VERSION;"'

Sorry, I'm new to github and don't know, how to pull code :-(

Than

Cross-platform module installation

If I am correct, PHP module naming follows this pattern:

  • Debian: php5-module
  • RedHat: php-module

It would be nice if we could have a cross-platform option to install modules:

php_modules:
    - cli
    - fpm
    - gd

Fails in check mode

error while evaluating conditional: php_version.stdout.split('.')[0] == '5' and php_version.stdout.split('.')[1] < '5' in tasks/main.yml: 41

You could add an 'always_run' to the task registering php_version but then that would fail if no PHP has been installed yet wouldn't it?

Perhaps also add a - "ansible-playbook -i tests/inventory tests/$SITE --check" to your travis tests?

When apc is enabled the role cannot be provisioned twice

Hi,

I have problems provisioning my environment with php_enable_apc set as true.

The first provisioning goes well but if I try to redo it I have the following error:

failed: [default] => {"failed": true, "gid": 0, "group": "root", "mode": "0777", "owner": "root", "path": "/etc/php5/apache2/conf.d/20-apc.ini", "size": 25, "src": "apc.ini.j2", "state": "link", "uid": 0}
msg: src file does not exist, use "force=yes" if you really want to create the link: /etc/php5/apache2/conf.d/apc.ini.j2

Tell me if you miss some information to reproduce.

Kind regards,

php.ini is not applied in certain situations on Ubuntu

Hello, I'm not sure whether it's a bug.
Role creates a configuration in /etc/php5/php.ini, but PHP use another files:
/etc/php5/cli/php.ini - for cli, and
/etc/php5/fpm/php.ini - for php-fpm

This forces to write additional code

    - name: Copy php.ini to php5/cli
      command: cp /etc/php5/php.ini /etc/php5/cli/php.ini

    - name: Copy php.ini to php5/fpm
      command: cp /etc/php5/php.ini /etc/php5/fpm/php.ini
      notify: restart php-fpm

PHP-FPM init script for build from source causes 30s delay when stopping via systemd

From downstream issue: geerlingguy/raspberry-pi-dramble#69

When using php-fpm built from source, the init script has a 30s delay that is hit, and shutting down, restarting, stopping, etc. takes an inordinately long amount of time. I'm going to switch the timeout to 2s instead, at least for now, since that should cover most cases... but I'd rather use a better solution that doesn't always hit this timeout when using systemd (e.g. on Debian 8+, Ubuntu 16+, CentOS 7+). Maybe using a real systemd service file instead of the init v file would be the best solution, but for now, since I'm supporting all the older OSes (Ubuntu 12/14, CentOS 6), that's not as simple an option :(

See options for start-stop-daemon here: http://manpages.ubuntu.com/manpages/karmic/man8/start-stop-daemon.8.html

www.conf pool

Hello! First of all, thank you for your work.

I have a question about recents changes about the www.conf configuration: Why ? :)
I don't want to keep this file in the configuration and with these changes it's now complicated to remove it. Is there an option I missed to avoid the "Configure php-fpm pool" ?

Thanks for your help

Allow self-management of php.ini

Right now there are a bunch of sane defaults and some user-managed settings in php.ini, but there's no way I can keep the role svelte and also offer the flexibility required to allow anyone to use it for their own infrastructure. In some cases, it would be easiest to simply let people provide their own php.ini file as a template/copy in a separate task, and switch off this role's php.ini management.

So I'd like to add a php_use_managed_ini variable for that purpose.

Check install PHP version fails

I'm using drupal-vm and running into this error when running vagrant up.

TASK: [geerlingguy.php | Check the installed version of PHP.] ***************** 
failed: [REDACTED] => {"changed": false, "cmd": "php -r \"echo php_installed_version;\"", "delta": "0:00:00.001369", "end": "2016-01-13 17:45:09.385431", "rc": 127, "start": "2016-01-13 17:45:09.384062", "stdout_lines": [], "warnings": []}
stderr: /bin/sh: 1: php: not found

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/REDACTED/playbook.retry

REDACTED                    : ok=57   changed=25   unreachable=0    failed=1   

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

It looks like the problem may be that the step to install PHP packages is skipped.

TASK: [geerlingguy.php | Ensure PHP packages are installed.] ****************** 
skipping: [REDACTED]

Is there additional information can I provide to help track down this issue?

Add a default pool.d/www.conf for FPM for source install

If the role user is installing from source and wants PHP-FPM, then currently this role fails to build (as mentioned in #89 / @oxyc). I'm also running into the problem when building Drupal Pi with PHP 7.x source:

TASK [geerlingguy.php : Configure php-fpm pool (if enabled).] ******************
failed: [10.0.1.18] => (item={u'regexp': u'^listen.?=.+$', u'line': u'listen = 127.0.0.1:9000'}) => {"failed": true, "item": {"line": "listen = 127.0.0.1:9000", "regexp": "^listen.?=.+$"}, "msg": "Destination /etc/php5/fpm/pool.d/www.conf does not exist !", "rc": 257}

So the best bet is probably just to have a templated file that can be installed if it doesn't exist. It seems the file is present on Debian at least, need to confirm that the file is present on RedHat too (for package-based installs).

`restart php-fpm` Failing

Would appreciate any help.

Getting failure on "restart php-fpm"

failed: [default] => {"failed": true}

FATAL: all hosts have already failed -- aborting

Partial output: Full vagrant up output & related files

 _______________________________________________
< NOTIFIED: geerlingguy.php | restart webserver >
 -----------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


changed: [default]
 _____________________________________________
< NOTIFIED: geerlingguy.php | restart php-fpm >
 ---------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


failed: [default] => {"failed": true}

FATAL: all hosts have already failed -- aborting
 _____________________________________________
< NOTIFIED: geerlingguy.php | restart php-fpm >
 ---------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


FATAL: no hosts matched or all hosts have already failed -- aborting


FATAL: all hosts have already failed -- aborting
 _____________________________________________
< NOTIFIED: geerlingguy.php | restart php-fpm >
 ---------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


FATAL: no hosts matched or all hosts have already failed -- aborting


FATAL: all hosts have already failed -- aborting
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


           to retry, use: --limit @/Users/halo/vagrant.retry

default                    : ok=22   changed=9    unreachable=0    failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
vagrant destroy -f && vagrant up: 05:03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.