Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Apache support with apxs #35

@eebs

Description

@eebs

Hello all,

I'd like to start a discussion and/or get some input on how to use puppet-php with apache. I've done some poking around, and have gotten things to work fairly well, but I've come across a number of issues that prevent everything from working 100%. I'm not sure if all the issues can be solved by puppet-php or are the responsibility of puppet-php, but I'll get to that later.

Goal:

To be able to install multiple versions of PHP for use with apache and be able to switch between them, requiring only a restart of apache to use the selected version.

Problems:

Support for apxs

Currently there is no support for building a DSO with apxs to be used with apache. The --with-apxs2=DIR configuration option allows you to set the path to apxs, which will then be used to create the .so module file. Adding this option is not straight forward however, because older versions (< 5.3.3) do not support both the --with-apxs2=DIR option and --enable-fpm option as mentioned in #12, (php bug report).

I have worked around this so far by adding some configuration options to puppet-php, namely the disable_fpm and configure_params options. You can see my changes here. disable-fpm simply suppresses the --enable-fpm configuration option, and configure_params is an array of configuration params that is merged with the default args in php_source.rb.

This allows you to add the following to your manifests to build php with the apache2handler SAPI module:

# Configure php to disable fpm, and add the --with-apxs2=DIR option
class { 'php::config':
    disable_fpm => true,
    configure_params => '--with-apxs2=/usr/sbin/apxs'
}

This patch forces ALL versions of php to use the specified configuration. I am not familiar enough with puppet to know the correct pattern/methodology to use to allow for different configuration for each version. If it would be better to allow configuration on a per-version basis, I would be happy to update the code if someone could point me in the right direction for how to do it.

Shared object is overwritten with each version build

Using the above configuration, I am able to build php and have a libphp5.so file created as a result. The libphp5.so file is created at /usr/libexec/apache2/libphp5.so. I can load the libphp5.so object into apache using the LoadModule directive (this step is actually done by apxs I believe), and it works great. The problem occurs when you build a new version of php. When a new build is made, the libphp5.so file is overwritten.

After some digging, I found that phpenv actually does have support for quickly switching between versions of php loaded by apache. This is acomplished by updating a symlink at $phpenv_root/lib/libphp5.so This symlink points to a location within the selected version, for example libphp5.so -> /opt/boxen/phpenv/versions/5.3.27/libexec/libphp5.so.


Side note, I am not seeing the issue mentioned in #21, as phpenv only sets PHPENV_ROOT to ~/.phpenv if PHPENV_ROOT isn't aready set, which is currently being done by puppet-php.


If libphp5.so is placed in $phpenv_root/versions/$version/libexec/, and you instruct apache to load the module from the symlink location, everything works great. I tried this out by building a version of php, copying libphp5.so into $version/libexec/libphp5.so, building a new version, and copying the new libphp5.so file into the new version. Switching the php version using phpenv global and restarting apache results in the correct version of php being used by apache.

So how to we get libphp5.so to be copied to our versioned directory? Well looking at the output of ./configure --help I found that there's an option --libexecdir=DIR that looks like it sets the directory where libphp5.so will be copied to. I tried adding that to the php configuration options, but sadly libphp5.so was still copied to /usr/libexec/apache2/libphp5.so.

After some further source code digging and Googling, I found a single mention on PHP's bug tracking site indicating that the php configure scripts ignore the --libexecdir=DIR option. Sure enough, I found the following in php-src/sapi/apache2handler/config.m4:

APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`
if test -z `$APXS -q SYSCONFDIR`; then
INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
             $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
                   -i -n php5"
else
APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR`
INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
            \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \
             $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
                   -S SYSCONFDIR='$APXS_SYSCONFDIR' \
                   -i -a -n php5"
fi

Now, I am quickly stepping outside by normal comfort zone as I have no real experience with the complexities of the configure/build processes, but from the above code we can see that APXS_LIBEXECDIR is determined by querying apxs for its current LIBEXECDIR option. Running apxs -q LIBEXECDIR produces the output /usr/libexec/apache2, which matches what I'm seeing when building php.

This is where I'm stuck. I don't know enough about the configuration/build process to know what's a feasible solution. Is this a php source problem? Is there any way to set the correct libexecdir on apxs before the build process starts?

Questions

So here are my questions for the community:

  1. Is there a desire for apache/apxs support in puppet-php? Or are most people simply using FPM/nginx.
  2. Should I submit a PR to allow the disabling of FPM and the ability to add additional configuration options (such as --with-apxs2=DIR).
  3. Is it possible to set the LIBEXECDIR option on apxs before each build, and what is the best way to do so? Is this the correct approach?

Thank you for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions