Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Switch Apache to use FPM instead of mod_php #346

Closed
geerlingguy opened this issue Dec 14, 2015 · 5 comments
Closed

Switch Apache to use FPM instead of mod_php #346

geerlingguy opened this issue Dec 14, 2015 · 5 comments

Comments

@geerlingguy
Copy link
Owner

By default, Apache 2.4 will use mod_php instead of FPM. I'd like to have Apache use FPM instead, to ensure extra consistency with Nginx and better overall performance.

@geerlingguy
Copy link
Owner Author

Steps to manually switch (at least on Ubuntu 14.04):

  1. sudo apt-get install -y libapache2-mod-fastcgi

  2. sudo nano /etc/apache2/mods-enabled/fastcgi.conf, and add the following inside:

      <IfModule mod_fastcgi.c>
        AddType application/x-httpd-fastphp5 .php
        Action application/x-httpd-fastphp5 /php5-fcgi
        Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
        FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
        <Directory /usr/lib/cgi-bin>
          Require all granted
        </Directory>
      </IfModule>
    
  3. sudo a2enmod actions

  4. sudo service apache2 restart

If it were just Ubuntu 14.04, I'd be adding the support immediately. As it is, this is a complicated enough configuration (why, oh why, Apache!?) that I'd rather add a new role, geerlingguy.apache-fastcgi-php and use that along with apache (e.g. add the following line after the apache role include in provisioning/playbook.yml):

  - { role: geerlingguy.apache-fastcgi-php, when: drupalvm_webserver == 'apache' }

I'll also need to add the role to provisioning/requirements.yml

@geerlingguy
Copy link
Owner Author

It's actually much simpler, it seems... adding the line below will proxy requests through PHP-FPM in each Drupal site virtualhost:

apache_vhosts:
  - servername: "{{ drupal_domain }}"
    documentroot: "{{ drupal_core_path }}"
    extra_parameters: |
          ProxyPassMatch ^/(.*\.php(/.*)?)$ "unix:/var/run/php5-fpm.sock|fcgi://localhost{{ drupal_core_path }}"

And as long as we have Apache 2.4 (e.g. use the below task to set it to 2.4 on Ubuntu 12.04), we can just enable mod_proxy_fcgi, and the above proxypass works wonderfully:

- name: Add repository for Apache 2.4 on Ubuntu 12.04.
  apt_repository: repo='ppa:ondrej/apache2'
  when: ansible_distribution_version == "12.04"

I'm updating the freshly-renamed geerlingguy.apache-php-fpm role now, and will rename it on galaxy or delete/re-add it...

@geerlingguy
Copy link
Owner Author

So... I definitely need to add the ability to configure—at a minimum—the listen directive in PHP-FPM's www.conf file. Because it defaults to a UNIX socket on Ubuntu, and a TCP/IP port (9000) on RedHat... and we need it consistent to make users not have to switch a bunch of virtualhost configs when switching platforms.

It might be best to default to whatever we use with Nginx currently (by default), as that would require the least amount of rework.

@geerlingguy
Copy link
Owner Author

I'm very close to finishing this... just completing testing against:

  • Ubuntu 14.04
  • Ubuntu 12.04
  • CentOS 7
  • CentOS 6

@geerlingguy
Copy link
Owner Author

For CentOS 6, I'm just updating the docs and mentioning that users can either elect to use mod_php or switch to Nginx. I'm not going to support an extra role + more layers of setup just to get Apache 2.4+ running on CentOS 6. See also #376.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant